Merge branch 'rolling_updates_with_statefulset_annotations' of github.com:zalando-incubator/postgres-operator into rolling_updates_with_statefulset_annotations

This commit is contained in:
Oleksii Kliukin 2018-05-07 08:10:35 +02:00
commit f41a42f922
3 changed files with 21 additions and 9 deletions

View File

@ -189,10 +189,13 @@ func (c *Cluster) updateStatefulSet(newStatefulSet *v1beta1.StatefulSet, include
return fmt.Errorf("could not patch statefulset spec %q: %v", statefulSetName, err)
}
if includeAnnotations && newStatefulSet.Annotations != nil {
patchData := metadataAnnotationsPatch(newStatefulSet.Annotations)
c.logger.Debugf("updating statefulset annotations")
if patchData, err = metaPatch(newStatefulSet.ObjectMeta); err != nil {
return fmt.Errorf("could not form patch for the stetefulset metadata: %v", err)
}
statefulSet, err = c.KubeClient.StatefulSets(c.Statefulset.Namespace).Patch(
c.Statefulset.Name,
types.StrategicMergePatchType,
types.MergePatchType,
[]byte(patchData), "")
if err != nil {
return fmt.Errorf("could not patch statefulset annotations %q: %v", patchData, err)

View File

@ -221,7 +221,7 @@ func (c *Cluster) syncPodDisruptionBudget(isUpdate bool) error {
func (c *Cluster) syncStatefulSet() error {
var (
cachedRollingUpdateFlag, podsRollingUpdateRequired bool
cachedRollingUpdateFlag, cachedStatefulsetExists, podsRollingUpdateRequired bool
)
sset, err := c.KubeClient.StatefulSets(c.Namespace).Get(c.statefulSetName(), metav1.GetOptions{})
if err != nil {
@ -253,12 +253,14 @@ func (c *Cluster) syncStatefulSet() error {
// if we reset the rolling update flag in the statefulset structure in memory but didn't manage to update
// the actual object in Kubernetes for some reason we want to avoid doing an unnecessary update by relying
// on the 'cached' in-memory flag.
cachedStatefulsetExists = true
cachedRollingUpdateFlag = getRollingUpdateFlag(c.Statefulset, true)
c.logger.Debugf("cached statefulset value exists, rollingUpdate flag is %t", cachedRollingUpdateFlag)
}
// statefulset is already there, make sure we use its definition in order to compare with the spec.
c.Statefulset = sset
if podsRollingUpdateRequired = getRollingUpdateFlag(c.Statefulset, false); podsRollingUpdateRequired {
if cachedStatefulsetExists {
if cachedRollingUpdateFlag {
c.logger.Infof("found a statefulset with an unfinished pods rolling update")
} else {
@ -266,6 +268,7 @@ func (c *Cluster) syncStatefulSet() error {
podsRollingUpdateRequired = false
}
}
}
desiredSS, err := c.generateStatefulSet(&c.Spec)
if err != nil {
@ -302,7 +305,7 @@ func (c *Cluster) syncStatefulSet() error {
c.logger.Infof("pods have been recreated")
setRollingUpdateFlag(c.Statefulset, false)
if err := c.updateStatefulSet(c.Statefulset, true); err != nil {
c.logger.Warningf("could not clear rolling update for the statefulset")
c.logger.Warningf("could not clear rolling update for the statefulset: %v", err)
}
}
return nil

View File

@ -139,6 +139,12 @@ func specPatch(spec interface{}) ([]byte, error) {
}{spec})
}
func metaPatch(meta interface{}) ([]byte, error) {
return json.Marshal(struct {
ObjMeta interface{} `json:"metadata"`
}{meta})
}
func metadataAnnotationsPatch(annotations map[string]string) string {
annotationsList := make([]string, 0, len(annotations))