Skip to content

Commit

Permalink
test: Add E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scuzhanglei authored and fengye87 committed Aug 26, 2022
1 parent 4b5e4d2 commit 2fbc8ca
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -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
67 changes: 67 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
4 changes: 4 additions & 0 deletions test/e2e/config/kind/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
disableDefaultCNI: true
6 changes: 6 additions & 0 deletions test/e2e/create-container-disk-vm/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: virt.virtink.smartx.com/v1alpha1
kind: VirtualMachine
metadata:
name: ubuntu-container-disk
status:
phase: Running
27 changes: 27 additions & 0 deletions test/e2e/create-container-disk-vm/00-create-vm.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
6 changes: 6 additions & 0 deletions test/e2e/create-container-rootfs-vm/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: virt.virtink.smartx.com/v1alpha1
kind: VirtualMachine
metadata:
name: ubuntu-container-rootfs
status:
phase: Running
31 changes: 31 additions & 0 deletions test/e2e/create-container-rootfs-vm/00-create-vm.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
6 changes: 6 additions & 0 deletions test/e2e/create-datavolume-vm/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: virt.virtink.smartx.com/v1alpha1
kind: VirtualMachine
metadata:
name: ubuntu-datavolume
status:
phase: Running
43 changes: 43 additions & 0 deletions test/e2e/create-datavolume-vm/00-create-vm.yaml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions test/e2e/create-masquerade-vm/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: virt.virtink.smartx.com/v1alpha1
kind: VirtualMachine
metadata:
name: ubuntu-masquerade
status:
phase: Running
32 changes: 32 additions & 0 deletions test/e2e/create-masquerade-vm/00-create-vm.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
6 changes: 6 additions & 0 deletions test/e2e/kuttl-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestSuite
testDirs:
- test/e2e
timeout: 300
parallel: 1

0 comments on commit 2fbc8ca

Please sign in to comment.