mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-04 14:41:33 +02:00
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:
+11
-4
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user