From f105da2ab3f221fce8389f95f5ae56150735f20a Mon Sep 17 00:00:00 2001 From: Angel Misevski Date: Fri, 3 Jun 2022 18:24:34 -0400 Subject: [PATCH] Fix ignoring order of volumeMounts when comparing deployments Since support for subpath automount volumes was added, the comparison function used to ignore the order of volumeMounts in a deployment is no longer valid, as multiple volumeMounts can use the same volume. This can result in spurious changes to the deployment's spec, if the operator reads volumes in a random order. To fix this, also compare mountPath and subPath. The comparison function for other slices is unchanged, as in those cases the name is a key in the list and must be unique. Signed-off-by: Angel Misevski --- pkg/provision/sync/diffopts.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/provision/sync/diffopts.go b/pkg/provision/sync/diffopts.go index 37214c512..ca5111e58 100644 --- a/pkg/provision/sync/diffopts.go +++ b/pkg/provision/sync/diffopts.go @@ -48,7 +48,17 @@ var deploymentDiffOpts = cmp.Options{ return strings.Compare(a.Name, b.Name) > 0 }), cmpopts.SortSlices(func(a, b corev1.VolumeMount) bool { - return strings.Compare(a.Name, b.Name) > 0 + switch { + case a.Name != b.Name: + return strings.Compare(a.Name, b.Name) > 0 + case a.MountPath != b.MountPath: + return strings.Compare(a.MountPath, b.MountPath) > 0 + case a.SubPath != b.SubPath: + return strings.Compare(a.SubPath, b.SubPath) > 0 + default: + // If mountPath + subPath match, the deployment is invalid, so this cannot happen. + return false + } }), cmpopts.SortSlices(func(a, b corev1.EnvFromSource) bool { return strings.Compare(getNameFromEnvFrom(a), getNameFromEnvFrom(b)) > 0