Skip to content

Commit

Permalink
Get rid of busybox dockerhub image usage in tests (#231)
Browse files Browse the repository at this point in the history
DockerHub is rate limiting, so at some point pulling this will simply fail.

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>
  • Loading branch information
akalenyu authored Apr 4, 2024
1 parent bd72fa2 commit 93f9eea
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 62 deletions.
60 changes: 58 additions & 2 deletions tests/framework/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
6 changes: 3 additions & 3 deletions tests/resource_filtering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
57 changes: 0 additions & 57 deletions tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 93f9eea

Please sign in to comment.