From 6634e7355ed7199a0fe7618c3af01d0c84014668 Mon Sep 17 00:00:00 2001 From: Nestor Acuna-Blanco Date: Wed, 3 Jul 2024 15:39:43 +0200 Subject: [PATCH] feat: deploy and functest make tasks This tasks are helpful when working wieh an external Kubernetes cluster. The 'deploy' task installs the bundles and their dependencies, while the 'functest' task runs the function tests against the cluster. Signed-off-by: Nestor Acuna-Blanco --- DEVELOPMENT.md | 2 ++ Makefile | 11 ++++++++ scripts/deploy-kubevirt-and-cdi.sh | 41 ++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100755 scripts/deploy-kubevirt-and-cdi.sh diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 455bc4e2..3c551ab3 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -50,6 +50,8 @@ The following targets are provided by the `Makefile` * `make kubeconform`: Install vendored `kubeconform` from `./tools` into `./_bin`. * `make yq`: Install vendored `yq` from `./tools` into `./_bin`. * `make golangci-lint`: Install `golangci-lint` version specified in `Makefile` into `./_bin`. +* `make deploy`: Deploy `common-instancetypes` to an external cluster. +* `make functest`: Run functest against an external cluster. ## Running Makefile targets within a container diff --git a/Makefile b/Makefile index 09f6f0ff..84b71944 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,9 @@ YQ_PACKAGE ?= github.com/mikefarah/yq/v4 # Version of golangci-lint to install GOLANGCI_LINT_VERSION ?= v1.55.2 +# Kubeconfig default value +KUBECONFIG ?= ~/.kube/config + .PHONY: all all: lint validate readme test-lint test @@ -41,6 +44,14 @@ lint: generate generate: kustomize yq scripts/generate.sh +.PHONY: deploy +deploy: generate + scripts/deploy-kubevirt-and-cdi.sh && KUBECTL=kubectl scripts/sync.sh + +.PHONY: functest +functest: + cd tests && KUBECONFIG=$(KUBECONFIG) go test -v -timeout 0 ./functests/... -ginkgo.v -ginkgo.randomize-all $(FUNCTEST_EXTRA_ARGS) + .PHONY: validate validate: generate schema kubeconform scripts/validate.sh diff --git a/scripts/deploy-kubevirt-and-cdi.sh b/scripts/deploy-kubevirt-and-cdi.sh new file mode 100755 index 00000000..7367db07 --- /dev/null +++ b/scripts/deploy-kubevirt-and-cdi.sh @@ -0,0 +1,41 @@ +#!/bin/bash +set -e + +function latest_version() { + local repo="$1" + curl -s https://api.github.com/repos/kubevirt/${repo}/releases/latest | \ + grep '"tag_name":' | \ + sed -E 's/.*"([^"]+)".*/\1/' +} + + +# Deploying kubevirt +KUBEVIRT_VERSION=$(curl -L https://storage.googleapis.com/kubevirt-prow/devel/release/kubevirt/kubevirt/stable.txt) +KUBEVIRT_NAMESPACE=${1:-kubevirt} + +kubectl apply -n ${KUBEVIRT_NAMESPACE} -f "https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml" +kubectl apply -n ${KUBEVIRT_NAMESPACE} -f "https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-cr.yaml" + +kubectl patch -n ${KUBEVIRT_NAMESPACE} kubevirt kubevirt --type='json' -p '[{ + "op": "add", + "path": "/spec/configuration/developerConfiguration/featureGates/-", + "value": "NUMA", +},{ + "op": "add", + "path": "/spec/configuration/developerConfiguration/featureGates/-", + "value": "GPU", +}]' + +echo "Waiting for Kubevirt to be ready..." +kubectl wait --for=condition=Available --timeout=600s -n ${KUBEVIRT_NAMESPACE} kv/kubevirt + + +# Deploying CDI +CDI_VERSION=$(latest_version "containerized-data-importer") +CDI_NAMESPACE=cdi + +kubectl apply -n ${CDI_NAMESPACE} -f "https://github.com/kubevirt/containerized-data-importer/releases/download/${CDI_VERSION}/cdi-operator.yaml" +kubectl apply -n ${CDI_NAMESPACE} -f "https://github.com/kubevirt/containerized-data-importer/releases/download/${CDI_VERSION}/cdi-cr.yaml" + +echo "Waiting for CDI to be ready..." +kubectl wait --for=condition=Available --timeout=600s -n ${CDI_NAMESPACE} cdi/cdi