mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-19 09:35:08 +02:00
Do rolling update after creating of a statefulset if pods were present. (#110)
Make sure we always re-create pods if we had to create the statefulset, even if the pods from the old statefulset were already there.
This commit is contained in:
committed by
Murat Kabilov
parent
49cb395aed
commit
9f9a89185f
+32
-15
@@ -96,8 +96,18 @@ func (c *Cluster) syncEndpoint() error {
|
|||||||
|
|
||||||
func (c *Cluster) syncStatefulSet() error {
|
func (c *Cluster) syncStatefulSet() error {
|
||||||
cSpec := c.Spec
|
cSpec := c.Spec
|
||||||
|
var rollUpdate bool
|
||||||
if c.Statefulset == nil {
|
if c.Statefulset == nil {
|
||||||
c.logger.Infof("Can't find the cluster's StatefulSet")
|
c.logger.Infof("Can't find the cluster's StatefulSet")
|
||||||
|
pods, err := c.listPods()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Can't list pods of the StatefulSet: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(pods) > 0 {
|
||||||
|
c.logger.Infof("Found pods without the statefulset: trigger rolling update")
|
||||||
|
rollUpdate = true
|
||||||
|
}
|
||||||
ss, err := c.createStatefulSet()
|
ss, err := c.createStatefulSet()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Can't create missing StatefulSet: %s", err)
|
return fmt.Errorf("Can't create missing StatefulSet: %s", err)
|
||||||
@@ -107,23 +117,30 @@ func (c *Cluster) syncStatefulSet() error {
|
|||||||
return fmt.Errorf("Cluster is not ready: %s", err)
|
return fmt.Errorf("Cluster is not ready: %s", err)
|
||||||
}
|
}
|
||||||
c.logger.Infof("Created missing StatefulSet '%s'", util.NameFromMeta(ss.ObjectMeta))
|
c.logger.Infof("Created missing StatefulSet '%s'", util.NameFromMeta(ss.ObjectMeta))
|
||||||
return nil
|
if !rollUpdate {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
desiredSS := c.genStatefulSet(cSpec)
|
|
||||||
match, 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 !rollUpdate {
|
if !rollUpdate {
|
||||||
c.logger.Debugln("No rolling update is needed")
|
var (
|
||||||
return nil
|
match bool
|
||||||
|
reason string
|
||||||
|
)
|
||||||
|
desiredSS := c.genStatefulSet(cSpec)
|
||||||
|
match, 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 !rollUpdate {
|
||||||
|
c.logger.Debugln("No rolling update is needed")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.logger.Debugln("Performing rolling update")
|
c.logger.Debugln("Performing rolling update")
|
||||||
if err := c.recreatePods(); err != nil {
|
if err := c.recreatePods(); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user