e2e: update snapshot to v1beta1

updating the snapshot client and
test to use v1beta1 client and API.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna
2024-12-12 13:31:29 +01:00
committed by mergify[bot]
parent 5bfff89e04
commit a17fef07e6
16 changed files with 202 additions and 192 deletions

View File

@ -18,9 +18,10 @@ package e2e
import (
"context"
"crypto/sha256"
"fmt"
groupsnapapi "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1alpha1"
groupsnapapi "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/test/e2e/framework"
)
@ -78,16 +79,32 @@ func (c *cephFSVolumeGroupSnapshot) ValidateResourcesForCreate(vgs *groupsnapapi
return fmt.Errorf("failed getting cephFS metadata pool name: %w", err)
}
sourcePVCCount := len(vgs.Status.PVCVolumeSnapshotRefList)
vgsc, err := c.groupclient.VolumeGroupSnapshotContents().Get(
ctx,
*vgs.Status.BoundVolumeGroupSnapshotContentName,
metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get VolumeGroupSnapshotContent: %w", err)
}
sourcePVCCount := len(vgsc.Status.VolumeSnapshotHandlePairList)
// we are creating clones for each source PVC
clonePVCCount := len(vgs.Status.PVCVolumeSnapshotRefList)
clonePVCCount := len(vgsc.Status.VolumeSnapshotHandlePairList)
totalPVCCount := sourcePVCCount + clonePVCCount
validateSubvolumeCount(c.framework, totalPVCCount, fileSystemName, subvolumegroup)
// we are creating 1 snapshot for each source PVC, validate the snapshot count
for _, pvcSnap := range vgs.Status.PVCVolumeSnapshotRefList {
for _, snapshot := range vgsc.Status.VolumeSnapshotHandlePairList {
volumeHandle := snapshot.VolumeHandle
volumeSnapshotName := fmt.Sprintf("snapshot-%x", sha256.Sum256([]byte(
string(vgsc.UID)+volumeHandle)))
volumeSnapshot, err := c.snapClient.VolumeSnapshots(vgs.Namespace).Get(ctx, volumeSnapshotName, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get VolumeSnapshot: %w", err)
}
pvcName := *volumeSnapshot.Spec.Source.PersistentVolumeClaimName
pvc, err := c.framework.ClientSet.CoreV1().PersistentVolumeClaims(vgs.Namespace).Get(ctx,
pvcSnap.PersistentVolumeClaimRef.Name,
pvcName,
metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get PVC: %w", err)
@ -165,8 +182,16 @@ func (rvgs *rbdVolumeGroupSnapshot) GetVolumeGroupSnapshotClass() (*groupsnapapi
}
func (rvgs *rbdVolumeGroupSnapshot) ValidateResourcesForCreate(vgs *groupsnapapi.VolumeGroupSnapshot) error {
sourcePVCCount := len(vgs.Status.PVCVolumeSnapshotRefList)
clonePVCCount := len(vgs.Status.PVCVolumeSnapshotRefList)
vgsc, err := rvgs.groupclient.VolumeGroupSnapshotContents().Get(
context.TODO(),
*vgs.Status.BoundVolumeGroupSnapshotContentName,
metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get VolumeGroupSnapshotContent: %w", err)
}
sourcePVCCount := len(vgsc.Status.VolumeSnapshotHandlePairList)
clonePVCCount := len(vgsc.Status.VolumeSnapshotHandlePairList)
totalPVCCount := sourcePVCCount + clonePVCCount
validateOmapCount(rvgs.framework, totalPVCCount, rbdType, defaultRBDPool, volumesType)

View File

@ -18,12 +18,14 @@ package e2e
import (
"context"
"crypto/sha256"
"fmt"
"time"
groupsnapapi "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1alpha1"
groupsnapapi "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumegroupsnapshot/v1beta1"
snapapi "github.com/kubernetes-csi/external-snapshotter/client/v8/apis/volumesnapshot/v1"
groupsnapclient "github.com/kubernetes-csi/external-snapshotter/client/v8/clientset/versioned/typed/volumegroupsnapshot/v1alpha1"
groupsnapclient "github.com/kubernetes-csi/external-snapshotter/client/v8/clientset/versioned/typed/volumegroupsnapshot/v1beta1"
snapclient "github.com/kubernetes-csi/external-snapshotter/client/v8/clientset/versioned/typed/volumesnapshot/v1"
v1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
@ -75,7 +77,8 @@ type VolumeGroupSnapshotter interface {
type volumeGroupSnapshotterBase struct {
timeout int
framework *framework.Framework
groupclient *groupsnapclient.GroupsnapshotV1alpha1Client
groupclient *groupsnapclient.GroupsnapshotV1beta1Client
snapClient *snapclient.SnapshotV1Client
storageClassName string
blockPVC bool
totalPVCCount int
@ -96,9 +99,15 @@ func newVolumeGroupSnapshotBase(f *framework.Framework, namespace,
return nil, fmt.Errorf("error creating group snapshot client: %w", err)
}
s, err := snapclient.NewForConfig(config)
if err != nil {
return nil, fmt.Errorf("error creating snapshot client: %w", err)
}
return &volumeGroupSnapshotterBase{
framework: f,
groupclient: c,
snapClient: s,
namespace: namespace,
storageClassName: storageClass,
blockPVC: blockPVC,
@ -160,13 +169,27 @@ func (v *volumeGroupSnapshotterBase) DeletePVCs(pvcs []*v1.PersistentVolumeClaim
func (v *volumeGroupSnapshotterBase) CreatePVCClones(
vgs *groupsnapapi.VolumeGroupSnapshot,
) ([]*v1.PersistentVolumeClaim, error) {
pvcSnapRef := vgs.Status.PVCVolumeSnapshotRefList
groupSnapshotContent, err := v.groupclient.VolumeGroupSnapshotContents().Get(
context.TODO(),
*vgs.Status.BoundVolumeGroupSnapshotContentName,
metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("failed to get VolumeGroupSnapshotContent: %w", err)
}
namespace := vgs.Namespace
ctx := context.TODO()
pvcs := make([]*v1.PersistentVolumeClaim, len(pvcSnapRef))
for i, pvcSnap := range pvcSnapRef {
pvcs := make([]*v1.PersistentVolumeClaim, len(groupSnapshotContent.Status.VolumeSnapshotHandlePairList))
for i, snapshot := range groupSnapshotContent.Status.VolumeSnapshotHandlePairList {
volumeHandle := snapshot.VolumeHandle
volumeSnapshotName := fmt.Sprintf("snapshot-%x", sha256.Sum256([]byte(
string(groupSnapshotContent.UID)+volumeHandle)))
volumeSnapshot, err := v.snapClient.VolumeSnapshots(namespace).Get(ctx, volumeSnapshotName, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("failed to get VolumeSnapshot: %w", err)
}
pvcName := *volumeSnapshot.Spec.Source.PersistentVolumeClaimName
pvc, err := v.framework.ClientSet.CoreV1().PersistentVolumeClaims(namespace).Get(ctx,
pvcSnap.PersistentVolumeClaimRef.Name,
pvcName,
metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("failed to get PVC: %w", err)
@ -179,12 +202,11 @@ func (v *volumeGroupSnapshotterBase) CreatePVCClones(
Spec: *pvc.Spec.DeepCopy(),
}
snap := pvcSnap.VolumeSnapshotRef
apiGroup := snapapi.GroupName
pvcs[i].Spec.DataSource = &v1.TypedLocalObjectReference{
APIGroup: &apiGroup,
Kind: "VolumeSnapshot",
Name: snap.Name,
Name: volumeSnapshot.Name,
}
pvcs[i].Spec.StorageClassName = &v.storageClassName
// cleanup the VolumeName as we are creating a new PVC
@ -263,7 +285,7 @@ func (v *volumeGroupSnapshotterBase) DeletePods(pods []*v1.Pod) error {
return nil
}
func (v volumeGroupSnapshotterBase) CreateVolumeGroupSnapshotClass(
func (v *volumeGroupSnapshotterBase) CreateVolumeGroupSnapshotClass(
groupSnapshotClass *groupsnapapi.VolumeGroupSnapshotClass,
) error {
return wait.PollUntilContextTimeout(
@ -286,7 +308,7 @@ func (v volumeGroupSnapshotterBase) CreateVolumeGroupSnapshotClass(
})
}
func (v volumeGroupSnapshotterBase) CreateVolumeGroupSnapshot(name,
func (v *volumeGroupSnapshotterBase) CreateVolumeGroupSnapshot(name,
volumeGroupSnapshotClassName string, labels map[string]string,
) (*groupsnapapi.VolumeGroupSnapshot, error) {
namespace := v.namespace
@ -356,7 +378,7 @@ func (v volumeGroupSnapshotterBase) CreateVolumeGroupSnapshot(name,
return groupSnapshot, nil
}
func (v volumeGroupSnapshotterBase) DeleteVolumeGroupSnapshot(volumeGroupSnapshotName string) error {
func (v *volumeGroupSnapshotterBase) DeleteVolumeGroupSnapshot(volumeGroupSnapshotName string) error {
namespace := v.namespace
ctx := context.TODO()
err := v.groupclient.VolumeGroupSnapshots(namespace).Delete(
@ -395,7 +417,7 @@ func (v volumeGroupSnapshotterBase) DeleteVolumeGroupSnapshot(volumeGroupSnapsho
})
}
func (v volumeGroupSnapshotterBase) DeleteVolumeGroupSnapshotClass(groupSnapshotClassName string) error {
func (v *volumeGroupSnapshotterBase) DeleteVolumeGroupSnapshotClass(groupSnapshotClassName string) error {
ctx := context.TODO()
err := v.groupclient.VolumeGroupSnapshotClasses().Delete(
ctx, groupSnapshotClassName, metav1.DeleteOptions{})