Skip to content

Commit

Permalink
Adds E2E coverage reporting
Browse files Browse the repository at this point in the history
Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
  • Loading branch information
m1kola committed Jul 7, 2023
1 parent 25b3d9c commit 65c48f5
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ jobs:
- uses: codecov/codecov-action@v3
with:
files: cover.out
flags: unit
fail_ci_if_error: true
functionalities: fixes
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/**
Expand All @@ -33,4 +34,3 @@ install.sh
*~
\#*\#
.\#*

21 changes: 16 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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", "securityContext": {"runAsUser": 65532, "runAsNonRoot": true, "allowPrivilegeEscalation": false, "seccompProfile": {"type": "RuntimeDefault"}, "capabilities": {"drop": ["ALL"]}}, "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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 -
8 changes: 8 additions & 0 deletions config/e2e/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace: operator-controller-system

resources:
- ../default
- manager_e2e_coverage_pvc.yaml

patches:
- path: manager_e2e_coverage_patch.yaml
21 changes: 21 additions & 0 deletions config/e2e/manager_e2e_coverage_patch.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions config/e2e/manager_e2e_coverage_pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: e2e-coverage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 64Mi

0 comments on commit 65c48f5

Please sign in to comment.