Skip to content

Commit

Permalink
clean temp vsclass for dm restore (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemcmullan authored and sseago committed Feb 13, 2023
1 parent a519b2f commit 86988f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/controller/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
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 86988f2

Please sign in to comment.