Skip to content

Commit e71891e

Browse files
authored
improve logical backup comparison unit test and improve container sync (zalando#2686)
* improve logical backup comparison unit test and improve container sync * add new comparison function for volume mounts + unit test
1 parent 37d6993 commit e71891e

File tree

3 files changed

+334
-15
lines changed

3 files changed

+334
-15
lines changed

pkg/cluster/cluster.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ func (c *Cluster) compareContainers(description string, setA, setB []v1.Containe
597597
newCheck("new %s's %s (index %d) security context does not match the current one",
598598
func(a, b v1.Container) bool { return !reflect.DeepEqual(a.SecurityContext, b.SecurityContext) }),
599599
newCheck("new %s's %s (index %d) volume mounts do not match the current one",
600-
func(a, b v1.Container) bool { return !reflect.DeepEqual(a.VolumeMounts, b.VolumeMounts) }),
600+
func(a, b v1.Container) bool { return !compareVolumeMounts(a.VolumeMounts, b.VolumeMounts) }),
601601
}
602602

603603
if !c.OpConfig.EnableLazySpiloUpgrade {
@@ -738,6 +738,27 @@ func comparePorts(a, b []v1.ContainerPort) bool {
738738
return true
739739
}
740740

741+
func compareVolumeMounts(old, new []v1.VolumeMount) bool {
742+
if len(old) != len(new) {
743+
return false
744+
}
745+
for _, mount := range old {
746+
if !volumeMountExists(mount, new) {
747+
return false
748+
}
749+
}
750+
return true
751+
}
752+
753+
func volumeMountExists(mount v1.VolumeMount, mounts []v1.VolumeMount) bool {
754+
for _, m := range mounts {
755+
if reflect.DeepEqual(mount, m) {
756+
return true
757+
}
758+
}
759+
return false
760+
}
761+
741762
func (c *Cluster) compareAnnotations(old, new map[string]string) (bool, string) {
742763
reason := ""
743764
ignoredAnnotations := make(map[string]bool)

0 commit comments

Comments
 (0)