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

Fix test issues + increase number of nodes in the cluster #241

Merged
merged 6 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cluster-up/hack/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fi

KUBEVIRTCI_CLUSTER_PATH=${KUBEVIRTCI_CLUSTER_PATH:-${KUBEVIRTCI_PATH}/cluster}
KUBEVIRT_PROVIDER=${KUBEVIRT_PROVIDER:-k8s-1.27}
KUBEVIRT_NUM_NODES=${KUBEVIRT_NUM_NODES:-1}
KUBEVIRT_NUM_NODES=${KUBEVIRT_NUM_NODES:-2}
KUBEVIRT_MEMORY_SIZE=${KUBEVIRT_MEMORY_SIZE:-5120M}
KUBEVIRT_NUM_SECONDARY_NICS=${KUBEVIRT_NUM_SECONDARY_NICS:-0}
KUBEVIRT_DEPLOY_ISTIO=${KUBEVIRT_DEPLOY_ISTIO:-false}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
k8s.io/apimachinery v0.27.1
k8s.io/client-go v12.0.0+incompatible
k8s.io/klog/v2 v2.120.1
k8s.io/utils v0.0.0-20230505201702-9f6742963106
k8s.io/utils v0.0.0-20240423183400-0849a56e8f22
kubevirt.io/api v1.2.0
kubevirt.io/client-go v1.1.1
kubevirt.io/containerized-data-importer-api v1.58.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1591,8 +1591,8 @@ k8s.io/utils v0.0.0-20200414100711-2df71ebbae66/go.mod h1:jPW/WVKK9YHAvNhRxK0md/
k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20211116205334-6203023598ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU=
k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/utils v0.0.0-20240423183400-0849a56e8f22 h1:ao5hUqGhsqdm+bYbjH/pRkCs0unBGe9UyDahzs9zQzQ=
k8s.io/utils v0.0.0-20240423183400-0849a56e8f22/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
kubevirt.io/api v1.2.0 h1:1f8XQLPl4BuHPsc6SHTPnYSYeDxucKCQGa8CdrGJSRc=
kubevirt.io/api v1.2.0/go.mod h1:SbeR9ma4EwnaOZEUkh/lNz0kzYm5LPpEDE30vKXC5Zg=
kubevirt.io/client-go v1.1.1 h1:X/fk9kLW65aHRM3GW71UIzXLZsALPoggt4786yLYz1g=
Expand Down
21 changes: 10 additions & 11 deletions tests/dv_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
. "github.com/onsi/gomega"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
cdiv1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
"kubevirt.io/kubevirt-velero-plugin/tests/framework"
. "kubevirt.io/kubevirt-velero-plugin/tests/framework/matcher"
Expand Down Expand Up @@ -122,14 +121,7 @@ var _ = Describe("DV Backup", func() {
framework.EventuallyDVWith(f.KvClient, srcDv.Namespace, srcDv.Name, 180, HaveSucceeded())

By("Creating source pod")
podSpec := framework.NewPod("source-use-pod", sourceVolumeName, "while true; do echo hello; sleep 2; done")
_, err = f.KvClient.CoreV1().Pods(sourceNamespace.Name).Create(context.TODO(), podSpec, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
Eventually(func() v1.PodPhase {
pod, err := f.KvClient.CoreV1().Pods(sourceNamespace.Name).Get(context.TODO(), podSpec.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
return pod.Status.Phase
}, 90*time.Second, 2*time.Second).Should(Equal(v1.PodRunning))
sourcePod := framework.RunPodAndWaitPhase(f.KvClient, sourceNamespace.Name, sourcePod(sourceVolumeName), v1.PodRunning)

By("Creating clone DV - object under test")
dvSpec := framework.NewCloneDataVolume(dvName, "100Mi", srcDv.Namespace, srcDv.Name, f.StorageClass)
Expand All @@ -152,8 +144,7 @@ var _ = Describe("DV Backup", func() {
Expect(ok).To(BeTrue())

By("Deleting source pod")
err = f.KvClient.CoreV1().Pods(sourceNamespace.Name).Delete(context.TODO(), podSpec.Name, metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
framework.DeletePod(f.KvClient, sourceNamespace.Name, sourcePod.Name)

By("Creating restore test-restore")
err = framework.CreateRestoreForBackup(timeout, backupName, restoreName, f.BackupNamespace, true)
Expand All @@ -167,3 +158,11 @@ var _ = Describe("DV Backup", func() {
})
})
})

func sourcePod(volumeName string) *v1.Pod {
return framework.PodWithPvcSpec(
"source-use-pod",
volumeName,
[]string{"sh"},
[]string{"-c", "while true; do echo hello; sleep 2; done"})
}
140 changes: 140 additions & 0 deletions tests/framework/pod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package framework

import (
"context"
"fmt"
"time"

ginkgo "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/utils/ptr"

apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"kubevirt.io/client-go/kubecli"
)

const (
busyboxImage = "quay.io/quay/busybox:latest"
)

func PodWithPvcSpec(podName, pvcName string, cmd, args []string) *v1.Pod {
volumeName := "pv1"
// uid is used as the qemu group in fsGroup
const uid int64 = 107

return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
GenerateName: podName,
Annotations: map[string]string{
"cdi.kubevirt.io/testing": podName,
},
},
Spec: v1.PodSpec{
SecurityContext: &v1.PodSecurityContext{
FSGroup: ptr.To[int64](uid),
},
RestartPolicy: v1.RestartPolicyNever,
Containers: []v1.Container{
{
Name: podName,
Image: busyboxImage,
Command: cmd,
Args: args,
Resources: v1.ResourceRequirements{
Limits: map[v1.ResourceName]resource.Quantity{
v1.ResourceCPU: *resource.NewQuantity(0, resource.DecimalSI),
awels marked this conversation as resolved.
Show resolved Hide resolved
v1.ResourceMemory: *resource.NewQuantity(0, resource.DecimalSI)},
Requests: map[v1.ResourceName]resource.Quantity{
v1.ResourceCPU: *resource.NewQuantity(0, resource.DecimalSI),
v1.ResourceMemory: *resource.NewQuantity(0, resource.DecimalSI)},
},
VolumeMounts: []v1.VolumeMount{
{
Name: volumeName,
MountPath: "/pvc",
},
},
SecurityContext: &v1.SecurityContext{
RunAsNonRoot: ptr.To(true),
RunAsUser: ptr.To[int64](uid),
RunAsGroup: ptr.To[int64](uid),
Capabilities: &v1.Capabilities{
Drop: []v1.Capability{
"ALL",
},
},
SeccompProfile: &v1.SeccompProfile{
Type: v1.SeccompProfileTypeRuntimeDefault,
},
AllowPrivilegeEscalation: ptr.To(false),
},
},
},
Volumes: []v1.Volume{
{
Name: volumeName,
VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
ClaimName: pvcName,
},
},
},
},
},
}
}

