Skip to content
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

e2e: enhance volumegroupsnapshot test #4934

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 74 additions & 1 deletion e2e/volumegroupsnapshot_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,70 @@ func (v *volumeGroupSnapshotterBase) CreatePVCClones(
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"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use sleep infinity instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think should be fine for now, i just copied it from other test file, planning for refractoring will take care of it in next PR.

},
},
},
}
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(
groupSnapshotClass *groupsnapapi.VolumeGroupSnapshotClass,
) error {
Expand Down Expand Up @@ -396,12 +460,21 @@ func (v *volumeGroupSnapshotterBase) testVolumeGroupSnapshot(vol VolumeGroupSnap
if err != nil {
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
err = vol.ValidateResourcesForCreate(volumeGroupSnapshot)
if err != nil {
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
err = v.DeletePVCs(clonePVCs)
if err != nil {
Expand Down