Replace the statefulset if it cannot be updated. (#18)

Updates to statefulset spec for fields other than 'replicas' and
containers' are forbidden. However, it is possible to delete the old
statefulset without deleting its pods and create the new one, using the
changed specs. The new statefulset shall pick up the orphaned pods.

Change the statefulset's comparison to return the combined effect of
all checks, not just the first non-matching field.
This commit is contained in:
Oleksii Kliukin
2017-05-17 11:28:21 +02:00
committed by GitHub
parent 356be8f0f1
commit 4457ce4e47
5 changed files with 175 additions and 47 deletions
+11 -4
View File
@@ -107,7 +107,7 @@ func (c *Cluster) syncEndpoint() error {
func (c *Cluster) syncStatefulSet() error {
cSpec := c.Spec
var rollUpdate bool
var rollUpdate, needsReplace bool
if c.Statefulset == nil {
c.logger.Infof("Can't find the cluster's StatefulSet")
pods, err := c.listPods()
@@ -137,19 +137,26 @@ func (c *Cluster) syncStatefulSet() error {
match bool
reason string
)
desiredSS, err := c.genStatefulSet(cSpec)
if err != nil {
return fmt.Errorf("Can't generate StatefulSet: %s", err)
}
match, rollUpdate, reason = c.compareStatefulSetWith(desiredSS)
match, needsReplace, rollUpdate, reason = c.compareStatefulSetWith(desiredSS)
if match {
return nil
}
c.logStatefulSetChanges(c.Statefulset, desiredSS, false, reason)
if err := c.updateStatefulSet(desiredSS); err != nil {
return fmt.Errorf("Can't update StatefulSet: %s", err)
if !needsReplace {
if err := c.updateStatefulSet(desiredSS); err != nil {
return fmt.Errorf("Can't update StatefulSet: %s", err)
}
} else {
if err := c.replaceStatefulSet(desiredSS); err != nil {
return fmt.Errorf("Can't replace StatefulSet: %s", err)
}
}
if !rollUpdate {