mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-22 10:38:30 +02:00
Use list of checks instead of a map
This commit is contained in:
+20
-34
@@ -377,11 +377,17 @@ func (c *Cluster) compareStatefulSetWith(statefulSet *v1beta1.StatefulSet) *comp
|
|||||||
return &compareStatefulsetResult{match: match, reasons: reasons, rollingUpdate: needsRollUpdate, replace: needsReplace}
|
return &compareStatefulsetResult{match: match, reasons: reasons, rollingUpdate: needsRollUpdate, replace: needsReplace}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ContainerCondition func(a, b v1.Container) bool
|
||||||
|
|
||||||
type ContainerCheck struct {
|
type ContainerCheck struct {
|
||||||
condition func(a, b v1.Container) bool
|
condition ContainerCondition
|
||||||
reason string
|
reason string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewCheck(msg string, cond ContainerCondition) ContainerCheck {
|
||||||
|
return ContainerCheck{reason: msg, condition: cond}
|
||||||
|
}
|
||||||
|
|
||||||
// compareContainers: compare containers from two stateful sets
|
// compareContainers: compare containers from two stateful sets
|
||||||
// and return:
|
// and return:
|
||||||
// * whether or not roll update is needed
|
// * whether or not roll update is needed
|
||||||
@@ -389,39 +395,19 @@ type ContainerCheck struct {
|
|||||||
func (c *Cluster) compareContainers(setA, setB *v1beta1.StatefulSet) (bool, []string) {
|
func (c *Cluster) compareContainers(setA, setB *v1beta1.StatefulSet) (bool, []string) {
|
||||||
reasons := make([]string, 0)
|
reasons := make([]string, 0)
|
||||||
needsRollUpdate := false
|
needsRollUpdate := false
|
||||||
checks := map[string]ContainerCheck{
|
checks := []ContainerCheck{
|
||||||
"name": ContainerCheck{
|
NewCheck("new statefulset's container %d name doesn't match the current one",
|
||||||
condition: func(a, b v1.Container) bool { return a.Name != b.Name },
|
func(a, b v1.Container) bool { return a.Name != b.Name }),
|
||||||
reason: "new statefulset's container %d name doesn't match the current one",
|
NewCheck("new statefulset's container %d image doesn't match the current one",
|
||||||
},
|
func(a, b v1.Container) bool { return a.Image != b.Image }),
|
||||||
"image": ContainerCheck{
|
NewCheck("new statefulset's container %d ports don't match the current one",
|
||||||
condition: func(a, b v1.Container) bool { return a.Image != b.Image },
|
func(a, b v1.Container) bool { return !reflect.DeepEqual(a.Ports, b.Ports) }),
|
||||||
reason: "new statefulset's container %d image doesn't match the current one",
|
NewCheck("new statefulset's container %d resources don't match the current ones",
|
||||||
},
|
func(a, b v1.Container) bool { return !compareResources(&a.Resources, &b.Resources) }),
|
||||||
"ports": ContainerCheck{
|
NewCheck("new statefulset's container %d environment doesn't match the current one",
|
||||||
condition: func(a, b v1.Container) bool {
|
func(a, b v1.Container) bool { return !reflect.DeepEqual(a.Env, b.Env) }),
|
||||||
return !reflect.DeepEqual(a.Ports, b.Ports)
|
NewCheck("new statefulset's container %d environment sources don't match the current one",
|
||||||
},
|
func(a, b v1.Container) bool { return !reflect.DeepEqual(a.EnvFrom, b.EnvFrom) }),
|
||||||
reason: "new statefulset's container %d ports don't match the current one",
|
|
||||||
},
|
|
||||||
"resourses": ContainerCheck{
|
|
||||||
condition: func(a, b v1.Container) bool {
|
|
||||||
return !compareResources(&a.Resources, &b.Resources)
|
|
||||||
},
|
|
||||||
reason: "new statefulset's container %d resources don't match the current ones",
|
|
||||||
},
|
|
||||||
"env": ContainerCheck{
|
|
||||||
condition: func(a, b v1.Container) bool {
|
|
||||||
return !reflect.DeepEqual(a.Env, b.Env)
|
|
||||||
},
|
|
||||||
reason: "new statefulset's container %d environment doesn't match the current one",
|
|
||||||
},
|
|
||||||
"env_from": ContainerCheck{
|
|
||||||
condition: func(a, b v1.Container) bool {
|
|
||||||
return !reflect.DeepEqual(a.EnvFrom, b.EnvFrom)
|
|
||||||
},
|
|
||||||
reason: "new statefulset's container %d environment sources don't match the current one",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for index, containerA := range setA.Spec.Template.Spec.Containers {
|
for index, containerA := range setA.Spec.Template.Spec.Containers {
|
||||||
|
|||||||
Reference in New Issue
Block a user