Skip to content

Commit

Permalink
Wait for snapshot to be deleted in DeleteCSISnapshot function (#1210)
Browse files Browse the repository at this point in the history
* Add poll.Wait() for CSI snapshot to be deleted

* Fix gofmt errors

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
Shlok Chaudhari and mergify[bot] committed Jan 29, 2022
1 parent 5068148 commit abfbcbd
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/function/delete_csi_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import (
"context"

v1 "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"

kanister "github.com/kanisterio/kanister/pkg"
"github.com/kanisterio/kanister/pkg/kube"
"github.com/kanisterio/kanister/pkg/kube/snapshot"
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/poll"
)

func init() {
Expand Down Expand Up @@ -71,6 +73,9 @@ func (*deleteCSISnapshotFunc) Exec(ctx context.Context, tp param.TemplateParams,
if _, err := deleteCSISnapshot(ctx, snapshotter, name, namespace); err != nil {
return nil, err
}
if err := waitForCSISnapshotDeletion(ctx, snapshotter, name, namespace); err != nil {
return nil, err
}
return nil, nil
}

Expand All @@ -84,3 +89,13 @@ func (*deleteCSISnapshotFunc) RequiredArgs() []string {
func deleteCSISnapshot(ctx context.Context, snapshotter snapshot.Snapshotter, name, namespace string) (*v1.VolumeSnapshot, error) {
return snapshotter.Delete(ctx, name, namespace)
}

func waitForCSISnapshotDeletion(ctx context.Context, snapshotter snapshot.Snapshotter, name, namespace string) error {
return poll.Wait(ctx, func(context.Context) (done bool, err error) {
_, err = snapshotter.Get(ctx, name, namespace)
if apierrors.IsNotFound(err) {
return true, nil
}
return false, err
})
}

0 comments on commit abfbcbd

Please sign in to comment.