func RunPodAndWaitPhase(kvClient kubecli.KubevirtClient, namespace string, podSpec *v1.Pod, expectedPhase v1.PodPhase) *v1.Pod {
ginkgo.By("creating a pod")
pod, err := kvClient.CoreV1().Pods(namespace).Create(context.Background(), podSpec, metav1.CreateOptions{})
Expect(err).WithOffset(1).ToNot(HaveOccurred())

ginkgo.By("Wait for pod to reach a completed phase")
Eventually(func() v1.PodPhase {
updatedPod, err := kvClient.CoreV1().Pods(namespace).Get(context.Background(), pod.Name, metav1.GetOptions{})
if err != nil {
fmt.Fprintf(ginkgo.GinkgoWriter, "Failed getting pod phase: %s\n", err)
return v1.PodUnknown
}
return updatedPod.Status.Phase
}, 2*time.Minute, 5*time.Second).WithOffset(1).Should(Equal(expectedPhase))

return pod
}

func FindLauncherPod(client *kubernetes.Clientset, namespace string, vmName string) v1.Pod {
var pod v1.Pod
pods, err := client.CoreV1().Pods(namespace).List(context.TODO(), metav1.ListOptions{
LabelSelector: "kubevirt.io=virt-launcher",
})
Expect(err).WithOffset(1).ToNot(HaveOccurred())
for _, item := range pods.Items {
if ann, ok := item.GetAnnotations()["kubevirt.io/domain"]; ok && ann == vmName {
pod = item
}
}
Expect(pod).WithOffset(1).ToNot(BeNil())
return pod
}

func DeletePod(kvClient kubecli.KubevirtClient, namespace, podName string) {
ginkgo.By("Delete pod")
zero := int64(0)
err := kvClient.CoreV1().Pods(namespace).Delete(context.Background(), podName,
metav1.DeleteOptions{
GracePeriodSeconds: &zero,
})
Expect(err).WithOffset(1).ToNot(HaveOccurred())

ginkgo.By("verify deleted")
Eventually(func() error {
_, err := kvClient.CoreV1().Pods(namespace).Get(context.Background(), podName, metav1.GetOptions{})
return err
}, 3*time.Minute, 5*time.Second).
WithOffset(1).
Should(Satisfy(apierrs.IsNotFound), "pod should disappear")
}
104 changes: 0 additions & 104 deletions tests/framework/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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 @@ -25,7 +24,6 @@ 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 @@ -270,108 +268,6 @@ func NewPVC(pvcName, size, storageClass string) *v1.PersistentVolumeClaim {
return pvcSpec
}

func NewPod(podName, pvcName, cmd string) *v1.Pod {
return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: podName,
Annotations: map[string]string{
"cdi.kubevirt.io/testing": podName,
},
},
Spec: v1.PodSpec{
// this may be causing an issue
TerminationGracePeriodSeconds: &[]int64{10}[0],
RestartPolicy: v1.RestartPolicyNever,
Containers: []v1.Container{
{
Name: "runner",
Image: busyboxImage,
Command: []string{"/bin/sh", "-c", cmd},
Resources: v1.ResourceRequirements{
Limits: map[v1.ResourceName]resource.Quantity{
v1.ResourceCPU: *resource.NewQuantity(0, resource.DecimalSI),
v1.ResourceMemory: *resource.NewQuantity(0, resource.DecimalSI)},
Requests: map[v1.ResourceName]resource.Quantity{
v1.ResourceCPU: *resource.NewQuantity(0, resource.DecimalSI),
v1.ResourceMemory: *resource.NewQuantity(0, resource.DecimalSI)},
},
VolumeMounts: []v1.VolumeMount{
{
Name: "storage",
MountPath: "/mnt",
},
},
},
},
Volumes: []v1.Volume{
{
Name: "storage",
VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{
ClaimName: pvcName,
},
},
},
},
},
}
}

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
2 changes: 1 addition & 1 deletion tests/manifests/instancetype.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: instancetype.kubevirt.io/v1alpha2
apiVersion: instancetype.kubevirt.io/v1beta1
kind: VirtualMachineInstancetype
metadata:
name: test-vm-instancetype
Expand Down
2 changes: 1 addition & 1 deletion tests/manifests/preference.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: instancetype.kubevirt.io/v1alpha2
apiVersion: instancetype.kubevirt.io/v1beta1
kind: VirtualMachinePreference
metadata:
name: test-vm-preference
Expand Down
Loading