Adjust naming and prevent a flag reset
This commit is contained in:
		
							parent
							
								
									4dcf2cae40
								
							
						
					
					
						commit
						f9c10b3d00
					
				|  | @ -82,7 +82,7 @@ type Cluster struct { | |||
| } | ||||
| 
 | ||||
| type compareStatefulsetResult struct { | ||||
| 	match         bool | ||||
| 	update        bool | ||||
| 	replace       bool | ||||
| 	rollingUpdate bool | ||||
| 	reasons       []string | ||||
|  | @ -346,7 +346,7 @@ func (c *Cluster) Create() error { | |||
| 
 | ||||
| func (c *Cluster) compareStatefulSetWith(statefulSet *v1beta1.StatefulSet) *compareStatefulsetResult { | ||||
| 	reasons := make([]string, 0) | ||||
| 	match, needsRollUpdate, needsReplace := true, false, false | ||||
| 	update, needsRollUpdate, needsReplace := false, false, false | ||||
| 
 | ||||
| 	if len(c.Statefulset.Spec.Template.Spec.Containers) == 0 { | ||||
| 		c.logger.Warningf("statefulset %q has no container", util.NameFromMeta(c.Statefulset.ObjectMeta)) | ||||
|  | @ -370,14 +370,14 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *v1beta1.StatefulSet) *comp | |||
| 		} | ||||
| 
 | ||||
| 		if check.statefulSetCondition(c.Statefulset, statefulSet) { | ||||
| 			if check.result.differs != nil { | ||||
| 				match = !*check.result.differs | ||||
| 			if util.IsTrue(check.result.needUpdate) { | ||||
| 				update = true | ||||
| 			} | ||||
| 			if check.result.needsRollUpdate != nil { | ||||
| 				needsRollUpdate = *check.result.needsRollUpdate | ||||
| 			if util.IsTrue(check.result.needsRollUpdate) { | ||||
| 				needsRollUpdate = true | ||||
| 			} | ||||
| 			if check.result.needsReplace != nil { | ||||
| 				needsReplace = *check.result.needsReplace | ||||
| 			if util.IsTrue(check.result.needsReplace) { | ||||
| 				needsReplace = true | ||||
| 			} | ||||
| 
 | ||||
| 			reasons = append(reasons, check.reason) | ||||
|  | @ -394,10 +394,15 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *v1beta1.StatefulSet) *comp | |||
| 	// the template and the diff
 | ||||
| 
 | ||||
| 	if needsRollUpdate || needsReplace { | ||||
| 		match = false | ||||
| 		update = true | ||||
| 	} | ||||
| 
 | ||||
| 	return &compareStatefulsetResult{match: match, reasons: reasons, rollingUpdate: needsRollUpdate, replace: needsReplace} | ||||
| 	return &compareStatefulsetResult{ | ||||
| 		update:        update, | ||||
| 		reasons:       reasons, | ||||
| 		rollingUpdate: needsRollUpdate, | ||||
| 		replace:       needsReplace, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (c *Cluster) compareVolumeClaimTemplates(setA, setB *v1beta1.StatefulSet) (bool, []string) { | ||||
|  | @ -412,7 +417,11 @@ func (c *Cluster) compareVolumeClaimTemplates(setA, setB *v1beta1.StatefulSet) ( | |||
| 				continue | ||||
| 			} | ||||
| 
 | ||||
| 			if check.volumeClaimCondition(&claimA, &claimB) { | ||||
| 			if !check.volumeClaimCondition(&claimA, &claimB) { | ||||
| 				continue | ||||
| 			} | ||||
| 
 | ||||
| 			if util.IsTrue(check.result.needsReplace) { | ||||
| 				needsReplace = true | ||||
| 				reasons = append(reasons, fmt.Sprintf(check.reason, index)) | ||||
| 			} | ||||
|  | @ -438,7 +447,11 @@ func (c *Cluster) compareContainers(setA, setB *v1beta1.StatefulSet) (bool, []st | |||
| 				continue | ||||
| 			} | ||||
| 
 | ||||
| 			if check.containerCondition(&containerA, &containerB) { | ||||
| 			if !check.containerCondition(&containerA, &containerB) { | ||||
| 				continue | ||||
| 			} | ||||
| 
 | ||||
| 			if util.IsTrue(check.result.needsRollUpdate) { | ||||
| 				needsRollUpdate = true | ||||
| 				reasons = append(reasons, fmt.Sprintf(check.reason, index)) | ||||
| 			} | ||||
|  |  | |||
|  | @ -25,7 +25,7 @@ func True() *bool { | |||
| } | ||||
| 
 | ||||
| type Result struct { | ||||
| 	differs         *bool | ||||
| 	needUpdate      *bool | ||||
| 	needsRollUpdate *bool | ||||
| 	needsReplace    *bool | ||||
| } | ||||
|  | @ -60,11 +60,11 @@ func (c *Cluster) getStatefulSetChecks() []ResourceCheck { | |||
| 	return []ResourceCheck{ | ||||
| 		c.NewCheck("new statefulset's number of replicas doesn't match the current one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { return a.Spec.Replicas != b.Spec.Replicas }, | ||||
| 			Result{differs: True()}), | ||||
| 			Result{needUpdate: True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's annotations doesn't match the current one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { return !reflect.DeepEqual(a.Annotations, b.Annotations) }, | ||||
| 			Result{differs: True()}), | ||||
| 			Result{needUpdate: True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's serviceAccountName service asccount name doesn't match the current one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { | ||||
|  | @ -99,7 +99,7 @@ func (c *Cluster) getStatefulSetChecks() []ResourceCheck { | |||
| 		c.NewCheck("new statefulset's pod template metadata annotations doesn't match the current one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { | ||||
| 				return !reflect.DeepEqual(a.Spec.Template.Annotations, b.Spec.Template.Annotations) | ||||
| 			}, Result{differs: True(), needsRollUpdate: True(), needsReplace: True()}), | ||||
| 			}, Result{needUpdate: True(), needsRollUpdate: True(), needsReplace: True()}), | ||||
| 
 | ||||
| 		c.NewCheck("new statefulset's volumeClaimTemplates contains different number of volumes to the old one", | ||||
| 			func(a, b *v1beta1.StatefulSet) bool { | ||||
|  |  | |||
|  | @ -286,7 +286,7 @@ func (c *Cluster) syncStatefulSet() error { | |||
| 		c.setRollingUpdateFlagForStatefulSet(desiredSS, podsRollingUpdateRequired) | ||||
| 
 | ||||
| 		cmp := c.compareStatefulSetWith(desiredSS) | ||||
| 		if !cmp.match { | ||||
| 		if cmp.update { | ||||
| 			if cmp.rollingUpdate && !podsRollingUpdateRequired { | ||||
| 				podsRollingUpdateRequired = true | ||||
| 				c.setRollingUpdateFlagForStatefulSet(desiredSS, podsRollingUpdateRequired) | ||||
|  |  | |||
|  | @ -126,3 +126,7 @@ func Coalesce(val, defaultVal string) string { | |||
| 	} | ||||
| 	return val | ||||
| } | ||||
| 
 | ||||
| func IsTrue(value *bool) bool { | ||||
| 	return value != nil && *value | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue