Use patch for snapshot-controller when there are no finalizers

- Also address PR feedback re: avoid a deepCopy for annotations patch

Signed-off-by: Grant Griffiths <ggriffiths@purestorage.com>
This commit is contained in:
Grant Griffiths
2021-09-29 16:23:42 -07:00
parent 0ccf801780
commit d14e2eea8f
3 changed files with 20 additions and 29 deletions

View File

@@ -583,18 +583,23 @@ func (ctrl *csiSnapshotSideCarController) setAnnVolumeSnapshotBeingCreated(conte
}
// Set AnnVolumeSnapshotBeingCreated
// Combine existing annotations with the new annotations.
// If there are no existing annotations, we create a new map.
klog.V(5).Infof("setAnnVolumeSnapshotBeingCreated: set annotation [%s:yes] on content [%s].", utils.AnnVolumeSnapshotBeingCreated, content.Name)
contentClone := content.DeepCopy()
metav1.SetMetaDataAnnotation(&contentClone.ObjectMeta, utils.AnnVolumeSnapshotBeingCreated, "yes")
patchedAnnotations := make(map[string]string)
for k, v := range content.GetAnnotations() {
patchedAnnotations[k] = v
}
patchedAnnotations[utils.AnnVolumeSnapshotBeingCreated] = "yes"
var patches []utils.PatchOp
patches = append(patches, utils.PatchOp{
Op: "replace",
Path: "/metadata/annotations",
Value: contentClone.ObjectMeta.GetAnnotations(),
Value: patchedAnnotations,
})
patchedContent, err := utils.PatchVolumeSnapshotContent(contentClone, patches, ctrl.clientset)
patchedContent, err := utils.PatchVolumeSnapshotContent(content, patches, ctrl.clientset)
if err != nil {
return content, newControllerUpdateError(content.Name, err.Error())
}