From 519b216d45b939fc8771cf9ecc0efb6836907fba Mon Sep 17 00:00:00 2001 From: Mikalai Radchuk Date: Mon, 3 Jul 2023 11:48:51 +0100 Subject: [PATCH] Adds E2E coverage reporting Signed-off-by: Mikalai Radchuk --- .github/workflows/e2e.yaml | 7 +++++++ .github/workflows/unit-test.yaml | 1 + .gitignore | 4 ++-- Makefile | 21 ++++++++++++++++----- config/e2e/kustomization.yaml | 8 ++++++++ config/e2e/manager_e2e_coverage_patch.yaml | 21 +++++++++++++++++++++ config/e2e/manager_e2e_coverage_pvc.yaml | 10 ++++++++++ 7 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 config/e2e/kustomization.yaml create mode 100644 config/e2e/manager_e2e_coverage_patch.yaml create mode 100644 config/e2e/manager_e2e_coverage_pvc.yaml diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index d562d21fd..750f6f300 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -23,3 +23,10 @@ jobs: - name: Run e2e tests run: | make e2e + + - uses: codecov/codecov-action@v3 + with: + files: e2e-cover.out + flags: e2e + fail_ci_if_error: true + functionalities: fixes diff --git a/.github/workflows/unit-test.yaml b/.github/workflows/unit-test.yaml index a169f2960..bba7222ab 100644 --- a/.github/workflows/unit-test.yaml +++ b/.github/workflows/unit-test.yaml @@ -25,5 +25,6 @@ jobs: - uses: codecov/codecov-action@v3 with: files: cover.out + flags: unit fail_ci_if_error: true functionalities: fixes diff --git a/.gitignore b/.gitignore index ecfd7f0f4..2ed68b2c3 100644 --- a/.gitignore +++ b/.gitignore @@ -14,8 +14,9 @@ Dockerfile.cross # Test binary, build with `go test -c` *.test -# Output of the go coverage tool, specifically when used with LiteIDE +# Output of the go coverage tools *.out +coverage # Release output dist/** @@ -33,4 +34,3 @@ install.sh *~ \#*\# .\#* - diff --git a/Makefile b/Makefile index ed615c694..e8b6a35f6 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,8 @@ KIND_CLUSTER_NAME ?= operator-controller CONTAINER_RUNTIME ?= docker +KUSTOMIZE_BUILD_DIR ?= config/default + # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) GOBIN=$(shell go env GOPATH)/bin @@ -103,7 +105,16 @@ test-unit: $(SETUP_ENVTEST) ## Run the unit tests eval $$($(SETUP_ENVTEST) use -p env $(ENVTEST_VERSION)) && go test -tags $(GO_BUILD_TAGS) -count=1 -short $(UNIT_TEST_DIRS) -coverprofile cover.out e2e: KIND_CLUSTER_NAME=operator-controller-e2e -e2e: run kind-load-test-artifacts test-e2e kind-cluster-cleanup ## Run e2e test suite on local kind cluster +e2e: KUSTOMIZE_BUILD_DIR=config/e2e +e2e: GO_BUILD_FLAGS=-cover +e2e: run kind-load-test-artifacts test-e2e ## Run e2e test suite on local kind cluster + # Coverage-instrumented binary produces coverage on termination, so we scale down the manager before gathering the coverage + kubectl -n $(OPERATOR_CONTROLLER_NAMESPACE) scale deployment/operator-controller-controller-manager --replicas=0 + kubectl -n $(OPERATOR_CONTROLLER_NAMESPACE) run pvc-copy --image busybox --restart=Never --override-type strategic --overrides='{"spec": {"volumes": [{"name": "data", "persistentVolumeClaim": {"claimName": "e2e-coverage"}}], "containers": [{"name": "pvc-copy", "volumeMounts": [{"name": "data", "mountPath": "/data"}]}]}}' -- sleep infinity + kubectl -n $(OPERATOR_CONTROLLER_NAMESPACE) wait --for=condition=ready pod pvc-copy + kubectl -n $(OPERATOR_CONTROLLER_NAMESPACE) cp pvc-copy:/data/ ./coverage/ + go tool covdata textfmt -i=./coverage/ -o e2e-cover.out + $(MAKE) kind-cluster-cleanup KIND_CLUSTER_NAME=$(KIND_CLUSTER_NAME) kind-load: $(KIND) ## Loads the currently constructed image onto the cluster $(KIND) load docker-image $(IMG) --name $(KIND_CLUSTER_NAME) @@ -174,7 +185,7 @@ release: $(GORELEASER) ## Runs goreleaser for the operator-controller. By defaul quickstart: export MANIFEST="https://github.com/operator-framework/operator-controller/releases/download/$(VERSION)/operator-controller.yaml" quickstart: $(KUSTOMIZE) generate ## Generate the installation release manifests and scripts - $(KUSTOMIZE) build config/default | sed "s/:devel/:$(VERSION)/g" > operator-controller.yaml + $(KUSTOMIZE) build $(KUSTOMIZE_BUILD_DIR) | sed "s/:devel/:$(VERSION)/g" > operator-controller.yaml envsubst '$$CATALOGD_VERSION,$$CERT_MGR_VERSION,$$RUKPAK_VERSION,$$MANIFEST' < scripts/install.tpl.sh > install.sh ##@ Deployment @@ -186,7 +197,7 @@ endif .PHONY: install install: export MANIFEST="./operator-controller.yaml" install: manifests $(KUSTOMIZE) generate ## Install CRDs into the K8s cluster specified in ~/.kube/config. - $(KUSTOMIZE) build config/default > operator-controller.yaml + $(KUSTOMIZE) build $(KUSTOMIZE_BUILD_DIR) > operator-controller.yaml envsubst '$$CATALOGD_VERSION,$$CERT_MGR_VERSION,$$RUKPAK_VERSION,$$MANIFEST' < scripts/install.tpl.sh | bash -s .PHONY: uninstall @@ -196,8 +207,8 @@ uninstall: manifests $(KUSTOMIZE) ## Uninstall CRDs from the K8s cluster specifi .PHONY: deploy deploy: manifests $(KUSTOMIZE) ## Deploy controller to the K8s cluster specified in ~/.kube/config. cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} - $(KUSTOMIZE) build config/default | kubectl apply -f - + $(KUSTOMIZE) build $(KUSTOMIZE_BUILD_DIR) | kubectl apply -f - .PHONY: undeploy undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. - $(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f - + $(KUSTOMIZE) build $(KUSTOMIZE_BUILD_DIR) | kubectl delete --ignore-not-found=$(ignore-not-found) -f - diff --git a/config/e2e/kustomization.yaml b/config/e2e/kustomization.yaml new file mode 100644 index 000000000..3cb7ee051 --- /dev/null +++ b/config/e2e/kustomization.yaml @@ -0,0 +1,8 @@ +namespace: operator-controller-system + +resources: +- ../default +- manager_e2e_coverage_pvc.yaml + +patches: +- path: manager_e2e_coverage_patch.yaml diff --git a/config/e2e/manager_e2e_coverage_patch.yaml b/config/e2e/manager_e2e_coverage_patch.yaml new file mode 100644 index 000000000..bda011daf --- /dev/null +++ b/config/e2e/manager_e2e_coverage_patch.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: controller-manager + namespace: system +spec: + template: + spec: + containers: + - name: kube-rbac-proxy + - name: manager + env: + - name: GOCOVERDIR + value: /e2e-coverage + volumeMounts: + - name: e2e-coverage-volume + mountPath: /e2e-coverage + volumes: + - name: e2e-coverage-volume + persistentVolumeClaim: + claimName: e2e-coverage diff --git a/config/e2e/manager_e2e_coverage_pvc.yaml b/config/e2e/manager_e2e_coverage_pvc.yaml new file mode 100644 index 000000000..126d4d4e6 --- /dev/null +++ b/config/e2e/manager_e2e_coverage_pvc.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: e2e-coverage +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 64Mi