From 93f9eea6ee3f44eb8074f822e26df95d9ed4243a Mon Sep 17 00:00:00 2001 From: Alex Kalenyuk Date: Thu, 4 Apr 2024 19:30:39 +0300 Subject: [PATCH] Get rid of busybox dockerhub image usage in tests (#231) DockerHub is rate limiting, so at some point pulling this will simply fail. Signed-off-by: Alex Kalenyuk --- tests/framework/storage.go | 60 ++++++++++++++++++++++++++++++-- tests/resource_filtering_test.go | 6 ++-- tests/utils.go | 57 ------------------------------ 3 files changed, 61 insertions(+), 62 deletions(-) diff --git a/tests/framework/storage.go b/tests/framework/storage.go index e0d5dcda..7428c6aa 100644 --- a/tests/framework/storage.go +++ b/tests/framework/storage.go @@ -12,6 +12,7 @@ import ( "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/resource" "k8s.io/client-go/kubernetes" + "k8s.io/utils/pointer" apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -24,6 +25,7 @@ import ( const ( pollInterval = 2 * time.Second waitTime = 180 * time.Second + busyboxImage = "quay.io/quay/busybox:latest" ) func IsDataVolumeGC(kvClient kubecli.KubevirtClient) bool { @@ -269,7 +271,6 @@ func NewPVC(pvcName, size, storageClass string) *v1.PersistentVolumeClaim { } func NewPod(podName, pvcName, cmd string) *v1.Pod { - importerImage := "quay.io/quay/busybox:latest" return &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: podName, @@ -284,7 +285,7 @@ func NewPod(podName, pvcName, cmd string) *v1.Pod { Containers: []v1.Container{ { Name: "runner", - Image: importerImage, + Image: busyboxImage, Command: []string{"/bin/sh", "-c", cmd}, Resources: v1.ResourceRequirements{ Limits: map[v1.ResourceName]resource.Quantity{ @@ -316,6 +317,61 @@ func NewPod(podName, pvcName, cmd string) *v1.Pod { } } +func PodWithPvcSpec(podName, pvcName string, cmd, args []string) *v1.Pod { + volumeName := "pv1" + const uid int64 = 107 + + return &v1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + GenerateName: podName, + }, + Spec: v1.PodSpec{ + SecurityContext: &v1.PodSecurityContext{ + FSGroup: pointer.Int64(uid), + }, + RestartPolicy: v1.RestartPolicyNever, + Containers: []v1.Container{ + { + Name: podName, + Image: busyboxImage, + Command: cmd, + Args: args, + VolumeMounts: []v1.VolumeMount{ + { + Name: volumeName, + MountPath: "/pvc", + }, + }, + SecurityContext: &v1.SecurityContext{ + RunAsNonRoot: pointer.Bool(true), + RunAsUser: pointer.Int64(uid), + RunAsGroup: pointer.Int64(uid), + Capabilities: &v1.Capabilities{ + Drop: []v1.Capability{ + "ALL", + }, + }, + SeccompProfile: &v1.SeccompProfile{ + Type: v1.SeccompProfileTypeRuntimeDefault, + }, + AllowPrivilegeEscalation: pointer.Bool(false), + }, + }, + }, + Volumes: []v1.Volume{ + { + Name: volumeName, + VolumeSource: v1.VolumeSource{ + PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ + ClaimName: pvcName, + }, + }, + }, + }, + }, + } +} + func NewCloneDataVolume(name, size, srcNamespace, srcPvcName string, storageClassName string) *cdiv1.DataVolume { dv := &cdiv1.DataVolume{ ObjectMeta: metav1.ObjectMeta{ diff --git a/tests/resource_filtering_test.go b/tests/resource_filtering_test.go index dd2fefe8..69983294 100644 --- a/tests/resource_filtering_test.go +++ b/tests/resource_filtering_test.go @@ -3498,21 +3498,21 @@ func deletePod(kvClient kubecli.KubevirtClient, namespace, podName string) { } func verifyFileExists(volumeName string) *v1.Pod { - return PodWithPvcSpec("reader-pod", + return framework.PodWithPvcSpec("reader-pod", volumeName, []string{"sh"}, []string{"-c", "test -f /pvc/test.txt"}) } func verifyNoFile(volumeName string) *v1.Pod { - return PodWithPvcSpec("reader-pod", + return framework.PodWithPvcSpec("reader-pod", volumeName, []string{"sh"}, []string{"-c", "! test -e /pvc/test.txt"}) } func writerPod(volumeName string) *v1.Pod { - return PodWithPvcSpec( + return framework.PodWithPvcSpec( "writer-pod", volumeName, []string{"sh"}, diff --git a/tests/utils.go b/tests/utils.go index 46339d05..8d3d1e04 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -9,7 +9,6 @@ import ( v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/pointer" kvv1 "kubevirt.io/api/core/v1" "kubevirt.io/client-go/kubecli" cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1" @@ -39,62 +38,6 @@ func PrintEvents(client kubecli.KubevirtClient, namespace, name string) { } } -func PodWithPvcSpec(podName, pvcName string, cmd, args []string) *v1.Pod { - image := "busybox" - volumeName := "pv1" - const uid int64 = 107 - - return &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - GenerateName: podName, - }, - Spec: v1.PodSpec{ - SecurityContext: &v1.PodSecurityContext{ - FSGroup: pointer.Int64(uid), - }, - RestartPolicy: v1.RestartPolicyNever, - Containers: []v1.Container{ - { - Name: podName, - Image: image, - Command: cmd, - Args: args, - VolumeMounts: []v1.VolumeMount{ - { - Name: volumeName, - MountPath: "/pvc", - }, - }, - SecurityContext: &v1.SecurityContext{ - RunAsNonRoot: pointer.Bool(true), - RunAsUser: pointer.Int64(uid), - RunAsGroup: pointer.Int64(uid), - Capabilities: &v1.Capabilities{ - Drop: []v1.Capability{ - "ALL", - }, - }, - SeccompProfile: &v1.SeccompProfile{ - Type: v1.SeccompProfileTypeRuntimeDefault, - }, - AllowPrivilegeEscalation: pointer.Bool(false), - }, - }, - }, - Volumes: []v1.Volume{ - { - Name: volumeName, - VolumeSource: v1.VolumeSource{ - PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ - ClaimName: pvcName, - }, - }, - }, - }, - }, - } -} - var newVMSpecBlankDVTemplate = func(vmName, size string) *kvv1.VirtualMachine { no := false var zero int64 = 0