Reset VolumeSnapshotRef in Backup Sync Flow (#8005)
Signed-off-by: Anshul Ahuja <anshulahuja@microsoft.com> Co-authored-by: Anshul Ahuja <anshulahuja@microsoft.com>release-1.13
parent
5158490834
commit
89be8e00d3
|
@ -40,6 +40,7 @@ import (
|
||||||
"github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt"
|
"github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt"
|
||||||
"github.com/vmware-tanzu/velero/pkg/util/kube"
|
"github.com/vmware-tanzu/velero/pkg/util/kube"
|
||||||
|
|
||||||
|
corev1api "k8s.io/api/core/v1"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
)
|
)
|
||||||
|
@ -272,6 +273,20 @@ func (b *backupSyncReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
||||||
for _, snapCont := range snapConts {
|
for _, snapCont := range snapConts {
|
||||||
// TODO: Reset ResourceVersion prior to persisting VolumeSnapshotContents
|
// TODO: Reset ResourceVersion prior to persisting VolumeSnapshotContents
|
||||||
snapCont.ResourceVersion = ""
|
snapCont.ResourceVersion = ""
|
||||||
|
// Make the VolumeSnapshotContent static
|
||||||
|
snapCont.Spec.Source = snapshotv1api.VolumeSnapshotContentSource{
|
||||||
|
SnapshotHandle: snapCont.Status.SnapshotHandle,
|
||||||
|
}
|
||||||
|
// Set VolumeSnapshotRef to none exist one, because VolumeSnapshotContent
|
||||||
|
// validation webhook will check whether name and namespace are nil.
|
||||||
|
// external-snapshotter needs Source pointing to snapshot and VolumeSnapshot
|
||||||
|
// reference's UID to nil to determine the VolumeSnapshotContent is deletable.
|
||||||
|
snapCont.Spec.VolumeSnapshotRef = corev1api.ObjectReference{
|
||||||
|
APIVersion: snapshotv1api.SchemeGroupVersion.String(),
|
||||||
|
Kind: "VolumeSnapshot",
|
||||||
|
Namespace: "ns-" + string(snapCont.UID),
|
||||||
|
Name: "name-" + string(snapCont.UID),
|
||||||
|
}
|
||||||
err := b.client.Create(ctx, snapCont, &client.CreateOptions{})
|
err := b.client.Create(ctx, snapCont, &client.CreateOptions{})
|
||||||
switch {
|
switch {
|
||||||
case err != nil && apierrors.IsAlreadyExists(err):
|
case err != nil && apierrors.IsAlreadyExists(err):
|
||||||
|
|
Loading…
Reference in New Issue