@@ -377,51 +377,37 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *v1beta1.StatefulSet) *comp
377377 return & compareStatefulsetResult {match : match , reasons : reasons , rollingUpdate : needsRollUpdate , replace : needsReplace }
378378}
379379
380+ type ContainerCondition func (a , b v1.Container ) bool
381+
380382type ContainerCheck struct {
381- condition func ( a , b v1. Container ) bool
383+ condition ContainerCondition
382384 reason string
383385}
384386
387+ func NewCheck (msg string , cond ContainerCondition ) ContainerCheck {
388+ return ContainerCheck {reason : msg , condition : cond }
389+ }
390+
385391// compareContainers: compare containers from two stateful sets
386392// and return:
387393// * whether or not roll update is needed
388394// * a list of reasons in a human readable format
389395func (c * Cluster ) compareContainers (setA , setB * v1beta1.StatefulSet ) (bool , []string ) {
390396 reasons := make ([]string , 0 )
391397 needsRollUpdate := false
392- checks := map [string ]ContainerCheck {
393- "name" : ContainerCheck {
394- condition : func (a , b v1.Container ) bool { return a .Name != b .Name },
395- reason : "new statefulset's container %d name doesn't match the current one" ,
396- },
397- "image" : ContainerCheck {
398- condition : func (a , b v1.Container ) bool { return a .Image != b .Image },
399- reason : "new statefulset's container %d image doesn't match the current one" ,
400- },
401- "ports" : ContainerCheck {
402- condition : func (a , b v1.Container ) bool {
403- return ! reflect .DeepEqual (a .Ports , b .Ports )
404- },
405- reason : "new statefulset's container %d ports don't match the current one" ,
406- },
407- "resourses" : ContainerCheck {
408- condition : func (a , b v1.Container ) bool {
409- return ! compareResources (& a .Resources , & b .Resources )
410- },
411- reason : "new statefulset's container %d resources don't match the current ones" ,
412- },
413- "env" : ContainerCheck {
414- condition : func (a , b v1.Container ) bool {
415- return ! reflect .DeepEqual (a .Env , b .Env )
416- },
417- reason : "new statefulset's container %d environment doesn't match the current one" ,
418- },
419- "env_from" : ContainerCheck {
420- condition : func (a , b v1.Container ) bool {
421- return ! reflect .DeepEqual (a .EnvFrom , b .EnvFrom )
422- },
423- reason : "new statefulset's container %d environment sources don't match the current one" ,
424- },
398+ checks := []ContainerCheck {
399+ NewCheck ("new statefulset's container %d name doesn't match the current one" ,
400+ func (a , b v1.Container ) bool { return a .Name != b .Name }),
401+ NewCheck ("new statefulset's container %d image doesn't match the current one" ,
402+ func (a , b v1.Container ) bool { return a .Image != b .Image }),
403+ NewCheck ("new statefulset's container %d ports don't match the current one" ,
404+ func (a , b v1.Container ) bool { return ! reflect .DeepEqual (a .Ports , b .Ports ) }),
405+ NewCheck ("new statefulset's container %d resources don't match the current ones" ,
406+ func (a , b v1.Container ) bool { return ! compareResources (& a .Resources , & b .Resources ) }),
407+ NewCheck ("new statefulset's container %d environment doesn't match the current one" ,
408+ func (a , b v1.Container ) bool { return ! reflect .DeepEqual (a .Env , b .Env ) }),
409+ NewCheck ("new statefulset's container %d environment sources don't match the current one" ,
410+ func (a , b v1.Container ) bool { return ! reflect .DeepEqual (a .EnvFrom , b .EnvFrom ) }),
425411 }
426412
427413 for index , containerA := range setA .Spec .Template .Spec .Containers {
0 commit comments