@@ -47,6 +47,9 @@ import (
47
47
// The wait time limit for pod upgrade.
48
48
const waitLimit = 2 * 60 * 60
49
49
50
+ var startTime time.Time
51
+ var failCount int = 0
52
+
50
53
// StatefulSetSyncer used to operate statefulset.
51
54
type StatefulSetSyncer struct {
52
55
* mysqlcluster.MysqlCluster
@@ -146,6 +149,7 @@ func (s *StatefulSetSyncer) Sync(ctx context.Context) (syncer.SyncResult, error)
146
149
result .SetEventData ("Normal" , basicEventReason (s .Name , err ),
147
150
fmt .Sprintf ("%s %s %s successfully" , kind , key , result .Operation ))
148
151
log .Info (string (result .Operation ), "key" , key , "kind" , kind )
152
+ failCount = 0
149
153
}
150
154
return result , err
151
155
}
@@ -167,8 +171,22 @@ func (s *StatefulSetSyncer) canExpandPVC(ctx context.Context) bool {
167
171
// If newStorage is not greater than oldStorage, do not expand.
168
172
if newStorage .Cmp (* oldRequest .Storage ()) != 1 {
169
173
log .Info ("canExpandPVC" , "result" , "can not expand" , "reason" , "new pvc is not larger than old pvc" )
170
- return false
174
+ // Should return true, because if change replicas and storage size, it will fail again and again
175
+ // during expanding PVCs, not great then oldStorage it will not truely expand, just recreate
176
+ // statefulset.
177
+ if failCount > 0 && time .Since (startTime ) > time .Duration (30 )* time .Second {
178
+ log .Info ("canExpandPVC" , "result" , "reason" , "over 30 seconds, trying to expand" )
179
+ failCount = 0
180
+ return true
181
+ } else {
182
+ if failCount == 0 {
183
+ startTime = time .Now ()
184
+ }
185
+ failCount ++
186
+ return false
187
+ }
171
188
}
189
+ failCount = 0
172
190
return true
173
191
}
174
192
0 commit comments