Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VolumeSnapshotClass info in the DataUpload. #216

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading