Skip to content

Commit 69c10d1

Browse files
authored
fix(GcpNfsVolume): consider annotations equal if actual is superset o… (#288)
1 parent fa407c0 commit 69c10d1

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

pkg/skr/gcpnfsvolume/modifyPersistenceVolume.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,18 @@ func modifyPersistenceVolume(ctx context.Context, st composed.State) (error, con
4141
logger.Info("Detected modified PV capacity")
4242
}
4343

44-
//If labels are different, update PV labels.
45-
labels := getVolumeLabels(nfsVolume)
46-
if !areLabelsEqual(state.PV.Labels, labels) {
44+
expectedLabels := getVolumeLabels(nfsVolume)
45+
if !areLabelsEqual(state.PV.Labels, expectedLabels) {
4746
changed = true
48-
state.PV.Labels = labels
47+
state.PV.Labels = expectedLabels
4948
logger.Info("Detected modified PV labels")
5049
}
5150

52-
//If annotations are different, update PV annotations.
53-
annotations := getVolumeAnnotations(nfsVolume)
54-
if !areAnnotationsEqual(state.PV.Annotations, annotations) {
51+
expectedAnnotations := getVolumeAnnotations(nfsVolume)
52+
if !areAnnotationsSuperset(state.PV.Annotations, expectedAnnotations) {
5553
changed = true
56-
state.PV.Annotations = annotations
57-
logger.Info("Detected modified PV annotations")
54+
state.PV.Annotations = expectedAnnotations
55+
logger.Info("Detected desynced PV annotations")
5856
}
5957

6058
//No changes to PV, continue.

pkg/skr/gcpnfsvolume/modifyPersistentVolumeClaim.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ func modifyPersistentVolumeClaim(ctx context.Context, st composed.State) (error,
3535
logger.Info("Detected modified PVC capacity")
3636
}
3737

38-
labels := getVolumeClaimLabels(nfsVolume)
39-
labelsChanged := !areLabelsEqual(state.PVC.Labels, labels)
38+
expectedLabels := getVolumeClaimLabels(nfsVolume)
39+
labelsChanged := !areLabelsEqual(state.PVC.Labels, expectedLabels)
4040
if labelsChanged {
41-
state.PVC.Labels = labels
41+
state.PVC.Labels = expectedLabels
4242
logger.Info("Detected modified PVC labels")
4343
}
4444

45-
annotations := getVolumeClaimAnnotations(nfsVolume)
46-
annotationsChanged := !areAnnotationsEqual(state.PVC.Annotations, annotations)
47-
if annotationsChanged {
48-
state.PVC.Annotations = annotations
49-
logger.Info("Detected modified PVC annotations")
45+
expectedAnnotations := getVolumeClaimAnnotations(nfsVolume)
46+
annotationsDesynced := !areAnnotationsSuperset(state.PVC.Annotations, expectedAnnotations) // PVC controller will keep adding "pv.kubernetes.io/bind-completed=yes" annotation, so we must check if we are actual is superset of expected
47+
if annotationsDesynced {
48+
state.PVC.Annotations = expectedAnnotations
49+
logger.Info("Detected desynced PVC annotations")
5050
}
5151

52-
if !(capacityChanged || labelsChanged || annotationsChanged) {
52+
if !(capacityChanged || labelsChanged || annotationsDesynced) {
5353
return nil, nil
5454
}
5555

pkg/skr/gcpnfsvolume/util.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func gcpNfsVolumeCapacityToResourceQuantity(gcpVol *cloudresourcesv1beta1.GcpNfs
9090
return resource.NewQuantity(int64(gcpVol.Spec.CapacityGb)*1024*1024*1024, resource.BinarySI)
9191
}
9292

93-
func areMapsEqual(first, second map[string]string) bool {
93+
func areLabelsEqual(first, second map[string]string) bool {
9494
x := first
9595
y := second
9696

@@ -104,10 +104,11 @@ func areMapsEqual(first, second map[string]string) bool {
104104
return reflect.DeepEqual(x, y)
105105
}
106106

107-
func areLabelsEqual(first, second map[string]string) bool {
108-
return areMapsEqual(first, second)
109-
}
110-
111-
func areAnnotationsEqual(first, second map[string]string) bool {
112-
return areMapsEqual(first, second)
107+
func areAnnotationsSuperset(superset, subset map[string]string) bool {
108+
for key, value := range subset {
109+
if superset[key] != value {
110+
return false
111+
}
112+
}
113+
return true
113114
}

0 commit comments

Comments
 (0)