Skip to content

Commit

Permalink
OADP-2283: Remove vsc for datamover case (#278)
Browse files Browse the repository at this point in the history
* remove vsc for datamover case

* Move datamover deletion logic to datamover pkg

* run make update
  • Loading branch information
shubham-pampattiwar authored Jul 18, 2023
1 parent e82b445 commit 00e85af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/controller/backup_finalizer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ func (r *backupFinalizerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
deleteVolumeSnapshots(volumeSnapshots, volumeSnapshotContents, log, 30, r.client, r.volumeSnapshotClient, r.resourceTimeout)
}
// check if the VSBs associated with the backup are in completed state, if yes then clean them up
err = datamover.DeleteVSBsIfComplete(backup.Name, r.log)
// Also cleanup the datamover VSCs
err = datamover.CleanupDatamoverArtifacts(backup.Name, r.log, *vscList, r.volumeSnapshotClient)
if err != nil {
log.Error(err)
}
Expand Down
15 changes: 14 additions & 1 deletion pkg/datamover/datamover.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"fmt"
"time"

snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
snapshotterClientSet "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"

snapmoverv1alpha1 "github.com/konveyor/volume-snapshot-mover/api/v1alpha1"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -37,7 +40,7 @@ func GetVolumeSnapMoverClient() (kbclient.Client, error) {
return client, err
}

func DeleteVSBsIfComplete(backupName string, log logrus.FieldLogger) error {
func CleanupDatamoverArtifacts(backupName string, log logrus.FieldLogger, vscList snapshotv1api.VolumeSnapshotContentList, volumeSnapshotClient snapshotterClientSet.Interface) error {
volumeSnapMoverClient, err := GetVolumeSnapMoverClient()
if err != nil {
log.Errorf(err.Error())
Expand All @@ -55,6 +58,7 @@ func DeleteVSBsIfComplete(backupName string, log logrus.FieldLogger) error {
return err
}

// clean up VSBs as well as VSCs, VSB existence implies that the VSCs are from datamover workflow
if len(VSBList.Items) > 0 {
err = CheckIfVolumeSnapshotBackupsAreComplete(context.Background(), VSBList, log)
if err != nil {
Expand All @@ -71,6 +75,15 @@ func DeleteVSBsIfComplete(backupName string, log logrus.FieldLogger) error {
return err
}
}

// Delete the VSCs
for _, vsc := range vscList.Items {
log.Infof("Cleaning up datamover VSC: %s", vsc.Name)
err := volumeSnapshotClient.SnapshotV1().VolumeSnapshotContents().Delete(context.TODO(), vsc.Name, metav1.DeleteOptions{})
if err != nil {
log.Errorf("fail to delete VolumeSnapshotContent %s: %s", vsc.Namespace, err.Error())
}
}
}
return nil
}
Expand Down

0 comments on commit 00e85af

Please sign in to comment.