Skip to content

Commit

Permalink
Merge pull request #216 from blackpiglet/add_volume_snapshot_class
Browse files Browse the repository at this point in the history
Add VolumeSnapshotClass info in the DataUpload.
  • Loading branch information
Lyndon-Li authored Nov 28, 2023
2 parents 41cbf4a + 8162068 commit ef236d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions internal/backup/pvc_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (p *PVCBackupItemAction) Execute(item runtime.Unstructured, backup *velerov

dataUploadLog.Info("Starting data upload of backup")

dataUpload, err := createDataUpload(context.Background(), backup, p.CRClient, upd, &pvc, operationID)
dataUpload, err := createDataUpload(context.Background(), backup, p.CRClient, upd, &pvc, operationID, snapshotClass)
if err != nil {
dataUploadLog.WithError(err).Error("failed to submit DataUpload")
util.DeleteVolumeSnapshotIfAny(context.Background(), p.SnapshotClient, *upd, dataUploadLog)
Expand Down Expand Up @@ -303,7 +303,7 @@ func (p *PVCBackupItemAction) Cancel(operationID string, backup *velerov1api.Bac
}

func newDataUpload(backup *velerov1api.Backup, vs *snapshotv1api.VolumeSnapshot,
pvc *corev1api.PersistentVolumeClaim, operationID string) *velerov2alpha1.DataUpload {
pvc *corev1api.PersistentVolumeClaim, operationID string, vsClass *snapshotv1api.VolumeSnapshotClass) *velerov2alpha1.DataUpload {
dataUpload := &velerov2alpha1.DataUpload{
TypeMeta: metav1.TypeMeta{
APIVersion: velerov2alpha1.SchemeGroupVersion.String(),
Expand Down Expand Up @@ -333,6 +333,7 @@ func newDataUpload(backup *velerov1api.Backup, vs *snapshotv1api.VolumeSnapshot,
CSISnapshot: &velerov2alpha1.CSISnapshotSpec{
VolumeSnapshot: vs.Name,
StorageClass: *pvc.Spec.StorageClassName,
SnapshotClass: vsClass.Name,
},
SourcePVC: pvc.Name,
DataMover: backup.Spec.DataMover,
Expand All @@ -346,8 +347,9 @@ func newDataUpload(backup *velerov1api.Backup, vs *snapshotv1api.VolumeSnapshot,
}

func createDataUpload(ctx context.Context, backup *velerov1api.Backup, crClient crclient.Client,
vs *snapshotv1api.VolumeSnapshot, pvc *corev1api.PersistentVolumeClaim, operationID string) (*velerov2alpha1.DataUpload, error) {
dataUpload := newDataUpload(backup, vs, pvc, operationID)
vs *snapshotv1api.VolumeSnapshot, pvc *corev1api.PersistentVolumeClaim, operationID string,
vsClass *snapshotv1api.VolumeSnapshotClass) (*velerov2alpha1.DataUpload, error) {
dataUpload := newDataUpload(backup, vs, pvc, operationID, vsClass)

err := crClient.Create(ctx, dataUpload)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/backup/pvc_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestExecute(t *testing.T) {
pvc: builder.ForPersistentVolumeClaim("velero", "testPVC").VolumeName("testPV").StorageClass("testSC").Phase(corev1.ClaimBound).Result(),
pv: builder.ForPersistentVolume("testPV").CSI("hostpath", "testVolume").Result(),
sc: builder.ForStorageClass("testSC").Provisioner("hostpath").Result(),
vsClass: builder.ForVolumeSnapshotClass("tescVSClass").Driver("hostpath").ObjectMeta(builder.WithLabels(util.VolumeSnapshotClassSelectorLabel, "")).Result(),
vsClass: builder.ForVolumeSnapshotClass("testVSClass").Driver("hostpath").ObjectMeta(builder.WithLabels(util.VolumeSnapshotClassSelectorLabel, "")).Result(),
operationID: ".",
expectedErr: nil,
expectedDataUpload: &velerov2alpha1.DataUpload{
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestExecute(t *testing.T) {
CSISnapshot: &velerov2alpha1.CSISnapshotSpec{
VolumeSnapshot: "",
StorageClass: "testSC",
SnapshotClass: "",
SnapshotClass: "testVSClass",
},
SourcePVC: "testPVC",
SourceNamespace: "velero",
Expand Down

0 comments on commit ef236d9

Please sign in to comment.