diff --git a/.github/workflows/catalogd-e2e.yaml b/.github/workflows/catalogd-e2e.yaml index 06f592788..7f42c2449 100644 --- a/.github/workflows/catalogd-e2e.yaml +++ b/.github/workflows/catalogd-e2e.yaml @@ -17,8 +17,7 @@ jobs: with: go-version-file: "go.mod" - name: Run E2e - working-directory: catalogd - run: make e2e + run: make test-catalogd-e2e upgrade-e2e: runs-on: ubuntu-latest steps: @@ -27,5 +26,4 @@ jobs: with: go-version-file: "go.mod" - name: Run the upgrade e2e test - working-directory: catalogd - run: make test-upgrade-e2e + run: make test-catalogd-upgrade-e2e diff --git a/Makefile b/Makefile index ba2bc7953..a7dffa00b 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ endif export IMAGE_TAG IMG := $(IMAGE_REPO):$(IMAGE_TAG) +CATALOGD_IMG := $(CATALOG_IMAGE_REPO):$(IMAGE_TAG) # Define dependency versions (use go.mod if we also use Go code from dependency) export CERT_MGR_VERSION := v1.15.3 @@ -64,12 +65,15 @@ $(warning Could not find docker or podman in path! This may result in targets re endif KUSTOMIZE_BUILD_DIR := config/overlays/cert-manager +CATALOGD_KUSTOMIZE_BUILD_DIR := catalogd/config/overlays/cert-manager # Disable -j flag for make .NOTPARALLEL: .DEFAULT_GOAL := build +GINKGO := go run github.com/onsi/ginkgo/v2/ginkgo + #SECTION General # The help target prints out all targets with their descriptions organized @@ -209,6 +213,39 @@ test-e2e: KUSTOMIZE_BUILD_DIR := config/overlays/e2e test-e2e: GO_BUILD_FLAGS := -cover test-e2e: run image-registry e2e e2e-coverage kind-clean #HELP Run e2e test suite on local kind cluster +# Catalogd e2e tests +FOCUS := $(if $(TEST),-v -focus "$(TEST)") +ifeq ($(origin E2E_FLAGS), undefined) +E2E_FLAGS := +endif +test-catalogd-e2e: ## Run the e2e tests on existing cluster + $(GINKGO) $(E2E_FLAGS) -trace -vv $(FOCUS) test/catalogd-e2e + +catalogd-e2e: KIND_CLUSTER_NAME := catalogd-e2e +catalogd-e2e: ISSUER_KIND := Issuer +catalogd-e2e: ISSUER_NAME := selfsigned-issuer +catalogd-e2e: CATALOGD_KUSTOMIZE_BUILD_DIR := catalogd/config/overlays/e2e +catalogd-e2e: run catalogd-image-registry test-catalogd-e2e ## kind-clean Run e2e test suite on local kind cluster + +## image-registry target has to come after run-latest-release, +## because the image-registry depends on the olm-ca issuer. +.PHONY: test-catalogd-upgrade-e2e +test-catalogd-upgrade-e2e: export TEST_CLUSTER_CATALOG_NAME := test-catalog +test-catalogd-upgrade-e2e: export TEST_CLUSTER_CATALOG_IMAGE := docker-registry.catalogd-e2e.svc:5000/test-catalog:e2e +test-catalogd-upgrade-e2e: ISSUER_KIND=ClusterIssuer +test-catalogd-upgrade-e2e: ISSUER_NAME=olmv1-ca +test-catalogd-upgrade-e2e: kind-cluster docker-build kind-load run-latest-release catalogd-image-registry catalogd-pre-upgrade-setup kind-deploy catalogd-post-upgrade-checks kind-clean ## Run upgrade e2e tests on a local kind cluster + +.PHONY: catalogd-post-upgrade-checks +catalogd-post-upgrade-checks: + $(GINKGO) $(E2E_FLAGS) -trace -vv $(FOCUS) test/catalogd-upgrade-e2e + +catalogd-pre-upgrade-setup: + ./test/tools/imageregistry/pre-upgrade-setup.sh ${TEST_CLUSTER_CATALOG_IMAGE} ${TEST_CLUSTER_CATALOG_NAME} + +catalogd-image-registry: ## Setup in-cluster image registry + ./test/tools/imageregistry/registry.sh $(ISSUER_KIND) $(ISSUER_NAME) + .PHONY: extension-developer-e2e extension-developer-e2e: KUSTOMIZE_BUILD_DIR := config/overlays/cert-manager extension-developer-e2e: KIND_CLUSTER_NAME := operator-controller-ext-dev-e2e #EXHELP Run extension-developer e2e on local kind cluster @@ -246,10 +283,9 @@ kind-load: $(KIND) #EXHELP Loads the currently constructed images into the KIND kind-deploy: export MANIFEST := ./operator-controller.yaml kind-deploy: export DEFAULT_CATALOG := ./catalogd/config/base/default/clustercatalogs/default-catalogs.yaml kind-deploy: manifests $(KUSTOMIZE) - ($(KUSTOMIZE) build $(KUSTOMIZE_BUILD_DIR) && echo "---" && $(KUSTOMIZE) build catalogd/config/overlays/cert-manager | sed "s/cert-git-version/cert-$(VERSION)/g") > $(MANIFEST) + ($(KUSTOMIZE) build $(KUSTOMIZE_BUILD_DIR) && echo "---" && $(KUSTOMIZE) build $(CATALOGD_KUSTOMIZE_BUILD_DIR) | sed "s/cert-git-version/cert-$(VERSION)/g") > $(MANIFEST) envsubst '$$DEFAULT_CATALOG,$$CERT_MGR_VERSION,$$INSTALL_DEFAULT_CATALOGS,$$MANIFEST' < scripts/install.tpl.sh | bash -s - .PHONY: kind-cluster kind-cluster: $(KIND) #EXHELP Standup a kind cluster. -$(KIND) delete cluster --name $(KIND_CLUSTER_NAME) @@ -302,7 +338,12 @@ go-build-linux: export GOARCH=amd64 go-build-linux: $(BINARIES) .PHONY: run -run: docker-build kind-cluster kind-load kind-deploy #HELP Build the operator-controller then deploy it into a new kind cluster. +run: generate docker-build kind-cluster kind-load kind-deploy wait #HELP Build the operator-controller then deploy it into a new kind cluster. + +CATALOGD_NAMESPACE := olmv1-system +wait: + kubectl wait --for=condition=Available --namespace=$(CATALOGD_NAMESPACE) deployment/catalogd-controller-manager --timeout=60s + kubectl wait --for=condition=Ready --namespace=$(CATALOGD_NAMESPACE) certificate/catalogd-service-cert # Avoid upgrade test flakes when reissuing cert .PHONY: docker-build docker-build: build-linux #EXHELP Build docker image for operator-controller and catalog with GOOS=linux and local GOARCH. diff --git a/catalogd/Makefile b/catalogd/Makefile index 37fd95e05..0fdf290b8 100644 --- a/catalogd/Makefile +++ b/catalogd/Makefile @@ -23,9 +23,6 @@ else $(warning Could not find docker or podman in path! This may result in targets requiring a container runtime failing!) endif -# For standard development and release flows, we use the config/overlays/cert-manager overlay. -KUSTOMIZE_OVERLAY := config/overlays/cert-manager - # bingo manages consistent tooling versions for things like kind, kustomize, etc. include ./../.bingo/Variables.mk @@ -38,14 +35,6 @@ ifeq ($(origin KIND_CLUSTER_NAME), undefined) KIND_CLUSTER_NAME := catalogd endif -# E2E configuration -TESTDATA_DIR := testdata - -CATALOGD_NAMESPACE := olmv1-system -KIND_CLUSTER_IMAGE := kindest/node:v1.30.0@sha256:047357ac0cfea04663786a612ba1eaba9702bef25227a794b52890dd8bcd692e - -GINKGO := go run github.com/onsi/ginkgo/v2/ginkgo - ##@ General # The help target prints out all targets with their descriptions organized @@ -74,42 +63,6 @@ generate: $(CONTROLLER_GEN) ## Generate code and manifests. $(CONTROLLER_GEN) object:headerFile="../hack/boilerplate.go.txt" paths="./..." $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/base/crd/bases output:rbac:artifacts:config=config/base/rbac output:webhook:artifacts:config=config/base/manager/webhook/ -FOCUS := $(if $(TEST),-v -focus "$(TEST)") -ifeq ($(origin E2E_FLAGS), undefined) -E2E_FLAGS := -endif -test-e2e: ## Run the e2e tests on existing cluster - $(GINKGO) $(E2E_FLAGS) -trace -vv $(FOCUS) test/e2e - -e2e: KIND_CLUSTER_NAME := catalogd-e2e -e2e: ISSUER_KIND := Issuer -e2e: ISSUER_NAME := selfsigned-issuer -e2e: KUSTOMIZE_OVERLAY := config/overlays/e2e -e2e: run image-registry test-e2e kind-cluster-cleanup ## Run e2e test suite on local kind cluster - -image-registry: ## Setup in-cluster image registry - ./test/tools/imageregistry/registry.sh $(ISSUER_KIND) $(ISSUER_NAME) - -## image-registry target has to come after run-latest-release, -## because the image-registry depends on the olm-ca issuer. -.PHONY: test-upgrade-e2e -test-upgrade-e2e: export TEST_CLUSTER_CATALOG_NAME := test-catalog -test-upgrade-e2e: export TEST_CLUSTER_CATALOG_IMAGE := docker-registry.catalogd-e2e.svc:5000/test-catalog:e2e -test-upgrade-e2e: ISSUER_KIND=ClusterIssuer -test-upgrade-e2e: ISSUER_NAME=olmv1-ca -test-upgrade-e2e: kind-cluster cert-manager build-container kind-load run-latest-release image-registry pre-upgrade-setup only-deploy-manifest wait post-upgrade-checks kind-cluster-cleanup ## Run upgrade e2e tests on a local kind cluster - -pre-upgrade-setup: - ./test/tools/imageregistry/pre-upgrade-setup.sh ${TEST_CLUSTER_CATALOG_IMAGE} ${TEST_CLUSTER_CATALOG_NAME} - -.PHONY: run-latest-release -run-latest-release: - cd ..; curl -L -s https://github.com/operator-framework/operator-controller/releases/latest/download/install.sh | bash -s - -.PHONY: post-upgrade-checks -post-upgrade-checks: - $(GINKGO) $(E2E_FLAGS) -trace -vv $(FOCUS) test/upgrade - ##@ Build BINARIES=catalogd @@ -157,62 +110,16 @@ $(LINUX_BINARIES): BUILDBIN = bin/linux $(LINUX_BINARIES): GOOS=linux $(BUILDCMD) - -.PHONY: run -run: generate kind-cluster install ## Create a kind cluster and install a local build of catalogd - .PHONY: build-container build-container: build-linux ## Build docker image for catalogd. $(CONTAINER_RUNTIME) build -f Dockerfile -t $(IMAGE) ./bin/linux -##@ Deploy - -.PHONY: kind-cluster -kind-cluster: $(KIND) kind-cluster-cleanup ## Standup a kind cluster - $(KIND) create cluster --name $(KIND_CLUSTER_NAME) --image $(KIND_CLUSTER_IMAGE) - $(KIND) export kubeconfig --name $(KIND_CLUSTER_NAME) - -.PHONY: kind-cluster-cleanup -kind-cluster-cleanup: $(KIND) ## Delete the kind cluster - $(KIND) delete cluster --name $(KIND_CLUSTER_NAME) - .PHONY: kind-load -kind-load: check-cluster $(KIND) ## Load the built images onto the local cluster +kind-load: $(KIND) ## Load the built images onto the local cluster $(CONTAINER_RUNTIME) save $(IMAGE) | $(KIND) load image-archive /dev/stdin --name $(KIND_CLUSTER_NAME) -.PHONY: install -install: check-cluster build-container kind-load deploy wait ## Install local catalogd to an existing cluster - -.PHONY: deploy -deploy: export MANIFEST="./catalogd.yaml" -deploy: export DEFAULT_CATALOGS="./config/base/default/clustercatalogs/default-catalogs.yaml" -deploy: $(KUSTOMIZE) ## Deploy Catalogd to the K8s cluster specified in ~/.kube/config with cert-manager and default clustercatalogs - cd config/base/manager && $(KUSTOMIZE) edit set image controller=$(IMAGE) && cd ../../.. - $(KUSTOMIZE) build $(KUSTOMIZE_OVERLAY) | sed "s/cert-git-version/cert-$(GIT_VERSION)/g" > catalogd.yaml - envsubst '$$CERT_MGR_VERSION,$$MANIFEST,$$DEFAULT_CATALOGS' < scripts/install.tpl.sh | bash -s - -.PHONY: only-deploy-manifest -only-deploy-manifest: $(KUSTOMIZE) ## Deploy just the Catalogd manifest--used in e2e testing where cert-manager is installed in a separate step - cd config/base/manager && $(KUSTOMIZE) edit set image controller=$(IMAGE) - $(KUSTOMIZE) build $(KUSTOMIZE_OVERLAY) | kubectl apply -f - - -wait: - kubectl wait --for=condition=Available --namespace=$(CATALOGD_NAMESPACE) deployment/catalogd-controller-manager --timeout=60s - kubectl wait --for=condition=Ready --namespace=$(CATALOGD_NAMESPACE) certificate/catalogd-service-cert # Avoid upgrade test flakes when reissuing cert - - -.PHONY: cert-manager -cert-manager: - kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/${CERT_MGR_VERSION}/cert-manager.yaml - kubectl wait --for=condition=Available --namespace=cert-manager deployment/cert-manager-webhook --timeout=60s +##@ Deploy .PHONY: demo-update demo-update: hack/scripts/generate-asciidemo.sh - -.PHONY: check-cluster -check-cluster: - @kubectl config current-context >/dev/null 2>&1 || ( \ - echo "Error: Could not get current Kubernetes context. Maybe use 'run' or 'e2e' targets first?"; \ - exit 1; \ - ) diff --git a/catalogd/scripts/install.tpl.sh b/catalogd/scripts/install.tpl.sh deleted file mode 100644 index b71892439..000000000 --- a/catalogd/scripts/install.tpl.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -set -euo pipefail -IFS=$'\n\t' - -catalogd_manifest=$MANIFEST - -if [[ -z "$catalogd_manifest" ]]; then - echo "Error: Missing required MANIFEST variable" - exit 1 -fi - -cert_mgr_version=$CERT_MGR_VERSION -default_catalogs=$DEFAULT_CATALOGS - -if [[ -z "$default_catalogs" || -z "$cert_mgr_version" ]]; then - err="Error: Missing component value(s) for: " - if [[ -z "$default_catalogs" ]]; then - err+="default cluster catalogs " - fi - if [[ -z "$cert_mgr_version" ]]; then - err+="cert-manager version " - fi - echo "$err" - exit 1 -fi - -function kubectl_wait() { - namespace=$1 - runtime=$2 - timeout=$3 - - kubectl wait --for=condition=Available --namespace="${namespace}" "${runtime}" --timeout="${timeout}" -} - -kubectl apply -f "https://github.com/cert-manager/cert-manager/releases/download/$%7Bcert_mgr_version%7D/cert-manager.yaml" -kubectl_wait "cert-manager" "deployment/cert-manager-cainjector" "60s" -kubectl_wait "cert-manager" "deployment/cert-manager-webhook" "60s" -kubectl_wait "cert-manager" "deployment/cert-manager" "60s" -kubectl wait mutatingwebhookconfigurations/cert-manager-webhook --for=jsonpath='{.webhooks[0].clientConfig.caBundle}' --timeout=60s -kubectl wait validatingwebhookconfigurations/cert-manager-webhook --for=jsonpath='{.webhooks[0].clientConfig.caBundle}' --timeout=60s -kubectl apply -f "${catalogd_manifest}" -kubectl_wait "olmv1-system" "deployment/catalogd-controller-manager" "60s" - -kubectl apply -f "${default_catalogs}" -kubectl wait --for=condition=Serving "clustercatalog/operatorhubio" --timeout="60s" \ No newline at end of file diff --git a/catalogd/test/e2e/e2e_suite_test.go b/test/catalogd-e2e/e2e_suite_test.go similarity index 98% rename from catalogd/test/e2e/e2e_suite_test.go rename to test/catalogd-e2e/e2e_suite_test.go index 0a8970a1f..a2399bd0e 100644 --- a/catalogd/test/e2e/e2e_suite_test.go +++ b/test/catalogd-e2e/e2e_suite_test.go @@ -1,4 +1,4 @@ -package e2e +package catalogde2e import ( "fmt" diff --git a/catalogd/test/e2e/unpack_test.go b/test/catalogd-e2e/unpack_test.go similarity index 96% rename from catalogd/test/e2e/unpack_test.go rename to test/catalogd-e2e/unpack_test.go index 5062cd8b0..c16b96dff 100644 --- a/catalogd/test/e2e/unpack_test.go +++ b/test/catalogd-e2e/unpack_test.go @@ -1,4 +1,4 @@ -package e2e +package catalogde2e import ( "context" @@ -79,7 +79,7 @@ var _ = Describe("ClusterCatalog Unpacking", func() { actualFBC, err := ReadTestCatalogServerContents(ctx, catalog, c, kubeClient) Expect(err).To(Not(HaveOccurred())) - expectedFBC, err := os.ReadFile("../../testdata/catalogs/test-catalog/expected_all.json") + expectedFBC, err := os.ReadFile("../../catalogd/testdata/catalogs/test-catalog/expected_all.json") Expect(err).To(Not(HaveOccurred())) Expect(cmp.Diff(expectedFBC, actualFBC)).To(BeEmpty()) diff --git a/catalogd/test/e2e/util.go b/test/catalogd-e2e/util.go similarity index 98% rename from catalogd/test/e2e/util.go rename to test/catalogd-e2e/util.go index dab5edaeb..3d3a8a86c 100644 --- a/catalogd/test/e2e/util.go +++ b/test/catalogd-e2e/util.go @@ -1,4 +1,4 @@ -package e2e +package catalogde2e import ( "context" diff --git a/catalogd/test/upgrade/unpack_test.go b/test/catalogd-upgrade-e2e/unpack_test.go similarity index 94% rename from catalogd/test/upgrade/unpack_test.go rename to test/catalogd-upgrade-e2e/unpack_test.go index 9c42f11f1..1165152f1 100644 --- a/catalogd/test/upgrade/unpack_test.go +++ b/test/catalogd-upgrade-e2e/unpack_test.go @@ -1,4 +1,4 @@ -package upgradee2e +package catalogdupgradee2e import ( "bufio" @@ -21,7 +21,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" catalogdv1 "github.com/operator-framework/operator-controller/catalogd/api/v1" - "github.com/operator-framework/operator-controller/catalogd/test/e2e" + catalogde2e "github.com/operator-framework/operator-controller/test/catalogd-e2e" ) var _ = Describe("ClusterCatalog Unpacking", func() { @@ -87,12 +87,12 @@ var _ = Describe("ClusterCatalog Unpacking", func() { g.Expect(cond.Reason).To(Equal(catalogdv1.ReasonSucceeded)) }).Should(Succeed()) - expectedFBC, err := os.ReadFile("../../testdata/catalogs/test-catalog/expected_all.json") + expectedFBC, err := os.ReadFile("../../catalogd/testdata/catalogs/test-catalog/expected_all.json") Expect(err).To(Not(HaveOccurred())) By("Making sure the catalog content is available via the http server") Eventually(func(g Gomega) { - actualFBC, err := e2e.ReadTestCatalogServerContents(ctx, catalog, c, kubeClient) + actualFBC, err := catalogde2e.ReadTestCatalogServerContents(ctx, catalog, c, kubeClient) g.Expect(err).To(Not(HaveOccurred())) g.Expect(cmp.Diff(expectedFBC, actualFBC)).To(BeEmpty()) }).Should(Succeed()) diff --git a/catalogd/test/upgrade/upgrade_suite_test.go b/test/catalogd-upgrade-e2e/upgrade_suite_test.go similarity index 97% rename from catalogd/test/upgrade/upgrade_suite_test.go rename to test/catalogd-upgrade-e2e/upgrade_suite_test.go index 33b7c731b..76e0114e8 100644 --- a/catalogd/test/upgrade/upgrade_suite_test.go +++ b/test/catalogd-upgrade-e2e/upgrade_suite_test.go @@ -1,4 +1,4 @@ -package upgradee2e +package catalogdupgradee2e import ( "os" diff --git a/catalogd/test/tools/imageregistry/imagebuilder.yaml b/test/tools/imageregistry/imagebuilder.yaml similarity index 100% rename from catalogd/test/tools/imageregistry/imagebuilder.yaml rename to test/tools/imageregistry/imagebuilder.yaml diff --git a/catalogd/test/tools/imageregistry/imgreg.yaml b/test/tools/imageregistry/imgreg.yaml similarity index 100% rename from catalogd/test/tools/imageregistry/imgreg.yaml rename to test/tools/imageregistry/imgreg.yaml diff --git a/catalogd/test/tools/imageregistry/pre-upgrade-setup.sh b/test/tools/imageregistry/pre-upgrade-setup.sh similarity index 100% rename from catalogd/test/tools/imageregistry/pre-upgrade-setup.sh rename to test/tools/imageregistry/pre-upgrade-setup.sh diff --git a/catalogd/test/tools/imageregistry/registry.sh b/test/tools/imageregistry/registry.sh similarity index 84% rename from catalogd/test/tools/imageregistry/registry.sh rename to test/tools/imageregistry/registry.sh index 3995c9b3f..969dff3ec 100755 --- a/catalogd/test/tools/imageregistry/registry.sh +++ b/test/tools/imageregistry/registry.sh @@ -26,8 +26,8 @@ envsubst '${ISSUER_KIND},${ISSUER_NAME}' < test/tools/imageregistry/imgreg.yaml kubectl wait -n catalogd-e2e --for=condition=Available deployment/docker-registry --timeout=60s # Load the testdata onto the cluster as a configmap so it can be used with kaniko -kubectl create configmap -n catalogd-e2e --from-file=testdata/catalogs/test-catalog.Dockerfile catalogd-e2e.dockerfile -kubectl create configmap -n catalogd-e2e --from-file=testdata/catalogs/test-catalog catalogd-e2e.build-contents +kubectl create configmap -n catalogd-e2e --from-file=catalogd/testdata/catalogs/test-catalog.Dockerfile catalogd-e2e.dockerfile +kubectl create configmap -n catalogd-e2e --from-file=catalogd/testdata/catalogs/test-catalog catalogd-e2e.build-contents # Create the kaniko pod to build the test image and push it to the test registry. kubectl apply -f test/tools/imageregistry/imagebuilder.yaml