e2e: enhance volumegroupsnapshot test

update the e2e for volumegroupsnapshot
to create application pods from clone pvc
and delete the pods once we are able to
create the pods.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2024-10-30 09:30:39 +01:00 committed by mergify[bot]
parent a7959d4721
commit f4f03044f2

View File

@ -199,6 +199,70 @@ func (v *volumeGroupSnapshotterBase) CreatePVCClones(
return pvcs, nil return pvcs, nil
} }
func (v *volumeGroupSnapshotterBase) CreatePods(pvcs []*v1.PersistentVolumeClaim) ([]*v1.Pod, error) {
pods := make([]*v1.Pod, len(pvcs))
for i, p := range pvcs {
pods[i] = &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("pod-%d", i),
Namespace: p.Namespace,
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "container",
Image: "quay.io/centos/centos:latest",
Command: []string{"/bin/sleep", "999999"},
},
},
},
}
volName := "volume"
if p.Spec.VolumeMode != nil && *p.Spec.VolumeMode == v1.PersistentVolumeBlock {
pods[i].Spec.Containers[0].VolumeDevices = []v1.VolumeDevice{
{
Name: volName,
DevicePath: "/dev/xvda",
},
}
} else {
pods[i].Spec.Containers[0].VolumeMounts = []v1.VolumeMount{
{
Name: volName,
MountPath: "/mnt",
},
}
}
pods[i].Spec.Volumes = []v1.Volume{
{
Name: volName,
VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
ClaimName: p.Name,
},
},
},
}
err := createApp(v.framework.ClientSet, pods[i], v.timeout)
if err != nil {
return nil, fmt.Errorf("failed to create pod: %w", err)
}
}
return pods, nil
}
func (v *volumeGroupSnapshotterBase) DeletePods(pods []*v1.Pod) error {
for _, pod := range pods {
err := deletePod(pod.Name, pod.Namespace, v.framework.ClientSet, deployTimeout)
if err != nil {
return fmt.Errorf("failed to delete pod: %w", err)
}
}
return nil
}
func (v volumeGroupSnapshotterBase) CreateVolumeGroupSnapshotClass( func (v volumeGroupSnapshotterBase) CreateVolumeGroupSnapshotClass(
groupSnapshotClass *groupsnapapi.VolumeGroupSnapshotClass, groupSnapshotClass *groupsnapapi.VolumeGroupSnapshotClass,
) error { ) error {
@ -396,12 +460,21 @@ func (v *volumeGroupSnapshotterBase) testVolumeGroupSnapshot(vol VolumeGroupSnap
if err != nil { if err != nil {
return fmt.Errorf("failed to create clones: %w", err) return fmt.Errorf("failed to create clones: %w", err)
} }
// create pods using the cloned PVCs
pods, err := v.CreatePods(clonePVCs)
if err != nil {
return fmt.Errorf("failed to create pods: %w", err)
}
// validate the resources in the backend // validate the resources in the backend
err = vol.ValidateResourcesForCreate(volumeGroupSnapshot) err = vol.ValidateResourcesForCreate(volumeGroupSnapshot)
if err != nil { if err != nil {
return fmt.Errorf("failed to validate resources for create: %w", err) return fmt.Errorf("failed to validate resources for create: %w", err)
} }
// Delete the pods
err = v.DeletePods(pods)
if err != nil {
return fmt.Errorf("failed to delete pods: %w", err)
}
// Delete the clones // Delete the clones
err = v.DeletePVCs(clonePVCs) err = v.DeletePVCs(clonePVCs)
if err != nil { if err != nil {