-
Notifications
You must be signed in to change notification settings - Fork 8
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
OADP-1830: Only create VSR if it does not exist for a VSB #15
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -50,59 +50,67 @@ func (p *VolumeSnapshotBackupRestoreItemActionV2) Execute(input *velero.RestoreI | |||||
|
||||||
operationID := "" | ||||||
|
||||||
// create VSR per VSB | ||||||
vsr := datamoverv1alpha1.VolumeSnapshotRestore{ | ||||||
ObjectMeta: metav1.ObjectMeta{ | ||||||
GenerateName: "vsr-", | ||||||
Namespace: vsb.Namespace, | ||||||
Labels: map[string]string{ | ||||||
util.RestoreNameLabel: input.Restore.Name, | ||||||
util.BackupNameLabel: vsb.Labels[util.BackupNameLabel], | ||||||
util.PersistentVolumeClaimLabel: vsb.Annotations[util.VolumeSnapshotMoverSourcePVCName], | ||||||
util.VolumeSnapshotBackupLabel: vsb.Name, | ||||||
}, | ||||||
}, | ||||||
Spec: datamoverv1alpha1.VolumeSnapshotRestoreSpec{ | ||||||
ResticSecretRef: corev1.LocalObjectReference{ | ||||||
Name: vsb.Spec.ResticSecretRef.Name, | ||||||
// check if VolumeSnaphotRestore CR exists for VolumeSnaoshotBackup | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
VSRExists, err := util.VSRExistsForVSB(&vsb, p.Log) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
if !VSRExists { | ||||||
// create VSR per VSB | ||||||
vsr := datamoverv1alpha1.VolumeSnapshotRestore{ | ||||||
ObjectMeta: metav1.ObjectMeta{ | ||||||
GenerateName: "vsr-", | ||||||
Namespace: vsb.Namespace, | ||||||
Labels: map[string]string{ | ||||||
util.RestoreNameLabel: input.Restore.Name, | ||||||
util.BackupNameLabel: vsb.Labels[util.BackupNameLabel], | ||||||
util.PersistentVolumeClaimLabel: vsb.Annotations[util.VolumeSnapshotMoverSourcePVCName], | ||||||
util.VolumeSnapshotBackupLabel: vsb.Name, | ||||||
}, | ||||||
}, | ||||||
VolumeSnapshotMoverBackupref: datamoverv1alpha1.VSBRef{ | ||||||
BackedUpPVCData: datamoverv1alpha1.PVCData{ | ||||||
Name: vsb.Annotations[util.VolumeSnapshotMoverSourcePVCName], | ||||||
Size: vsb.Annotations[util.VolumeSnapshotMoverSourcePVCSize], | ||||||
StorageClassName: vsb.Annotations[util.VolumeSnapshotMoverSourcePVCStorageClass], | ||||||
Spec: datamoverv1alpha1.VolumeSnapshotRestoreSpec{ | ||||||
ResticSecretRef: corev1.LocalObjectReference{ | ||||||
Name: vsb.Spec.ResticSecretRef.Name, | ||||||
}, | ||||||
ResticRepository: vsb.Annotations[util.VolumeSnapshotMoverResticRepository], | ||||||
VolumeSnapshotClassName: vsb.Annotations[util.VolumeSnapshotMoverVolumeSnapshotClass], | ||||||
VolumeSnapshotMoverBackupref: datamoverv1alpha1.VSBRef{ | ||||||
BackedUpPVCData: datamoverv1alpha1.PVCData{ | ||||||
Name: vsb.Annotations[util.VolumeSnapshotMoverSourcePVCName], | ||||||
Size: vsb.Annotations[util.VolumeSnapshotMoverSourcePVCSize], | ||||||
StorageClassName: vsb.Annotations[util.VolumeSnapshotMoverSourcePVCStorageClass], | ||||||
}, | ||||||
ResticRepository: vsb.Annotations[util.VolumeSnapshotMoverResticRepository], | ||||||
VolumeSnapshotClassName: vsb.Annotations[util.VolumeSnapshotMoverVolumeSnapshotClass], | ||||||
}, | ||||||
ProtectedNamespace: vsb.Spec.ProtectedNamespace, | ||||||
}, | ||||||
ProtectedNamespace: vsb.Spec.ProtectedNamespace, | ||||||
}, | ||||||
} | ||||||
} | ||||||
|
||||||
vsrClient, err := util.GetVolumeSnapshotMoverClient() | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
vsrClient, err := util.GetVolumeSnapshotMoverClient() | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
// if namespace mapping is specified | ||||||
if val, ok := input.Restore.Spec.NamespaceMapping[vsr.GetNamespace()]; ok { | ||||||
vsr.SetNamespace(val) | ||||||
} | ||||||
// if namespace mapping is specified | ||||||
if val, ok := input.Restore.Spec.NamespaceMapping[vsr.GetNamespace()]; ok { | ||||||
vsr.SetNamespace(val) | ||||||
} | ||||||
|
||||||
err = vsrClient.Create(context.Background(), &vsr) | ||||||
if err != nil { | ||||||
return nil, errors.Wrapf(err, "error creating volumesnapshotrestore CR") | ||||||
} | ||||||
p.Log.Infof("[vsb-restore] vsr created: %s", vsr.Name) | ||||||
err = vsrClient.Create(context.Background(), &vsr) | ||||||
if err != nil { | ||||||
return nil, errors.Wrapf(err, "error creating volumesnapshotrestore CR") | ||||||
} | ||||||
p.Log.Infof("[vsb-restore] vsr created: %s", vsr.Name) | ||||||
|
||||||
// fetch the VSR so we get the name of the VSR as we use generate name for VSR CR creation | ||||||
err = vsrClient.Get(context.Background(), client.ObjectKey{Namespace: vsr.Namespace, Name: vsr.Name}, &vsr) | ||||||
if err != nil { | ||||||
return nil, errors.Wrapf(err, "error fetching volumesnapshotrestore CR for suppyling operationID") | ||||||
} | ||||||
// fetch the VSR so we get the name of the VSR as we use generate name for VSR CR creation | ||||||
err = vsrClient.Get(context.Background(), client.ObjectKey{Namespace: vsr.Namespace, Name: vsr.Name}, &vsr) | ||||||
if err != nil { | ||||||
return nil, errors.Wrapf(err, "error fetching volumesnapshotrestore CR for suppyling operationID") | ||||||
} | ||||||
|
||||||
// operationID for our datamover usecase is VSR NamespacedName which will unique per operation | ||||||
operationID = vsr.Namespace + "/" + vsr.Name | ||||||
// operationID for our datamover usecase is VSR NamespacedName which will unique per operation | ||||||
operationID = vsr.Namespace + "/" + vsr.Name | ||||||
} | ||||||
|
||||||
p.Log.Info("Returning from VolumeSnapshotBackupRestoreItemActionV2") | ||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to add backup UID here?
backup.Name isn't going to cause any issues here but it would be helpful to be able to compare if backup CR in the cluster still applies to this VSB.