Skip to content

Commit

Permalink
improve logical backup comparison unit test and improve container sync (
Browse files Browse the repository at this point in the history
#2686)

* improve logical backup comparison unit test and improve container sync
* add new comparison function for volume mounts + unit test
  • Loading branch information
FxKu committed Jul 8, 2024
1 parent 37d6993 commit e71891e
Show file tree
Hide file tree
Showing 3 changed files with 334 additions and 15 deletions.
23 changes: 22 additions & 1 deletion pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ func (c *Cluster) compareContainers(description string, setA, setB []v1.Containe
newCheck("new %s's %s (index %d) security context does not match the current one",
func(a, b v1.Container) bool { return !reflect.DeepEqual(a.SecurityContext, b.SecurityContext) }),
newCheck("new %s's %s (index %d) volume mounts do not match the current one",
func(a, b v1.Container) bool { return !reflect.DeepEqual(a.VolumeMounts, b.VolumeMounts) }),
func(a, b v1.Container) bool { return !compareVolumeMounts(a.VolumeMounts, b.VolumeMounts) }),
}

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

func compareVolumeMounts(old, new []v1.VolumeMount) bool {
if len(old) != len(new) {
return false
}
for _, mount := range old {
if !volumeMountExists(mount, new) {
return false
}
}
return true
}

func volumeMountExists(mount v1.VolumeMount, mounts []v1.VolumeMount) bool {
for _, m := range mounts {
if reflect.DeepEqual(mount, m) {
return true
}
}
return false
}

func (c *Cluster) compareAnnotations(old, new map[string]string) (bool, string) {
reason := ""
ignoredAnnotations := make(map[string]bool)
Expand Down
Loading

0 comments on commit e71891e

Please sign in to comment.