Skip to content

Commit ffe0838

Browse files
committed
mysqlcluster: when storage size shrink, and change replicas, It will reconcile fail forever. #436
1 parent 7d05a4f commit ffe0838

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

mysqlcluster/syncer/statefulset.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ import (
4747
// The wait time limit for pod upgrade.
4848
const waitLimit = 2 * 60 * 60
4949

50+
var startTime time.Time
51+
var failCount int = 0
52+
5053
// StatefulSetSyncer used to operate statefulset.
5154
type StatefulSetSyncer struct {
5255
*mysqlcluster.MysqlCluster
@@ -146,6 +149,7 @@ func (s *StatefulSetSyncer) Sync(ctx context.Context) (syncer.SyncResult, error)
146149
result.SetEventData("Normal", basicEventReason(s.Name, err),
147150
fmt.Sprintf("%s %s %s successfully", kind, key, result.Operation))
148151
log.Info(string(result.Operation), "key", key, "kind", kind)
152+
failCount = 0
149153
}
150154
return result, err
151155
}
@@ -167,8 +171,22 @@ func (s *StatefulSetSyncer) canExpandPVC(ctx context.Context) bool {
167171
// If newStorage is not greater than oldStorage, do not expand.
168172
if newStorage.Cmp(*oldRequest.Storage()) != 1 {
169173
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+
}
171188
}
189+
failCount = 0
172190
return true
173191
}
174192

sidecar/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func (cfg *Config) buildXenonConf() []byte {
333333
"admin": "root",
334334
"ping-timeout": %d,
335335
"passwd": "%s",
336-
"host": "localhost",
336+
"host": "127.0.0.1",
337337
"version": "%s",
338338
"master-sysvars": "%s",
339339
"slave-sysvars": "%s",

0 commit comments

Comments
 (0)