Skip to content

Commit a388bb6

Browse files
authored
Merge pull request #1302 from ConnorJC3/fix-content-resync
Queue resyncs in `ShouldEnqueueContentChange`
2 parents 7e30553 + a555af7 commit a388bb6

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

pkg/utils/util.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,10 @@ func GetDynamicSnapshotContentNameForGroupSnapshot(groupSnapshot *crdv1beta1.Vol
680680
// If the VolumeSnapshotContent object still contains other changes after this sanitization, the changes
681681
// are potentially meaningful and the object is enqueued to be considered for syncing
682682
func ShouldEnqueueContentChange(old *crdv1.VolumeSnapshotContent, new *crdv1.VolumeSnapshotContent) bool {
683+
// Always enqueue resyncs, which show up as an update with no change (thus no new version)
684+
if old.ResourceVersion == new.ResourceVersion {
685+
return true
686+
}
683687
sanitized := new.DeepCopy()
684688
// ResourceVersion always changes between revisions
685689
sanitized.ResourceVersion = old.ResourceVersion
@@ -693,7 +697,7 @@ func ShouldEnqueueContentChange(old *crdv1.VolumeSnapshotContent, new *crdv1.Vol
693697
if sanitized.Annotations == nil {
694698
sanitized.Annotations = map[string]string{}
695699
}
696-
for annotation, _ := range sidecarControlledContentAnnotations {
700+
for annotation := range sidecarControlledContentAnnotations {
697701
if value, ok := old.Annotations[annotation]; ok {
698702
sanitized.Annotations[annotation] = value
699703
} else {
@@ -702,7 +706,7 @@ func ShouldEnqueueContentChange(old *crdv1.VolumeSnapshotContent, new *crdv1.Vol
702706
}
703707
} else {
704708
// Old content has no annotations, so delete any sidecar-controlled annotations present on the new content
705-
for annotation, _ := range sidecarControlledContentAnnotations {
709+
for annotation := range sidecarControlledContentAnnotations {
706710
delete(sanitized.Annotations, annotation)
707711
}
708712
}

pkg/utils/util_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,30 @@ func TestShouldEnqueueContentChange(t *testing.T) {
489489
},
490490
expectedResult: true,
491491
},
492+
{
493+
name: "resync from informer (old matches new including resource version)",
494+
old: &crdv1.VolumeSnapshotContent{
495+
ObjectMeta: metav1.ObjectMeta{
496+
ResourceVersion: oldValue,
497+
},
498+
},
499+
new: &crdv1.VolumeSnapshotContent{
500+
ObjectMeta: metav1.ObjectMeta{
501+
ResourceVersion: oldValue,
502+
},
503+
},
504+
expectedResult: true,
505+
},
492506
}
493507
for _, tc := range testcases {
494508
t.Run(tc.name, func(t *testing.T) {
509+
// Inject resource version unless it is already set in test object
510+
if tc.old.ResourceVersion == "" {
511+
tc.old.ResourceVersion = oldValue
512+
}
513+
if tc.new.ResourceVersion == "" {
514+
tc.old.ResourceVersion = newValue
515+
}
495516
result := ShouldEnqueueContentChange(tc.old, tc.new)
496517
if result != tc.expectedResult {
497518
t.Fatalf("Incorrect result: Expected %v received %v", tc.expectedResult, result)

0 commit comments

Comments
 (0)