Skip to content

Commit

Permalink
clean temp vsclass for dm restore (vmware-tanzu#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemcmullan authored Sep 16, 2022
1 parent 8b64192 commit 0e83f63
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/controller/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ 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"

"github.com/apex/log"
jsonpatch "github.com/evanphx/json-patch"
"github.com/pkg/errors"
Expand Down Expand Up @@ -667,6 +668,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()
Expand Down
19 changes: 19 additions & 0 deletions pkg/datamover/datamover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit 0e83f63

Please sign in to comment.