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:
		
						commit
						f41a42f922
					
				| 
						 | 
				
			
			@ -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)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,17 +253,20 @@ 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 cachedRollingUpdateFlag {
 | 
			
		||||
				c.logger.Infof("found a statefulset with an unfinished pods rolling update")
 | 
			
		||||
			} else {
 | 
			
		||||
				c.logger.Infof("clearing the rolling update flag based on the cached information")
 | 
			
		||||
				podsRollingUpdateRequired = false
 | 
			
		||||
			if cachedStatefulsetExists {
 | 
			
		||||
				if cachedRollingUpdateFlag {
 | 
			
		||||
					c.logger.Infof("found a statefulset with an unfinished pods rolling update")
 | 
			
		||||
				} else {
 | 
			
		||||
					c.logger.Infof("clearing the rolling update flag based on the cached information")
 | 
			
		||||
					podsRollingUpdateRequired = false
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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))
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue