diff --git a/go.mod b/go.mod index b24b1384f..23da0ce29 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/container-storage-interface/spec v1.9.0 github.com/evanphx/json-patch v5.9.0+incompatible github.com/fsnotify/fsnotify v1.7.0 + github.com/go-openapi/jsonpointer v0.21.0 github.com/golang/mock v1.6.0 github.com/google/gofuzz v1.2.0 github.com/kubernetes-csi/csi-lib-utils v0.18.0 @@ -33,7 +34,6 @@ require ( github.com/emicklei/go-restful/v3 v3.12.0 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/go-openapi/jsonpointer v0.21.0 // indirect github.com/go-openapi/jsonreference v0.21.0 // indirect github.com/go-openapi/swag v0.23.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect diff --git a/pkg/common-controller/groupsnapshot_controller_helper.go b/pkg/common-controller/groupsnapshot_controller_helper.go index 69da282c2..f26406266 100644 --- a/pkg/common-controller/groupsnapshot_controller_helper.go +++ b/pkg/common-controller/groupsnapshot_controller_helper.go @@ -21,6 +21,7 @@ import ( "fmt" "time" + "github.com/go-openapi/jsonpointer" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" apierrs "k8s.io/apimachinery/pkg/api/errors" @@ -672,6 +673,29 @@ func (ctrl *csiSnapshotCommonController) updateGroupSnapshotStatus(groupSnapshot if !utils.IsGroupSnapshotReady(groupSnapshotObj) && utils.IsGroupSnapshotReady(groupSnapshotClone) { msg := fmt.Sprintf("GroupSnapshot %s is ready to use.", utils.GroupSnapshotKey(groupSnapshot)) ctrl.eventRecorder.Event(groupSnapshot, v1.EventTypeNormal, "GroupSnapshotReady", msg) + + // The VolumeGroupSnapshot resource is now ready to use. There's no need for the + // groupsnapshot.storage.kubernetes.io/info annotation anymore so we can remove it. + if metav1.HasAnnotation(groupSnapshotContent.ObjectMeta, utils.AnnSnapshotInfo) { + klog.V(5).Infof("updateGroupSnapshotStatus[%s]: removing info annotation on VolumeGroupSnapshotContent[%s]", + groupSnapshot.Name, + groupSnapshotContent.Name) + patches := []utils.PatchOp{ + { + Op: "remove", + Path: fmt.Sprintf("/metadata/annotations/%s", jsonpointer.Escape(utils.AnnSnapshotInfo)), + }, + } + + _, err := utils.PatchVolumeGroupSnapshotContent(groupSnapshotContent, patches, ctrl.clientset) + if err != nil { + klog.V(5).Infof("updateGroupSnapshotStatus[%s]: error while removing info annotation on VolumeGroupSnapshotContent[%s]: %s", + groupSnapshot.Name, + groupSnapshotContent.Name, + err.Error()) + return nil, newControllerUpdateError(utils.GroupSnapshotKey(groupSnapshot), err.Error()) + } + } } newGroupSnapshotObj, err := ctrl.clientset.GroupsnapshotV1alpha1().VolumeGroupSnapshots(groupSnapshotClone.Namespace).UpdateStatus(context.TODO(), groupSnapshotClone, metav1.UpdateOptions{})