From 2fbc8ca780afaa4f90c38080aab7b9cb896647bf Mon Sep 17 00:00:00 2001 From: zhanglei Date: Tue, 9 Aug 2022 18:38:19 +0800 Subject: [PATCH] test: Add E2E tests --- .github/workflows/e2e.yaml | 20 ++++++ Makefile | 67 +++++++++++++++++++ test/e2e/config/kind/config.yaml | 4 ++ .../create-container-disk-vm/00-assert.yaml | 6 ++ .../00-create-vm.yaml | 27 ++++++++ .../create-container-rootfs-vm/00-assert.yaml | 6 ++ .../00-create-vm.yaml | 31 +++++++++ test/e2e/create-datavolume-vm/00-assert.yaml | 6 ++ .../create-datavolume-vm/00-create-vm.yaml | 43 ++++++++++++ test/e2e/create-masquerade-vm/00-assert.yaml | 6 ++ .../create-masquerade-vm/00-create-vm.yaml | 32 +++++++++ test/e2e/kuttl-test.yaml | 6 ++ 12 files changed, 254 insertions(+) create mode 100644 .github/workflows/e2e.yaml create mode 100644 test/e2e/config/kind/config.yaml create mode 100644 test/e2e/create-container-disk-vm/00-assert.yaml create mode 100644 test/e2e/create-container-disk-vm/00-create-vm.yaml create mode 100644 test/e2e/create-container-rootfs-vm/00-assert.yaml create mode 100644 test/e2e/create-container-rootfs-vm/00-create-vm.yaml create mode 100644 test/e2e/create-datavolume-vm/00-assert.yaml create mode 100644 test/e2e/create-datavolume-vm/00-create-vm.yaml create mode 100644 test/e2e/create-masquerade-vm/00-assert.yaml create mode 100644 test/e2e/create-masquerade-vm/00-create-vm.yaml create mode 100644 test/e2e/kuttl-test.yaml diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml new file mode 100644 index 0000000..072c042 --- /dev/null +++ b/.github/workflows/e2e.yaml @@ -0,0 +1,20 @@ +name: e2e + +on: + push: + branches: + - main + tags: + - v* + +jobs: + e2e: + runs-on: self-hosted + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-go@v2 + with: + go-version: 1.17.9 + + - run: make e2e diff --git a/Makefile b/Makefile index 5b35a30..3e4ad3a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,13 @@ LOCALBIN ?= $(shell pwd)/bin ENVTEST ?= $(LOCALBIN)/setup-envtest ENVTEST_K8S_VERSION = 1.23 +KIND ?= $(LOCALBIN)/kind +CMCTL ?= $(LOCALBIN)/cmctl +SKAFFOLD ?= $(LOCALBIN)/skaffold +KUTTL ?= $(LOCALBIN)/kuttl +KUBECTL ?= $(LOCALBIN)/kubectl +GOARCH ?= $(shell go env GOARCH) +GOOS ?= $(shell go env GOOS) all: test @@ -23,3 +30,63 @@ $(LOCALBIN): envtest: $(ENVTEST) $(ENVTEST): $(LOCALBIN) GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest + +.PHONY: kind +kind: $(KIND) +$(KIND): $(LOCALBIN) + curl -sLo $(KIND) https://kind.sigs.k8s.io/dl/v0.14.0/kind-$(GOOS)-$(GOARCH) && chmod +x $(KIND) + +.PHONY: kubectl +kubectl: $(KUBECTL) +$(KUBECTL): $(LOCALBIN) + curl -sLo $(KUBECTL) https://dl.k8s.io/release/v1.24.0/bin/$(GOOS)/$(GOARCH)/kubectl && chmod +x $(KUBECTL) + +.PHONY: cmctl +cmctl: $(CMCTL) +$(CMCTL): $(LOCALBIN) + curl -sLo cmctl.tar.gz https://github.com/cert-manager/cert-manager/releases/download/v1.8.2/cmctl-$(GOOS)-$(GOARCH).tar.gz + tar xzf cmctl.tar.gz -C $(LOCALBIN) + rm -rf cmctl.tar.gz + +.PHONY: skaffold +skaffold: $(SKAFFOLD) +$(SKAFFOLD): $(LOCALBIN) + curl -sLo $(SKAFFOLD) https://storage.googleapis.com/skaffold/releases/latest/skaffold-$(GOOS)-$(GOARCH) && chmod +x $(SKAFFOLD) + +.PHONY: kuttl +kuttl: $(KUTTL) +$(KUTTL): $(LOCALBIN) + curl -sLo $(KUTTL) https://github.com/kudobuilder/kuttl/releases/download/v0.12.1/kubectl-kuttl_0.12.1_$(GOOS)_$(shell uname -m) && chmod +x $(KUTTL) + +E2E_KIND_CLUSTER_NAME = virtink-e2e-$(shell date "+%Y-%m-%d-%H-%M-%S") +E2E_KIND_CLUSTER_KUBECONFIG = /tmp/$(E2E_KIND_CLUSTER_NAME).kubeconfig + +.PHONY: e2e-image +e2e-image: + docker buildx build -t virt-controller:e2e -f build/virt-controller/Dockerfile --build-arg PRERUNNER_IMAGE=virt-prerunner:e2e . + docker buildx build -t virt-daemon:e2e -f build/virt-daemon/Dockerfile . + docker buildx build -t virt-prerunner:e2e -f build/virt-prerunner/Dockerfile . + +e2e: kind kubectl cmctl skaffold kuttl e2e-image + echo "e2e kind cluster: $(E2E_KIND_CLUSTER_NAME)" + + $(KIND) create cluster --config test/e2e/config/kind/config.yaml --name $(E2E_KIND_CLUSTER_NAME) --kubeconfig $(E2E_KIND_CLUSTER_KUBECONFIG) + $(KIND) load docker-image --name $(E2E_KIND_CLUSTER_NAME) virt-controller:e2e virt-daemon:e2e virt-prerunner:e2e + + KUBECONFIG=$(E2E_KIND_CLUSTER_KUBECONFIG) $(KUBECTL) apply -f https://projectcalico.docs.tigera.io/archive/v3.23/manifests/calico.yaml + KUBECONFIG=$(E2E_KIND_CLUSTER_KUBECONFIG) $(KUBECTL) wait -n kube-system deployment calico-kube-controllers --for condition=Available --timeout -1s + + KUBECONFIG=$(E2E_KIND_CLUSTER_KUBECONFIG) $(KUBECTL) apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.8.2/cert-manager.yaml + KUBECONFIG=$(E2E_KIND_CLUSTER_KUBECONFIG) $(CMCTL) check api --wait=10m + + KUBECONFIG=$(E2E_KIND_CLUSTER_KUBECONFIG) $(KUBECTL) apply -f https://github.com/kubevirt/containerized-data-importer/releases/download/v1.53.0/cdi-operator.yaml + KUBECONFIG=$(E2E_KIND_CLUSTER_KUBECONFIG) $(KUBECTL) wait -n cdi deployment cdi-operator --for condition=Available --timeout -1s + KUBECONFIG=$(E2E_KIND_CLUSTER_KUBECONFIG) $(KUBECTL) apply -f https://github.com/kubevirt/containerized-data-importer/releases/download/v1.53.0/cdi-cr.yaml + KUBECONFIG=$(E2E_KIND_CLUSTER_KUBECONFIG) $(KUBECTL) wait cdi.cdi.kubevirt.io cdi --for condition=Available --timeout -1s + + PATH=$(LOCALBIN):$(PATH) $(SKAFFOLD) render --offline=true --default-repo="" --digest-source=tag --images virt-controller:e2e,virt-daemon:e2e | KUBECONFIG=$(E2E_KIND_CLUSTER_KUBECONFIG) $(KUBECTL) apply -f - + KUBECONFIG=$(E2E_KIND_CLUSTER_KUBECONFIG) $(KUBECTL) wait -n virtink-system deployment virt-controller --for condition=Available --timeout -1s + + KUBECONFIG=$(E2E_KIND_CLUSTER_KUBECONFIG) $(KUTTL) test --config test/e2e/kuttl-test.yaml + + $(KIND) delete cluster --name $(E2E_KIND_CLUSTER_NAME) diff --git a/test/e2e/config/kind/config.yaml b/test/e2e/config/kind/config.yaml new file mode 100644 index 0000000..13e76dd --- /dev/null +++ b/test/e2e/config/kind/config.yaml @@ -0,0 +1,4 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +networking: + disableDefaultCNI: true diff --git a/test/e2e/create-container-disk-vm/00-assert.yaml b/test/e2e/create-container-disk-vm/00-assert.yaml new file mode 100644 index 0000000..645082e --- /dev/null +++ b/test/e2e/create-container-disk-vm/00-assert.yaml @@ -0,0 +1,6 @@ +apiVersion: virt.virtink.smartx.com/v1alpha1 +kind: VirtualMachine +metadata: + name: ubuntu-container-disk +status: + phase: Running diff --git a/test/e2e/create-container-disk-vm/00-create-vm.yaml b/test/e2e/create-container-disk-vm/00-create-vm.yaml new file mode 100644 index 0000000..699594f --- /dev/null +++ b/test/e2e/create-container-disk-vm/00-create-vm.yaml @@ -0,0 +1,27 @@ +apiVersion: virt.virtink.smartx.com/v1alpha1 +kind: VirtualMachine +metadata: + name: ubuntu-container-disk +spec: + instance: + memory: + size: 1Gi + disks: + - name: ubuntu + - name: cloud-init + interfaces: + - name: pod + volumes: + - name: ubuntu + containerDisk: + image: smartxworks/virtink-container-disk-ubuntu + - name: cloud-init + cloudInit: + userData: |- + #cloud-config + password: password + chpasswd: { expire: False } + ssh_pwauth: True + networks: + - name: pod + pod: {} diff --git a/test/e2e/create-container-rootfs-vm/00-assert.yaml b/test/e2e/create-container-rootfs-vm/00-assert.yaml new file mode 100644 index 0000000..2f62acc --- /dev/null +++ b/test/e2e/create-container-rootfs-vm/00-assert.yaml @@ -0,0 +1,6 @@ +apiVersion: virt.virtink.smartx.com/v1alpha1 +kind: VirtualMachine +metadata: + name: ubuntu-container-rootfs +status: + phase: Running diff --git a/test/e2e/create-container-rootfs-vm/00-create-vm.yaml b/test/e2e/create-container-rootfs-vm/00-create-vm.yaml new file mode 100644 index 0000000..9bbceeb --- /dev/null +++ b/test/e2e/create-container-rootfs-vm/00-create-vm.yaml @@ -0,0 +1,31 @@ +apiVersion: virt.virtink.smartx.com/v1alpha1 +kind: VirtualMachine +metadata: + name: ubuntu-container-rootfs +spec: + instance: + memory: + size: 1Gi + kernel: + image: smartxworks/virtink-kernel-5.15.12 + cmdline: "console=ttyS0 root=/dev/vda rw" + disks: + - name: ubuntu + - name: cloud-init + interfaces: + - name: pod + volumes: + - name: ubuntu + containerRootfs: + image: smartxworks/virtink-container-rootfs-ubuntu + size: 4Gi + - name: cloud-init + cloudInit: + userData: |- + #cloud-config + password: password + chpasswd: { expire: False } + ssh_pwauth: True + networks: + - name: pod + pod: {} diff --git a/test/e2e/create-datavolume-vm/00-assert.yaml b/test/e2e/create-datavolume-vm/00-assert.yaml new file mode 100644 index 0000000..a2e74f8 --- /dev/null +++ b/test/e2e/create-datavolume-vm/00-assert.yaml @@ -0,0 +1,6 @@ +apiVersion: virt.virtink.smartx.com/v1alpha1 +kind: VirtualMachine +metadata: + name: ubuntu-datavolume +status: + phase: Running diff --git a/test/e2e/create-datavolume-vm/00-create-vm.yaml b/test/e2e/create-datavolume-vm/00-create-vm.yaml new file mode 100644 index 0000000..09d9e64 --- /dev/null +++ b/test/e2e/create-datavolume-vm/00-create-vm.yaml @@ -0,0 +1,43 @@ +apiVersion: virt.virtink.smartx.com/v1alpha1 +kind: VirtualMachine +metadata: + name: ubuntu-datavolume +spec: + instance: + memory: + size: 1Gi + disks: + - name: ubuntu + - name: cloud-init + interfaces: + - name: pod + volumes: + - name: ubuntu + dataVolume: + volumeName: ubuntu + - name: cloud-init + cloudInit: + userData: |- + #cloud-config + password: password + chpasswd: { expire: False } + ssh_pwauth: True + networks: + - name: pod + pod: {} +--- +apiVersion: cdi.kubevirt.io/v1beta1 +kind: DataVolume +metadata: + name: ubuntu +spec: + source: + http: + #url: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img + url: http://192.168.17.20/kubrid/images/jammy-server-cloudimg-amd64.img + pvc: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 8Gi diff --git a/test/e2e/create-masquerade-vm/00-assert.yaml b/test/e2e/create-masquerade-vm/00-assert.yaml new file mode 100644 index 0000000..7cb4ddf --- /dev/null +++ b/test/e2e/create-masquerade-vm/00-assert.yaml @@ -0,0 +1,6 @@ +apiVersion: virt.virtink.smartx.com/v1alpha1 +kind: VirtualMachine +metadata: + name: ubuntu-masquerade +status: + phase: Running diff --git a/test/e2e/create-masquerade-vm/00-create-vm.yaml b/test/e2e/create-masquerade-vm/00-create-vm.yaml new file mode 100644 index 0000000..6ba49bc --- /dev/null +++ b/test/e2e/create-masquerade-vm/00-create-vm.yaml @@ -0,0 +1,32 @@ +apiVersion: virt.virtink.smartx.com/v1alpha1 +kind: VirtualMachine +metadata: + name: ubuntu-masquerade +spec: + instance: + memory: + size: 1Gi + kernel: + image: smartxworks/virtink-kernel-5.15.12 + cmdline: "console=ttyS0 root=/dev/vda rw" + disks: + - name: ubuntu + - name: cloud-init + interfaces: + - name: pod + masquerade: {} + volumes: + - name: ubuntu + containerRootfs: + image: smartxworks/virtink-container-rootfs-ubuntu + size: 4Gi + - name: cloud-init + cloudInit: + userData: |- + #cloud-config + password: password + chpasswd: { expire: False } + ssh_pwauth: True + networks: + - name: pod + pod: {} diff --git a/test/e2e/kuttl-test.yaml b/test/e2e/kuttl-test.yaml new file mode 100644 index 0000000..b4e3c81 --- /dev/null +++ b/test/e2e/kuttl-test.yaml @@ -0,0 +1,6 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestSuite +testDirs: + - test/e2e +timeout: 300 +parallel: 1