Skip to content

Commit

Permalink
Remove info annotation when the VolumeGroupSnapshot is ready to use
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardoce committed May 14, 2024
1 parent 81474e7 commit c69d79b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions pkg/common-controller/groupsnapshot_controller_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})
Expand Down

0 comments on commit c69d79b

Please sign in to comment.