mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-21 06:36:06 +00:00
Merge pull request #9706 from shubham-pampattiwar/cherry-pick-vgs-v1beta2-release-1.18
[release-1.18] Bump external-snapshotter to v8.4.0 for VGS v1beta2 support
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Bump external-snapshotter to v8.4.0 and migrate VolumeGroupSnapshot API from v1beta1 to v1beta2 for Kubernetes 1.34+ compatibility
|
||||
@@ -26,7 +26,7 @@ require (
|
||||
github.com/hashicorp/go-plugin v1.6.0
|
||||
github.com/joho/godotenv v1.3.0
|
||||
github.com/kopia/kopia v0.16.0
|
||||
github.com/kubernetes-csi/external-snapshotter/client/v8 v8.2.0
|
||||
github.com/kubernetes-csi/external-snapshotter/client/v8 v8.4.0
|
||||
github.com/onsi/ginkgo/v2 v2.22.0
|
||||
github.com/onsi/gomega v1.36.1
|
||||
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9
|
||||
|
||||
@@ -507,8 +507,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kubernetes-csi/external-snapshotter/client/v8 v8.2.0 h1:Q3jQ1NkFqv5o+F8dMmHd8SfEmlcwNeo1immFApntEwE=
|
||||
github.com/kubernetes-csi/external-snapshotter/client/v8 v8.2.0/go.mod h1:E3vdYxHj2C2q6qo8/Da4g7P+IcwqRZyy3gJBzYybV9Y=
|
||||
github.com/kubernetes-csi/external-snapshotter/client/v8 v8.4.0 h1:bMqrb3UHgHbP+PW9VwiejfDJU1R0PpXVZNMdeH8WYKI=
|
||||
github.com/kubernetes-csi/external-snapshotter/client/v8 v8.4.0/go.mod h1:E3vdYxHj2C2q6qo8/Da4g7P+IcwqRZyy3gJBzYybV9Y=
|
||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
|
||||
"k8s.io/client-go/util/retry"
|
||||
|
||||
volumegroupsnapshotv1beta1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta1"
|
||||
volumegroupsnapshotv1beta2 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta2"
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -765,7 +765,7 @@ func (p *pvcBackupItemAction) getVolumeSnapshotReference(
|
||||
}
|
||||
|
||||
// Re-fetch latest VGS to ensure status is populated after VGSC binding
|
||||
latestVGS := &volumegroupsnapshotv1beta1.VolumeGroupSnapshot{}
|
||||
latestVGS := &volumegroupsnapshotv1beta2.VolumeGroupSnapshot{}
|
||||
if err := p.crClient.Get(ctx, crclient.ObjectKeyFromObject(newVGS), latestVGS); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to re-fetch VolumeGroupSnapshot %s after VGSC binding wait", newVGS.Name)
|
||||
}
|
||||
@@ -913,7 +913,7 @@ func (p *pvcBackupItemAction) determineVGSClass(
|
||||
}
|
||||
|
||||
// 3. Fallback to label-based default
|
||||
vgsClassList := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotClassList{}
|
||||
vgsClassList := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotClassList{}
|
||||
if err := p.crClient.List(ctx, vgsClassList); err != nil {
|
||||
return "", errors.Wrap(err, "failed to list VolumeGroupSnapshotClasses")
|
||||
}
|
||||
@@ -942,22 +942,22 @@ func (p *pvcBackupItemAction) createVolumeGroupSnapshot(
|
||||
backup *velerov1api.Backup,
|
||||
pvc corev1api.PersistentVolumeClaim,
|
||||
vgsLabelKey, vgsLabelValue, vgsClassName string,
|
||||
) (*volumegroupsnapshotv1beta1.VolumeGroupSnapshot, error) {
|
||||
) (*volumegroupsnapshotv1beta2.VolumeGroupSnapshot, error) {
|
||||
vgsLabels := map[string]string{
|
||||
velerov1api.BackupNameLabel: label.GetValidName(backup.Name),
|
||||
velerov1api.BackupUIDLabel: string(backup.UID),
|
||||
vgsLabelKey: vgsLabelValue,
|
||||
}
|
||||
|
||||
vgs := &volumegroupsnapshotv1beta1.VolumeGroupSnapshot{
|
||||
vgs := &volumegroupsnapshotv1beta2.VolumeGroupSnapshot{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
GenerateName: fmt.Sprintf("velero-%s-", vgsLabelValue),
|
||||
Namespace: pvc.Namespace,
|
||||
Labels: vgsLabels,
|
||||
},
|
||||
Spec: volumegroupsnapshotv1beta1.VolumeGroupSnapshotSpec{
|
||||
Spec: volumegroupsnapshotv1beta2.VolumeGroupSnapshotSpec{
|
||||
VolumeGroupSnapshotClassName: &vgsClassName,
|
||||
Source: volumegroupsnapshotv1beta1.VolumeGroupSnapshotSource{
|
||||
Source: volumegroupsnapshotv1beta2.VolumeGroupSnapshotSource{
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
vgsLabelKey: vgsLabelValue,
|
||||
@@ -985,7 +985,7 @@ func (p *pvcBackupItemAction) createVolumeGroupSnapshot(
|
||||
func (p *pvcBackupItemAction) waitForVGSAssociatedVS(
|
||||
ctx context.Context,
|
||||
groupedPVCs []corev1api.PersistentVolumeClaim,
|
||||
vgs *volumegroupsnapshotv1beta1.VolumeGroupSnapshot,
|
||||
vgs *volumegroupsnapshotv1beta2.VolumeGroupSnapshot,
|
||||
timeout time.Duration,
|
||||
) (map[string]*snapshotv1api.VolumeSnapshot, error) {
|
||||
expected := len(groupedPVCs)
|
||||
@@ -1028,10 +1028,10 @@ func (p *pvcBackupItemAction) waitForVGSAssociatedVS(
|
||||
return vsMap, nil
|
||||
}
|
||||
|
||||
func hasOwnerReference(obj metav1.Object, vgs *volumegroupsnapshotv1beta1.VolumeGroupSnapshot) bool {
|
||||
func hasOwnerReference(obj metav1.Object, vgs *volumegroupsnapshotv1beta2.VolumeGroupSnapshot) bool {
|
||||
for _, ref := range obj.GetOwnerReferences() {
|
||||
if ref.Kind == kuberesource.VGSKind &&
|
||||
ref.APIVersion == volumegroupsnapshotv1beta1.GroupName+"/"+volumegroupsnapshotv1beta1.SchemeGroupVersion.Version &&
|
||||
ref.APIVersion == volumegroupsnapshotv1beta2.GroupName+"/"+volumegroupsnapshotv1beta2.SchemeGroupVersion.Version &&
|
||||
ref.UID == vgs.UID {
|
||||
return true
|
||||
}
|
||||
@@ -1042,7 +1042,7 @@ func hasOwnerReference(obj metav1.Object, vgs *volumegroupsnapshotv1beta1.Volume
|
||||
func (p *pvcBackupItemAction) updateVGSCreatedVS(
|
||||
ctx context.Context,
|
||||
vsMap map[string]*snapshotv1api.VolumeSnapshot,
|
||||
vgs *volumegroupsnapshotv1beta1.VolumeGroupSnapshot,
|
||||
vgs *volumegroupsnapshotv1beta2.VolumeGroupSnapshot,
|
||||
backup *velerov1api.Backup,
|
||||
) error {
|
||||
for pvcName, vs := range vsMap {
|
||||
@@ -1085,7 +1085,7 @@ func (p *pvcBackupItemAction) updateVGSCreatedVS(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *pvcBackupItemAction) patchVGSCDeletionPolicy(ctx context.Context, vgs *volumegroupsnapshotv1beta1.VolumeGroupSnapshot) error {
|
||||
func (p *pvcBackupItemAction) patchVGSCDeletionPolicy(ctx context.Context, vgs *volumegroupsnapshotv1beta2.VolumeGroupSnapshot) error {
|
||||
if vgs == nil || vgs.Status == nil || vgs.Status.BoundVolumeGroupSnapshotContentName == nil {
|
||||
return errors.New("VolumeGroupSnapshotContent name not found in VGS status")
|
||||
}
|
||||
@@ -1093,7 +1093,7 @@ func (p *pvcBackupItemAction) patchVGSCDeletionPolicy(ctx context.Context, vgs *
|
||||
vgscName := vgs.Status.BoundVolumeGroupSnapshotContentName
|
||||
|
||||
return retry.RetryOnConflict(retry.DefaultBackoff, func() error {
|
||||
vgsc := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{}
|
||||
vgsc := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{}
|
||||
if err := p.crClient.Get(ctx, crclient.ObjectKey{Name: *vgscName}, vgsc); err != nil {
|
||||
return errors.Wrapf(err, "failed to get VolumeGroupSnapshotContent %s for VolumeGroupSnapshot %s/%s", *vgscName, vgs.Namespace, vgs.Name)
|
||||
}
|
||||
@@ -1112,9 +1112,9 @@ func (p *pvcBackupItemAction) patchVGSCDeletionPolicy(ctx context.Context, vgs *
|
||||
})
|
||||
}
|
||||
|
||||
func (p *pvcBackupItemAction) deleteVGSAndVGSC(ctx context.Context, vgs *volumegroupsnapshotv1beta1.VolumeGroupSnapshot) error {
|
||||
func (p *pvcBackupItemAction) deleteVGSAndVGSC(ctx context.Context, vgs *volumegroupsnapshotv1beta2.VolumeGroupSnapshot) error {
|
||||
if vgs.Status != nil && vgs.Status.BoundVolumeGroupSnapshotContentName != nil {
|
||||
vgsc := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{
|
||||
vgsc := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: *vgs.Status.BoundVolumeGroupSnapshotContentName,
|
||||
},
|
||||
@@ -1139,11 +1139,11 @@ func (p *pvcBackupItemAction) deleteVGSAndVGSC(ctx context.Context, vgs *volumeg
|
||||
|
||||
func (p *pvcBackupItemAction) waitForVGSCBinding(
|
||||
ctx context.Context,
|
||||
vgs *volumegroupsnapshotv1beta1.VolumeGroupSnapshot,
|
||||
vgs *volumegroupsnapshotv1beta2.VolumeGroupSnapshot,
|
||||
timeout time.Duration,
|
||||
) error {
|
||||
return wait.PollUntilContextTimeout(ctx, time.Second, timeout, true, func(ctx context.Context) (bool, error) {
|
||||
vgsRef := &volumegroupsnapshotv1beta1.VolumeGroupSnapshot{}
|
||||
vgsRef := &volumegroupsnapshotv1beta2.VolumeGroupSnapshot{}
|
||||
if err := p.crClient.Get(ctx, crclient.ObjectKeyFromObject(vgs), vgsRef); err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -1156,8 +1156,8 @@ func (p *pvcBackupItemAction) waitForVGSCBinding(
|
||||
})
|
||||
}
|
||||
|
||||
func (p *pvcBackupItemAction) getVGSByLabels(ctx context.Context, namespace string, labels map[string]string) (*volumegroupsnapshotv1beta1.VolumeGroupSnapshot, error) {
|
||||
vgsList := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotList{}
|
||||
func (p *pvcBackupItemAction) getVGSByLabels(ctx context.Context, namespace string, labels map[string]string) (*volumegroupsnapshotv1beta2.VolumeGroupSnapshot, error) {
|
||||
vgsList := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotList{}
|
||||
if err := p.crClient.List(ctx, vgsList,
|
||||
crclient.InNamespace(namespace),
|
||||
crclient.MatchingLabels(labels),
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
|
||||
"github.com/vmware-tanzu/velero/pkg/kuberesource"
|
||||
|
||||
volumegroupsnapshotv1beta1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta1"
|
||||
volumegroupsnapshotv1beta2 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta2"
|
||||
"github.com/stretchr/testify/assert"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
@@ -1121,7 +1121,7 @@ func TestDetermineVGSClass(t *testing.T) {
|
||||
name string
|
||||
backup *velerov1api.Backup
|
||||
pvc *corev1api.PersistentVolumeClaim
|
||||
existingVGSClass []volumegroupsnapshotv1beta1.VolumeGroupSnapshotClass
|
||||
existingVGSClass []volumegroupsnapshotv1beta2.VolumeGroupSnapshotClass
|
||||
expectError bool
|
||||
expectResult string
|
||||
}{
|
||||
@@ -1153,7 +1153,7 @@ func TestDetermineVGSClass(t *testing.T) {
|
||||
name: "Default label-based match",
|
||||
pvc: &corev1api.PersistentVolumeClaim{},
|
||||
backup: &velerov1api.Backup{},
|
||||
existingVGSClass: []volumegroupsnapshotv1beta1.VolumeGroupSnapshotClass{
|
||||
existingVGSClass: []volumegroupsnapshotv1beta2.VolumeGroupSnapshotClass{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "default-class",
|
||||
@@ -1174,7 +1174,7 @@ func TestDetermineVGSClass(t *testing.T) {
|
||||
name: "Multiple matching VGS classes",
|
||||
pvc: &corev1api.PersistentVolumeClaim{},
|
||||
backup: &velerov1api.Backup{},
|
||||
existingVGSClass: []volumegroupsnapshotv1beta1.VolumeGroupSnapshotClass{
|
||||
existingVGSClass: []volumegroupsnapshotv1beta2.VolumeGroupSnapshotClass{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "class1",
|
||||
@@ -1204,7 +1204,7 @@ func TestDetermineVGSClass(t *testing.T) {
|
||||
|
||||
client := velerotest.NewFakeControllerRuntimeClient(t, initObjs...)
|
||||
logger := logrus.New()
|
||||
require.NoError(t, volumegroupsnapshotv1beta1.AddToScheme(client.Scheme()))
|
||||
require.NoError(t, volumegroupsnapshotv1beta2.AddToScheme(client.Scheme()))
|
||||
|
||||
action := &pvcBackupItemAction{crClient: client, log: logger}
|
||||
|
||||
@@ -1263,13 +1263,13 @@ func TestCreateVolumeGroupSnapshot(t *testing.T) {
|
||||
assert.Equal(t, string(testBackup.UID), vgs.Labels[velerov1api.BackupUIDLabel])
|
||||
|
||||
// Check that it exists in fake client
|
||||
retrieved := &volumegroupsnapshotv1beta1.VolumeGroupSnapshot{}
|
||||
retrieved := &volumegroupsnapshotv1beta2.VolumeGroupSnapshot{}
|
||||
err = crClient.Get(t.Context(), crclient.ObjectKey{Name: vgs.Name, Namespace: vgs.Namespace}, retrieved)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestWaitForVGSAssociatedVS(t *testing.T) {
|
||||
vgs := &volumegroupsnapshotv1beta1.VolumeGroupSnapshot{
|
||||
vgs := &volumegroupsnapshotv1beta2.VolumeGroupSnapshot{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-vgs",
|
||||
Namespace: "test-ns",
|
||||
@@ -1282,7 +1282,7 @@ func TestWaitForVGSAssociatedVS(t *testing.T) {
|
||||
if owned {
|
||||
refs = []metav1.OwnerReference{
|
||||
{
|
||||
APIVersion: "groupsnapshot.storage.k8s.io/v1beta1",
|
||||
APIVersion: "groupsnapshot.storage.k8s.io/v1beta2",
|
||||
Kind: "VolumeGroupSnapshot",
|
||||
Name: vgs.Name,
|
||||
UID: vgs.UID,
|
||||
@@ -1429,7 +1429,7 @@ func TestUpdateVGSCreatedVS(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
vgs := &volumegroupsnapshotv1beta1.VolumeGroupSnapshot{
|
||||
vgs := &volumegroupsnapshotv1beta2.VolumeGroupSnapshot{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-vgs",
|
||||
Namespace: "ns",
|
||||
@@ -1442,7 +1442,7 @@ func TestUpdateVGSCreatedVS(t *testing.T) {
|
||||
if withVGSOwner {
|
||||
refs = []metav1.OwnerReference{
|
||||
{
|
||||
APIVersion: "groupsnapshot.storage.k8s.io/v1beta1",
|
||||
APIVersion: "groupsnapshot.storage.k8s.io/v1beta2",
|
||||
Kind: "VolumeGroupSnapshot",
|
||||
Name: vgs.Name,
|
||||
UID: vgs.UID,
|
||||
@@ -1561,18 +1561,18 @@ func TestPatchVGSCDeletionPolicy(t *testing.T) {
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
vgsc := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{
|
||||
vgsc := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "test-vgsc"},
|
||||
Spec: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSpec{
|
||||
Spec: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSpec{
|
||||
DeletionPolicy: tt.initialPolicy,
|
||||
},
|
||||
}
|
||||
vgs := &volumegroupsnapshotv1beta1.VolumeGroupSnapshot{
|
||||
vgs := &volumegroupsnapshotv1beta2.VolumeGroupSnapshot{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-vgs",
|
||||
Namespace: "ns",
|
||||
},
|
||||
Status: &volumegroupsnapshotv1beta1.VolumeGroupSnapshotStatus{
|
||||
Status: &volumegroupsnapshotv1beta2.VolumeGroupSnapshotStatus{
|
||||
BoundVolumeGroupSnapshotContentName: pointer.String("test-vgsc"),
|
||||
},
|
||||
}
|
||||
@@ -1590,7 +1590,7 @@ func TestPatchVGSCDeletionPolicy(t *testing.T) {
|
||||
}
|
||||
require.NoError(t, err)
|
||||
|
||||
updated := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{}
|
||||
updated := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{}
|
||||
err = client.Get(t.Context(), crclient.ObjectKey{Name: "test-vgsc"}, updated)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tt.expectedPolicy, updated.Spec.DeletionPolicy)
|
||||
@@ -1599,20 +1599,20 @@ func TestPatchVGSCDeletionPolicy(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteVGSAndVGSC(t *testing.T) {
|
||||
makeVGS := func(name, namespace string, boundVGSCName *string) *volumegroupsnapshotv1beta1.VolumeGroupSnapshot {
|
||||
return &volumegroupsnapshotv1beta1.VolumeGroupSnapshot{
|
||||
makeVGS := func(name, namespace string, boundVGSCName *string) *volumegroupsnapshotv1beta2.VolumeGroupSnapshot {
|
||||
return &volumegroupsnapshotv1beta2.VolumeGroupSnapshot{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: namespace,
|
||||
},
|
||||
Status: &volumegroupsnapshotv1beta1.VolumeGroupSnapshotStatus{
|
||||
Status: &volumegroupsnapshotv1beta2.VolumeGroupSnapshotStatus{
|
||||
BoundVolumeGroupSnapshotContentName: boundVGSCName,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
makeVGSC := func(name string) *volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent {
|
||||
return &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{
|
||||
makeVGSC := func(name string) *volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent {
|
||||
return &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
@@ -1621,8 +1621,8 @@ func TestDeleteVGSAndVGSC(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
vgs *volumegroupsnapshotv1beta1.VolumeGroupSnapshot
|
||||
existingVGSC *volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent
|
||||
vgs *volumegroupsnapshotv1beta2.VolumeGroupSnapshot
|
||||
existingVGSC *volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent
|
||||
expectVGSCDelete bool
|
||||
expectVGSDelete bool
|
||||
}{
|
||||
@@ -1668,13 +1668,13 @@ func TestDeleteVGSAndVGSC(t *testing.T) {
|
||||
|
||||
// Check VGSC is deleted
|
||||
if tt.expectVGSCDelete {
|
||||
got := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{}
|
||||
got := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{}
|
||||
err = client.Get(t.Context(), crclient.ObjectKey{Name: "test-vgsc"}, got)
|
||||
assert.True(t, apierrors.IsNotFound(err), "expected VGSC to be deleted")
|
||||
}
|
||||
|
||||
// Check VGS is deleted
|
||||
gotVGS := &volumegroupsnapshotv1beta1.VolumeGroupSnapshot{}
|
||||
gotVGS := &volumegroupsnapshotv1beta2.VolumeGroupSnapshot{}
|
||||
err = client.Get(t.Context(), crclient.ObjectKey{Name: "test-vgs", Namespace: "ns"}, gotVGS)
|
||||
assert.True(t, apierrors.IsNotFound(err), "expected VGS to be deleted")
|
||||
})
|
||||
@@ -1769,8 +1769,8 @@ func TestFindExistingVSForBackup(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWaitForVGSCBinding(t *testing.T) {
|
||||
makeVGS := func(name string, withStatus bool) *volumegroupsnapshotv1beta1.VolumeGroupSnapshot {
|
||||
vgs := &volumegroupsnapshotv1beta1.VolumeGroupSnapshot{
|
||||
makeVGS := func(name string, withStatus bool) *volumegroupsnapshotv1beta2.VolumeGroupSnapshot {
|
||||
vgs := &volumegroupsnapshotv1beta2.VolumeGroupSnapshot{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: "ns",
|
||||
@@ -1778,7 +1778,7 @@ func TestWaitForVGSCBinding(t *testing.T) {
|
||||
}
|
||||
if withStatus {
|
||||
contentName := "vgsc-123"
|
||||
vgs.Status = &volumegroupsnapshotv1beta1.VolumeGroupSnapshotStatus{
|
||||
vgs.Status = &volumegroupsnapshotv1beta2.VolumeGroupSnapshotStatus{
|
||||
BoundVolumeGroupSnapshotContentName: &contentName,
|
||||
}
|
||||
}
|
||||
@@ -1787,7 +1787,7 @@ func TestWaitForVGSCBinding(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
vgs *volumegroupsnapshotv1beta1.VolumeGroupSnapshot
|
||||
vgs *volumegroupsnapshotv1beta2.VolumeGroupSnapshot
|
||||
expectErr bool
|
||||
}{
|
||||
{
|
||||
@@ -1830,8 +1830,8 @@ func TestGetVGSByLabels(t *testing.T) {
|
||||
labelVal := "backup-123"
|
||||
testLabels := map[string]string{labelKey: labelVal}
|
||||
|
||||
makeVGS := func(name string, labels map[string]string) *volumegroupsnapshotv1beta1.VolumeGroupSnapshot {
|
||||
return &volumegroupsnapshotv1beta1.VolumeGroupSnapshot{
|
||||
makeVGS := func(name string, labels map[string]string) *volumegroupsnapshotv1beta2.VolumeGroupSnapshot {
|
||||
return &volumegroupsnapshotv1beta2.VolumeGroupSnapshot{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: "test-ns",
|
||||
@@ -1916,7 +1916,7 @@ func (f *failingClient) List(ctx context.Context, list crclient.ObjectList, opts
|
||||
}
|
||||
|
||||
func TestHasOwnerReference(t *testing.T) {
|
||||
vgs := &volumegroupsnapshotv1beta1.VolumeGroupSnapshot{
|
||||
vgs := &volumegroupsnapshotv1beta2.VolumeGroupSnapshot{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-vgs",
|
||||
Namespace: "test-ns",
|
||||
@@ -1933,7 +1933,7 @@ func TestHasOwnerReference(t *testing.T) {
|
||||
name: "match kind, apiversion, uid",
|
||||
ownerRef: metav1.OwnerReference{
|
||||
Kind: kuberesource.VGSKind,
|
||||
APIVersion: volumegroupsnapshotv1beta1.GroupName + "/" + volumegroupsnapshotv1beta1.SchemeGroupVersion.Version,
|
||||
APIVersion: volumegroupsnapshotv1beta2.GroupName + "/" + volumegroupsnapshotv1beta2.SchemeGroupVersion.Version,
|
||||
UID: vgs.UID,
|
||||
},
|
||||
expect: true,
|
||||
@@ -1942,7 +1942,7 @@ func TestHasOwnerReference(t *testing.T) {
|
||||
name: "mismatch kind",
|
||||
ownerRef: metav1.OwnerReference{
|
||||
Kind: "other-kind",
|
||||
APIVersion: volumegroupsnapshotv1beta1.GroupName + "/" + volumegroupsnapshotv1beta1.SchemeGroupVersion.Version,
|
||||
APIVersion: volumegroupsnapshotv1beta2.GroupName + "/" + volumegroupsnapshotv1beta2.SchemeGroupVersion.Version,
|
||||
UID: vgs.UID,
|
||||
},
|
||||
expect: false,
|
||||
@@ -1960,7 +1960,7 @@ func TestHasOwnerReference(t *testing.T) {
|
||||
name: "mismatch uid",
|
||||
ownerRef: metav1.OwnerReference{
|
||||
Kind: kuberesource.VGSKind,
|
||||
APIVersion: volumegroupsnapshotv1beta1.GroupName + "/" + volumegroupsnapshotv1beta1.SchemeGroupVersion.Version,
|
||||
APIVersion: volumegroupsnapshotv1beta2.GroupName + "/" + volumegroupsnapshotv1beta2.SchemeGroupVersion.Version,
|
||||
UID: "wrong-uid",
|
||||
},
|
||||
expect: false,
|
||||
|
||||
@@ -19,7 +19,7 @@ package client
|
||||
import (
|
||||
"os"
|
||||
|
||||
volumegroupsnapshotv1beta1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta1"
|
||||
volumegroupsnapshotv1beta2 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta2"
|
||||
|
||||
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
||||
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||
@@ -168,7 +168,7 @@ func (f *factory) KubebuilderClient() (kbclient.Client, error) {
|
||||
if err := snapshotv1api.AddToScheme(scheme); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := volumegroupsnapshotv1beta1.AddToScheme(scheme); err != nil {
|
||||
if err := volumegroupsnapshotv1beta2.AddToScheme(scheme); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
kubebuilderClient, err := kbclient.New(clientConfig, kbclient.Options{
|
||||
@@ -207,7 +207,7 @@ func (f *factory) KubebuilderWatchClient() (kbclient.WithWatch, error) {
|
||||
if err := snapshotv1api.AddToScheme(scheme); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := volumegroupsnapshotv1beta1.AddToScheme(scheme); err != nil {
|
||||
if err := volumegroupsnapshotv1beta2.AddToScheme(scheme); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
kubebuilderWatchClient, err := kbclient.NewWithWatch(clientConfig, kbclient.Options{
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
"time"
|
||||
|
||||
logrusr "github.com/bombsimon/logrusr/v3"
|
||||
volumegroupsnapshotv1beta1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta1"
|
||||
volumegroupsnapshotv1beta2 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta2"
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
@@ -247,7 +247,7 @@ func newServer(f client.Factory, config *config.Config, logger *logrus.Logger) (
|
||||
cancelFunc()
|
||||
return nil, err
|
||||
}
|
||||
if err := volumegroupsnapshotv1beta1.AddToScheme(scheme); err != nil {
|
||||
if err := volumegroupsnapshotv1beta2.AddToScheme(scheme); err != nil {
|
||||
cancelFunc()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
volumegroupsnapshotv1beta1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta1"
|
||||
volumegroupsnapshotv1beta2 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta2"
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -457,7 +457,7 @@ func (ctx *finalizerContext) patchDynamicPVWithVolumeInfo() (errs results.Result
|
||||
func (ctx *finalizerContext) cleanupStubVGSC() (warnings results.Result) {
|
||||
ctx.logger.Info("cleaning up stub VolumeGroupSnapshotContents")
|
||||
|
||||
vgscList := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentList{}
|
||||
vgscList := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentList{}
|
||||
err := ctx.crClient.List(
|
||||
context.Background(),
|
||||
vgscList,
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
volumegroupsnapshotv1beta1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta1"
|
||||
volumegroupsnapshotv1beta2 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta2"
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -750,7 +750,7 @@ func TestCleanupStubVGSC(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
restore *velerov1api.Restore
|
||||
existingVGSCs []*volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent
|
||||
existingVGSCs []*volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent
|
||||
existingVSCs []*snapshotv1api.VolumeSnapshotContent
|
||||
expectedRemaining int
|
||||
expectedWarnings bool
|
||||
@@ -765,7 +765,7 @@ func TestCleanupStubVGSC(t *testing.T) {
|
||||
{
|
||||
name: "single stub VGSC deleted after VSCs are ready",
|
||||
restore: builder.ForRestore(velerov1api.DefaultNamespace, "restore-1").Result(),
|
||||
existingVGSCs: []*volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{
|
||||
existingVGSCs: []*volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "vgsc-stub-1",
|
||||
@@ -773,10 +773,10 @@ func TestCleanupStubVGSC(t *testing.T) {
|
||||
velerov1api.RestoreNameLabel: "restore-1",
|
||||
},
|
||||
},
|
||||
Spec: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSpec{
|
||||
Spec: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSpec{
|
||||
Driver: "rbd.csi.ceph.com",
|
||||
Source: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSource{
|
||||
GroupSnapshotHandles: &volumegroupsnapshotv1beta1.GroupSnapshotHandles{
|
||||
Source: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSource{
|
||||
GroupSnapshotHandles: &volumegroupsnapshotv1beta2.GroupSnapshotHandles{
|
||||
VolumeGroupSnapshotHandle: "vgs-handle-1",
|
||||
VolumeSnapshotHandles: []string{snapshotHandle1},
|
||||
},
|
||||
@@ -814,7 +814,7 @@ func TestCleanupStubVGSC(t *testing.T) {
|
||||
{
|
||||
name: "multiple stub VGSCs deleted",
|
||||
restore: builder.ForRestore(velerov1api.DefaultNamespace, "restore-1").Result(),
|
||||
existingVGSCs: []*volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{
|
||||
existingVGSCs: []*volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "vgsc-stub-1",
|
||||
@@ -822,10 +822,10 @@ func TestCleanupStubVGSC(t *testing.T) {
|
||||
velerov1api.RestoreNameLabel: "restore-1",
|
||||
},
|
||||
},
|
||||
Spec: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSpec{
|
||||
Spec: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSpec{
|
||||
Driver: "rbd.csi.ceph.com",
|
||||
Source: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSource{
|
||||
GroupSnapshotHandles: &volumegroupsnapshotv1beta1.GroupSnapshotHandles{
|
||||
Source: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSource{
|
||||
GroupSnapshotHandles: &volumegroupsnapshotv1beta2.GroupSnapshotHandles{
|
||||
VolumeGroupSnapshotHandle: "vgs-handle-1",
|
||||
VolumeSnapshotHandles: []string{snapshotHandle1},
|
||||
},
|
||||
@@ -839,10 +839,10 @@ func TestCleanupStubVGSC(t *testing.T) {
|
||||
velerov1api.RestoreNameLabel: "restore-1",
|
||||
},
|
||||
},
|
||||
Spec: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSpec{
|
||||
Spec: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSpec{
|
||||
Driver: "rbd.csi.ceph.com",
|
||||
Source: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSource{
|
||||
GroupSnapshotHandles: &volumegroupsnapshotv1beta1.GroupSnapshotHandles{
|
||||
Source: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSource{
|
||||
GroupSnapshotHandles: &volumegroupsnapshotv1beta2.GroupSnapshotHandles{
|
||||
VolumeGroupSnapshotHandle: "vgs-handle-2",
|
||||
VolumeSnapshotHandles: []string{snapshotHandle2},
|
||||
},
|
||||
@@ -902,7 +902,7 @@ func TestCleanupStubVGSC(t *testing.T) {
|
||||
{
|
||||
name: "VGSCs from different restore are not deleted",
|
||||
restore: builder.ForRestore(velerov1api.DefaultNamespace, "restore-1").Result(),
|
||||
existingVGSCs: []*volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{
|
||||
existingVGSCs: []*volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "vgsc-stub-mine",
|
||||
@@ -910,9 +910,9 @@ func TestCleanupStubVGSC(t *testing.T) {
|
||||
velerov1api.RestoreNameLabel: "restore-1",
|
||||
},
|
||||
},
|
||||
Spec: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSpec{
|
||||
Spec: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSpec{
|
||||
Driver: "rbd.csi.ceph.com",
|
||||
Source: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSource{},
|
||||
Source: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSource{},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -922,9 +922,9 @@ func TestCleanupStubVGSC(t *testing.T) {
|
||||
velerov1api.RestoreNameLabel: "restore-2",
|
||||
},
|
||||
},
|
||||
Spec: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSpec{
|
||||
Spec: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSpec{
|
||||
Driver: "rbd.csi.ceph.com",
|
||||
Source: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSource{},
|
||||
Source: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSource{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -934,7 +934,7 @@ func TestCleanupStubVGSC(t *testing.T) {
|
||||
{
|
||||
name: "VGSC deleted even when no snapshot handles in spec",
|
||||
restore: builder.ForRestore(velerov1api.DefaultNamespace, "restore-1").Result(),
|
||||
existingVGSCs: []*volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{
|
||||
existingVGSCs: []*volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "vgsc-stub-empty",
|
||||
@@ -942,9 +942,9 @@ func TestCleanupStubVGSC(t *testing.T) {
|
||||
velerov1api.RestoreNameLabel: "restore-1",
|
||||
},
|
||||
},
|
||||
Spec: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSpec{
|
||||
Spec: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSpec{
|
||||
Driver: "rbd.csi.ceph.com",
|
||||
Source: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSource{},
|
||||
Source: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSource{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -980,7 +980,7 @@ func TestCleanupStubVGSC(t *testing.T) {
|
||||
assert.True(t, warnings.IsEmpty(), "expected no warnings")
|
||||
}
|
||||
|
||||
remainingList := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentList{}
|
||||
remainingList := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentList{}
|
||||
require.NoError(t, fakeClient.List(t.Context(), remainingList))
|
||||
assert.Len(t, remainingList.Items, tc.expectedRemaining)
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
volumegroupsnapshotv1beta1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta1"
|
||||
volumegroupsnapshotv1beta2 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta2"
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -103,7 +103,7 @@ func (p *volumeSnapshotRestoreItemAction) ensureStubVGSCExists(
|
||||
vgscName := util.GenerateSha256FromRestoreUIDAndVsName(string(restore.UID), vgsh)
|
||||
|
||||
// Check if VGSC already exists
|
||||
existingVGSC := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{}
|
||||
existingVGSC := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{}
|
||||
err := p.crClient.Get(ctx, crclient.ObjectKey{Name: vgscName}, existingVGSC)
|
||||
if err == nil {
|
||||
// VGSC already exists, add this snapshot handle if not already present
|
||||
@@ -119,7 +119,7 @@ func (p *volumeSnapshotRestoreItemAction) ensureStubVGSCExists(
|
||||
|
||||
// Look up VolumeGroupSnapshotClass to get secret annotations
|
||||
vgscAnnotations := map[string]string{}
|
||||
vgscList := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotClassList{}
|
||||
vgscList := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotClassList{}
|
||||
if err := p.crClient.List(ctx, vgscList); err == nil {
|
||||
for _, vgsClass := range vgscList.Items {
|
||||
if vgsClass.Driver == driver {
|
||||
@@ -135,7 +135,7 @@ func (p *volumeSnapshotRestoreItemAction) ensureStubVGSCExists(
|
||||
}
|
||||
}
|
||||
|
||||
vgsc := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{
|
||||
vgsc := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: vgscName,
|
||||
Labels: map[string]string{
|
||||
@@ -143,11 +143,11 @@ func (p *volumeSnapshotRestoreItemAction) ensureStubVGSCExists(
|
||||
},
|
||||
Annotations: vgscAnnotations,
|
||||
},
|
||||
Spec: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSpec{
|
||||
Spec: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSpec{
|
||||
DeletionPolicy: snapshotv1api.VolumeSnapshotContentRetain,
|
||||
Driver: driver,
|
||||
Source: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSource{
|
||||
GroupSnapshotHandles: &volumegroupsnapshotv1beta1.GroupSnapshotHandles{
|
||||
Source: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSource{
|
||||
GroupSnapshotHandles: &volumegroupsnapshotv1beta2.GroupSnapshotHandles{
|
||||
VolumeGroupSnapshotHandle: vgsh,
|
||||
VolumeSnapshotHandles: []string{snapshotHandle},
|
||||
},
|
||||
@@ -164,7 +164,7 @@ func (p *volumeSnapshotRestoreItemAction) ensureStubVGSCExists(
|
||||
// Another VS restore created the VGSC between our Get and Create.
|
||||
// Re-fetch and add our snapshot handle.
|
||||
p.log.Infof("Stub VGSC %s was created by another VS restore, adding our handle", vgscName)
|
||||
raceVGSC := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{}
|
||||
raceVGSC := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{}
|
||||
if getErr := p.crClient.Get(ctx, crclient.ObjectKey{Name: vgscName}, raceVGSC); getErr != nil {
|
||||
return errors.Wrapf(getErr, "failed to get VGSC %s after race", vgscName)
|
||||
}
|
||||
@@ -174,7 +174,7 @@ func (p *volumeSnapshotRestoreItemAction) ensureStubVGSCExists(
|
||||
}
|
||||
|
||||
// Re-fetch to get server-assigned metadata (resourceVersion) needed for patching
|
||||
createdVGSC := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{}
|
||||
createdVGSC := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{}
|
||||
if err := p.crClient.Get(ctx, crclient.ObjectKey{Name: vgscName}, createdVGSC); err != nil {
|
||||
p.log.Warnf("Failed to fetch stub VGSC %s for status patch: %v", vgscName, err)
|
||||
return nil
|
||||
@@ -183,7 +183,7 @@ func (p *volumeSnapshotRestoreItemAction) ensureStubVGSCExists(
|
||||
// Set volumeGroupSnapshotHandle in status using Patch to avoid conflicts with the CSI controller.
|
||||
patchBase := createdVGSC.DeepCopy()
|
||||
if createdVGSC.Status == nil {
|
||||
createdVGSC.Status = &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentStatus{}
|
||||
createdVGSC.Status = &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentStatus{}
|
||||
}
|
||||
createdVGSC.Status.VolumeGroupSnapshotHandle = &vgsh
|
||||
if err := p.crClient.Status().Patch(ctx, createdVGSC, crclient.MergeFrom(patchBase)); err != nil {
|
||||
@@ -198,7 +198,7 @@ func (p *volumeSnapshotRestoreItemAction) ensureStubVGSCExists(
|
||||
// This is needed when multiple VolumeSnapshots from the same VolumeGroupSnapshot are restored.
|
||||
func (p *volumeSnapshotRestoreItemAction) addSnapshotHandleToVGSC(
|
||||
ctx context.Context,
|
||||
vgsc *volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent,
|
||||
vgsc *volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent,
|
||||
snapshotHandle string,
|
||||
) error {
|
||||
// Check if handle is already in the list
|
||||
@@ -214,7 +214,7 @@ func (p *volumeSnapshotRestoreItemAction) addSnapshotHandleToVGSC(
|
||||
// Add the snapshot handle to the list
|
||||
patchBase := vgsc.DeepCopy()
|
||||
if vgsc.Spec.Source.GroupSnapshotHandles == nil {
|
||||
vgsc.Spec.Source.GroupSnapshotHandles = &volumegroupsnapshotv1beta1.GroupSnapshotHandles{}
|
||||
vgsc.Spec.Source.GroupSnapshotHandles = &volumegroupsnapshotv1beta2.GroupSnapshotHandles{}
|
||||
}
|
||||
vgsc.Spec.Source.GroupSnapshotHandles.VolumeSnapshotHandles = append(
|
||||
vgsc.Spec.Source.GroupSnapshotHandles.VolumeSnapshotHandles,
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
volumegroupsnapshotv1beta1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta1"
|
||||
volumegroupsnapshotv1beta2 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta2"
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -232,7 +232,7 @@ func TestEnsureStubVGSCExists(t *testing.T) {
|
||||
name string
|
||||
vs *snapshotv1api.VolumeSnapshot
|
||||
restore *velerov1api.Restore
|
||||
existingVGSC *volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent
|
||||
existingVGSC *volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent
|
||||
expectVGSC bool
|
||||
expectErr bool
|
||||
expectedHandle string
|
||||
@@ -317,15 +317,15 @@ func TestEnsureStubVGSCExists(t *testing.T) {
|
||||
},
|
||||
},
|
||||
restore: builder.ForRestore("velero", "restore").ObjectMeta(builder.WithUID("restore-uid")).Result(),
|
||||
existingVGSC: &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{
|
||||
existingVGSC: &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: util.GenerateSha256FromRestoreUIDAndVsName("restore-uid", testVGSHandle),
|
||||
},
|
||||
Spec: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSpec{
|
||||
Spec: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSpec{
|
||||
Driver: testDriver,
|
||||
DeletionPolicy: snapshotv1api.VolumeSnapshotContentRetain,
|
||||
Source: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSource{
|
||||
GroupSnapshotHandles: &volumegroupsnapshotv1beta1.GroupSnapshotHandles{
|
||||
Source: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSource{
|
||||
GroupSnapshotHandles: &volumegroupsnapshotv1beta2.GroupSnapshotHandles{
|
||||
VolumeGroupSnapshotHandle: testVGSHandle,
|
||||
VolumeSnapshotHandles: []string{testSnapshotHandle},
|
||||
},
|
||||
@@ -362,7 +362,7 @@ func TestEnsureStubVGSCExists(t *testing.T) {
|
||||
|
||||
// Check if VGSC was created/updated
|
||||
vgscName := util.GenerateSha256FromRestoreUIDAndVsName(string(tc.restore.UID), tc.vs.Annotations[velerov1api.VolumeGroupSnapshotHandleAnnotation])
|
||||
vgsc := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{}
|
||||
vgsc := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{}
|
||||
getErr := crClient.Get(context.Background(), crclient.ObjectKey{Name: vgscName}, vgsc)
|
||||
|
||||
if tc.expectVGSC {
|
||||
@@ -420,23 +420,23 @@ func TestAddSnapshotHandleToVGSC(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
crClient := velerotest.NewFakeControllerRuntimeClient(t)
|
||||
|
||||
var source volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSource
|
||||
var source volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSource
|
||||
if tc.nilGroupSnapshotHandles {
|
||||
source = volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSource{}
|
||||
source = volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSource{}
|
||||
} else {
|
||||
source = volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSource{
|
||||
GroupSnapshotHandles: &volumegroupsnapshotv1beta1.GroupSnapshotHandles{
|
||||
source = volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSource{
|
||||
GroupSnapshotHandles: &volumegroupsnapshotv1beta2.GroupSnapshotHandles{
|
||||
VolumeGroupSnapshotHandle: testVGSHandle,
|
||||
VolumeSnapshotHandles: tc.existingHandles,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
existingVGSC := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{
|
||||
existingVGSC := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "test-vgsc",
|
||||
},
|
||||
Spec: volumegroupsnapshotv1beta1.VolumeGroupSnapshotContentSpec{
|
||||
Spec: volumegroupsnapshotv1beta2.VolumeGroupSnapshotContentSpec{
|
||||
Driver: testDriver,
|
||||
DeletionPolicy: snapshotv1api.VolumeSnapshotContentRetain,
|
||||
Source: source,
|
||||
@@ -445,7 +445,7 @@ func TestAddSnapshotHandleToVGSC(t *testing.T) {
|
||||
require.NoError(t, crClient.Create(context.Background(), existingVGSC))
|
||||
|
||||
// Re-fetch to get the created object with proper metadata
|
||||
fetchedVGSC := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{}
|
||||
fetchedVGSC := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{}
|
||||
require.NoError(t, crClient.Get(context.Background(), crclient.ObjectKey{Name: "test-vgsc"}, fetchedVGSC))
|
||||
|
||||
p := &volumeSnapshotRestoreItemAction{
|
||||
@@ -457,7 +457,7 @@ func TestAddSnapshotHandleToVGSC(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Verify the VGSC has expected handles
|
||||
updatedVGSC := &volumegroupsnapshotv1beta1.VolumeGroupSnapshotContent{}
|
||||
updatedVGSC := &volumegroupsnapshotv1beta2.VolumeGroupSnapshotContent{}
|
||||
require.NoError(t, crClient.Get(context.Background(), crclient.ObjectKey{Name: "test-vgsc"}, updatedVGSC))
|
||||
require.ElementsMatch(t, tc.expectedHandles, updatedVGSC.Spec.Source.GroupSnapshotHandles.VolumeSnapshotHandles)
|
||||
})
|
||||
|
||||
@@ -19,7 +19,7 @@ package test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
volumegroupsnapshotv1beta1 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta1"
|
||||
volumegroupsnapshotv1beta2 "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta2"
|
||||
|
||||
snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -45,7 +45,7 @@ func NewFakeControllerRuntimeClientBuilder(t *testing.T) *k8sfake.ClientBuilder
|
||||
require.NoError(t, appsv1api.AddToScheme(scheme))
|
||||
require.NoError(t, snapshotv1api.AddToScheme(scheme))
|
||||
require.NoError(t, storagev1api.AddToScheme(scheme))
|
||||
require.NoError(t, volumegroupsnapshotv1beta1.AddToScheme(scheme))
|
||||
require.NoError(t, volumegroupsnapshotv1beta2.AddToScheme(scheme))
|
||||
|
||||
return k8sfake.NewClientBuilder().WithScheme(scheme)
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func NewFakeControllerRuntimeClient(t *testing.T, initObjs ...runtime.Object) cl
|
||||
require.NoError(t, snapshotv1api.AddToScheme(scheme))
|
||||
require.NoError(t, storagev1api.AddToScheme(scheme))
|
||||
require.NoError(t, batchv1api.AddToScheme(scheme))
|
||||
require.NoError(t, volumegroupsnapshotv1beta1.AddToScheme(scheme))
|
||||
require.NoError(t, volumegroupsnapshotv1beta2.AddToScheme(scheme))
|
||||
|
||||
return k8sfake.NewClientBuilder().WithScheme(scheme).WithRuntimeObjects(initObjs...).Build()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user