From 86988f21ec314e24d630cc94bec946fe8a935902 Mon Sep 17 00:00:00 2001 From: Emily McMullan Date: Fri, 16 Sep 2022 10:50:29 -0400 Subject: [PATCH] clean temp vsclass for dm restore (#197) --- pkg/controller/backup_controller.go | 8 +++++++- pkg/datamover/datamover.go | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pkg/controller/backup_controller.go b/pkg/controller/backup_controller.go index a14bbce5cf..d1e96fd2e1 100644 --- a/pkg/controller/backup_controller.go +++ b/pkg/controller/backup_controller.go @@ -22,13 +22,13 @@ import ( "context" "encoding/json" "fmt" - "github.com/vmware-tanzu/velero/pkg/datamover" "io" "io/ioutil" "os" "sync" "time" + "github.com/vmware-tanzu/velero/pkg/datamover" jsonpatch "github.com/evanphx/json-patch" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -656,6 +656,12 @@ func (c *backupController) runBackup(backup *pkgbackup.Request) error { if err != nil { backupLog.Error(err) } + + // delete temp VSClass created for data mover restore + err := datamover.DeleteTempVSClass(backup.Name, c.volumeSnapshotClassLister, c.volumeSnapshotClient) + if err != nil { + backupLog.Error(err) + } } vsClassSet := sets.NewString() diff --git a/pkg/datamover/datamover.go b/pkg/datamover/datamover.go index 32ce983147..986a85fa24 100644 --- a/pkg/datamover/datamover.go +++ b/pkg/datamover/datamover.go @@ -9,9 +9,12 @@ import ( "github.com/apex/log" snapmoverv1alpha1 "github.com/konveyor/volume-snapshot-mover/api/v1alpha1" + snapshotterClientSet "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned" + snapshotv1listers "github.com/kubernetes-csi/external-snapshotter/client/v4/listers/volumesnapshot/v1" "github.com/pkg/errors" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" "golang.org/x/sync/errgroup" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" kbclient "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/client/config" @@ -118,3 +121,19 @@ func WaitForDataMoverBackupToComplete(backupName string) error { } return nil } + +func DeleteTempVSClass(backupName string, tempVS snapshotv1listers.VolumeSnapshotClassLister, client *snapshotterClientSet.Clientset) error { + + tempVSClass, err := tempVS.Get(fmt.Sprintf("%s-snapclass", backupName)) + if err != nil { + log.Errorf("failed to get temp vsClass %v", tempVSClass.Name) + return err + } + + err = client.SnapshotV1().VolumeSnapshotClasses().Delete(context.TODO(), tempVSClass.Name, metav1.DeleteOptions{}) + if err != nil { + log.Errorf("failed to delete temp vsClass %v", tempVSClass.Name) + return err + } + return nil +}