From 72af183397a208be11ec4dce34bf3ba3e9ed8cdf Mon Sep 17 00:00:00 2001 From: Israel Blancas Date: Tue, 29 Nov 2022 22:49:04 +0100 Subject: [PATCH] Run the E2E tests in OpenShift Signed-off-by: Israel Blancas --- Makefile | 43 +++++++++++++++++++++++----------- hack/install-metrics-server.sh | 17 ++++++++++---- hack/modify-test-images.sh | 4 ++++ kuttl-test.yaml | 7 ------ 4 files changed, 46 insertions(+), 25 deletions(-) create mode 100755 hack/modify-test-images.sh diff --git a/Makefile b/Makefile index 51e233c787..60d0003c8e 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,8 @@ else GOTEST_OPTS=-race -v endif +START_KIND_CLUSTER ?= true + KUBE_VERSION ?= 1.24 KIND_CONFIG ?= kind-$(KUBE_VERSION).yaml @@ -115,8 +117,9 @@ set-image-controller: manifests kustomize # Deploy controller in the current Kubernetes context, configured in ~/.kube/config .PHONY: deploy -deploy: set-image-controller +deploy: set-image-controller cert-manager $(KUSTOMIZE) build config/default | kubectl apply -f - + kubectl wait --timeout=5m --for=condition=available deployment opentelemetry-operator-controller-manager -n opentelemetry-operator-system # Undeploy controller in the current Kubernetes context, configured in ~/.kube/config .PHONY: undeploy @@ -171,38 +174,40 @@ e2e-log-operator: kubectl get deploy -A .PHONY: prepare-e2e -prepare-e2e: kuttl set-test-image-vars set-image-controller container container-target-allocator start-kind install-metrics-server load-image-all - mkdir -p tests/_build/crds tests/_build/manifests - $(KUSTOMIZE) build config/default -o tests/_build/manifests/01-opentelemetry-operator.yaml +prepare-e2e: kuttl set-image-controller container container-target-allocator start-kind install-metrics-server load-image-all deploy + mkdir -p tests/_build/crds $(KUSTOMIZE) build config/crd -o tests/_build/crds/ + TARGETALLOCATOR_IMG=$(TARGETALLOCATOR_IMG) ./hack/modify-test-images.sh .PHONY: scorecard-tests scorecard-tests: operator-sdk $(OPERATOR_SDK) scorecard -w=5m bundle || (echo "scorecard test failed" && exit 1) -.PHONY: set-test-image-vars -set-test-image-vars: - $(eval IMG=local/opentelemetry-operator:e2e) - $(eval TARGETALLOCATOR_IMG=local/opentelemetry-operator-targetallocator:e2e) # Build the container image, used only for local dev purposes # buildx is used to ensure same results for arm based systems (m1/2 chips) .PHONY: container container: - docker buildx build --platform linux/${ARCH} -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg OTELCOL_VERSION=${OTELCOL_VERSION} --build-arg TARGETALLOCATOR_VERSION=${TARGETALLOCATOR_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} --build-arg AUTO_INSTRUMENTATION_NODEJS_VERSION=${AUTO_INSTRUMENTATION_NODEJS_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} --build-arg AUTO_INSTRUMENTATION_DOTNET_VERSION=${AUTO_INSTRUMENTATION_DOTNET_VERSION} . + docker buildx build --load --platform linux/${ARCH} -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg OTELCOL_VERSION=${OTELCOL_VERSION} --build-arg TARGETALLOCATOR_VERSION=${TARGETALLOCATOR_VERSION} --build-arg AUTO_INSTRUMENTATION_JAVA_VERSION=${AUTO_INSTRUMENTATION_JAVA_VERSION} --build-arg AUTO_INSTRUMENTATION_NODEJS_VERSION=${AUTO_INSTRUMENTATION_NODEJS_VERSION} --build-arg AUTO_INSTRUMENTATION_PYTHON_VERSION=${AUTO_INSTRUMENTATION_PYTHON_VERSION} --build-arg AUTO_INSTRUMENTATION_DOTNET_VERSION=${AUTO_INSTRUMENTATION_DOTNET_VERSION} . # Push the container image, used only for local dev purposes .PHONY: container-push container-push: docker push ${IMG} +.PHONY: container-target-allocator-push +container-target-allocator-push: + docker push ${TARGETALLOCATOR_IMG} + .PHONY: container-target-allocator container-target-allocator: - docker buildx build --platform linux/${ARCH} -t ${TARGETALLOCATOR_IMG} cmd/otel-allocator + docker buildx build --load --platform linux/${ARCH} -t ${TARGETALLOCATOR_IMG} cmd/otel-allocator .PHONY: start-kind start-kind: +ifeq (true,$(START_KIND_CLUSTER)) kind create cluster --config $(KIND_CONFIG) +endif .PHONY: install-metrics-server install-metrics-server: @@ -212,12 +217,22 @@ install-metrics-server: load-image-all: load-image-operator load-image-target-allocator .PHONY: load-image-operator -load-image-operator: - kind load docker-image local/opentelemetry-operator:e2e +load-image-operator: container +ifeq (true,$(START_KIND_CLUSTER)) + kind load docker-image $(IMG) +else + $(MAKE) container-push +endif + .PHONY: load-image-target-allocator -load-image-target-allocator: - kind load docker-image ${TARGETALLOCATOR_IMG} +load-image-target-allocator: container-target-allocator +ifeq (true,$(START_KIND_CLUSTER)) + kind load docker-image $(TARGETALLOCATOR_IMG) +else + $(MAKE) container-target-allocator-push +endif + .PHONY: cert-manager cert-manager: cmctl diff --git a/hack/install-metrics-server.sh b/hack/install-metrics-server.sh index d63332d77f..10720d16ae 100755 --- a/hack/install-metrics-server.sh +++ b/hack/install-metrics-server.sh @@ -1,7 +1,16 @@ #!/bin/bash -# Install metrics-server on kind clusters for autoscale tests. Note: This is not needed for minikube, +# Install metrics-server on kind clusters for autoscale tests. +# Note: This is not needed for minikube, # you can just add --addons "metrics-server" to the start command. -kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml -kubectl patch deployment -n kube-system metrics-server --type "json" -p '[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": --kubelet-insecure-tls}]' -kubectl wait --for=condition=available deployment/metrics-server -n kube-system --timeout=5m + + +if [[ "$(kubectl api-resources)" =~ "openshift" ]]; then + echo "Connected to an OpenShift cluster. metrics-server installation is not needed" +elif [[ "$(kubectl get deployment metrics-server -n kube-system 2>&1 )" =~ "NotFound" ]]; then + kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml + kubectl patch deployment -n kube-system metrics-server --type "json" -p '[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": --kubelet-insecure-tls}]' + kubectl wait --for=condition=available deployment/metrics-server -n kube-system --timeout=5m +else + echo "metrics-server is installed. Skipping installation" +fi diff --git a/hack/modify-test-images.sh b/hack/modify-test-images.sh new file mode 100755 index 0000000000..8950c7032c --- /dev/null +++ b/hack/modify-test-images.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +sed -i "s#local/opentelemetry-operator-targetallocator:e2e#${TARGETALLOCATOR_IMG}#g" tests/e2e/smoke-targetallocator/00-install.yaml +sed -i "s#local/opentelemetry-operator-targetallocator:e2e#${TARGETALLOCATOR_IMG}#g" tests/e2e/targetallocator-features/00-install.yaml diff --git a/kuttl-test.yaml b/kuttl-test.yaml index de2c6041f4..9dac43816a 100644 --- a/kuttl-test.yaml +++ b/kuttl-test.yaml @@ -2,13 +2,6 @@ apiVersion: kuttl.dev/v1beta1 kind: TestSuite crdDir: ./tests/_build/crds/ artifactsDir: ./tests/_build/artifacts/ -kindContainers: - - local/opentelemetry-operator:e2e -commands: - - command: make cert-manager - - command: kubectl apply -f ./tests/_build/manifests/01-opentelemetry-operator.yaml - - command: kubectl wait --timeout=5m --for=condition=available deployment opentelemetry-operator-controller-manager -n opentelemetry-operator-system - - command: sleep 5s testDirs: - ./tests/e2e/ timeout: 150 \ No newline at end of file