From ef35961caceb87c2da168032ac7c12fb0e918638 Mon Sep 17 00:00:00 2001 From: Anand Kumar Singh Date: Mon, 15 Jul 2024 16:13:01 +0530 Subject: [PATCH] chore: update operator-sdk version to 1.32 (#742) * update operator-sdk version to 1.32 Signed-off-by: Anand Kumar Singh * fix: usign controller-gen 1.14.0 Signed-off-by: Anand Kumar Singh * fix: test, CRD filepath Signed-off-by: Anand Kumar Singh --------- Signed-off-by: Anand Kumar Singh --- Makefile | 46 +++++++++++++++++-- bundle.Dockerfile | 2 +- ...gitops-operator.clusterserviceversion.yaml | 14 +++++- ...s-operator-metrics-service_v1_service.yaml | 1 + bundle/metadata/annotations.yaml | 2 +- config/default/manager_auth_proxy_patch.yaml | 1 + config/manager/manager.yaml | 10 +++- config/rbac/auth_proxy_service.yaml | 1 + test/e2e/suite_test.go | 2 +- test/nondefaulte2e/suite_test.go | 2 +- 10 files changed, 71 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index ea6d5515d..de37c1767 100644 --- a/Makefile +++ b/Makefile @@ -40,12 +40,23 @@ IMAGE_TAG_BASE ?= $(IMAGE) # You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=/:) BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:$(VERSION) +# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command +BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) + +# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests +# You can enable this value if you would like to use SHA Based Digests +# To enable set flag to true +USE_IMAGE_DIGESTS ?= false +ifeq ($(USE_IMAGE_DIGESTS), true) + BUNDLE_GEN_FLAGS += --use-image-digests +endif + # Image URL to use all building/pushing image targets IMG ?= $(IMAGE):$(VERSION) # Set the Operator SDK version to use. # This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit. -OPERATOR_SDK_VERSION ?= v1.22.2 +OPERATOR_SDK_VERSION ?= v1.32.0 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) @@ -61,6 +72,7 @@ endif SHELL = /usr/bin/env bash -o pipefail .SHELLFLAGS = -ec +.PHONY: all all: build ##@ General @@ -76,42 +88,57 @@ all: build # More info on the awk command: # http://linuxcommand.org/lc3_adv_awk.php +.PHONY: help help: ## Display this help. @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) ##@ Development +.PHONY: manifests manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. $(CONTROLLER_GEN) rbac:roleName=manager-role webhook crd paths="./..." output:crd:artifacts:config=config/crd/bases +.PHONY: generate generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." +.PHONY: fmt fmt: ## Run go fmt against code. go fmt ./... +.PHONY: vet vet: ## Run go vet against code. go vet ./... +.PHONY: test-all test-all: manifests generate fmt vet ## Run all tests. go test -timeout 1h ./... -coverprofile cover.out +.PHONY: test-e2e test-e2e: manifests generate fmt vet ## Run e2e tests. go test -p 1 -timeout 1h ./test/e2e -coverprofile cover.out -ginkgo.v go test -p 1 -timeout 1h ./test/nondefaulte2e -coverprofile cover.out -ginkgo.v +.PHONY: test-metrics test-metrics: go test -timeout 30m ./test/e2e -ginkgo.focus="Argo CD metrics controller" -coverprofile cover.out -ginkgo.v + +.PHONY: test-route test-route: go test -timeout 30m ./test/e2e -ginkgo.focus="Argo CD ConsoleLink controller" -coverprofile cover.out -ginkgo.v + +.PHONY: test-gitopsservice test-gitopsservice: go test -p 1 -timeout 1h ./test/e2e -ginkgo.focus="GitOpsServiceController" -coverprofile cover.out -ginkgo.v + +.PHONY: test-gitopsservice-nondefault test-gitopsservice-nondefault: go test -p 1 -timeout 30m ./test/nondefaulte2e -ginkgo.focus="GitOpsServiceNoDefaultInstall" -coverprofile cover.out -ginkgo.v +.PHONY: test test: manifests generate fmt vet ## Run unit tests. go test `go list ./... | grep -v test` -coverprofile cover.out @@ -142,15 +169,19 @@ e2e-non-olm-tests-all: ##@ Build +.PHONY: build build: generate fmt vet ## Build manager binary. go build -o bin/manager main.go +.PHONY: run run: manifests generate fmt vet ## Run a controller from your host. REDIS_CONFIG_PATH="build/redis" go run ./main.go +.PHONY: docker-build docker-build: test ## Build docker image with the manager. docker build -t ${IMG} . +.PHONY: docker-push docker-push: ## Push docker image with the manager. docker push ${IMG} @@ -178,31 +209,40 @@ OPERATOR_SDK = $(shell which operator-sdk) endif endif +ifndef ignore-not-found + ignore-not-found = false +endif ##@ Deployment +.PHONY: install install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. ## TODO: Remove sed usage after all v1alpha1 references are updated to v1beta1 in codebase. ## For local testing, conversion webhook defined in crd makes call to webhook for each v1alpha1 reference ## causing failures as we don't set up the webhook for local testing. $(KUSTOMIZE) build config/crd | sed '/conversion:/,/- v1beta1/d' |kubectl apply --server-side=true -f - +.PHONY: uninstall uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. $(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=true -f - +.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 --server-side=true -f - +.PHONY: undeploy undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. $(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=true -f - CONTROLLER_GEN = $(shell pwd)/bin/controller-gen +.PHONY: controller-gen controller-gen: ## Download controller-gen locally if necessary. $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14.0) KUSTOMIZE = $(shell pwd)/bin/kustomize +.PHONY: kustomize kustomize: ## Download kustomize locally if necessary. $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.5.2) @@ -226,7 +266,7 @@ endef bundle: operator-sdk manifests kustomize ## Generate bundle manifests and metadata, then validate generated files. $(OPERATOR_SDK) generate kustomize manifests -q cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) - $(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) + $(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS) $(OPERATOR_SDK) bundle validate ./bundle .PHONY: bundle-build @@ -246,7 +286,7 @@ ifeq (,$(shell which opm 2>/dev/null)) set -e ;\ mkdir -p $(dir $(OPM)) ;\ OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \ - curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\ + curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\ chmod +x $(OPM) ;\ } else diff --git a/bundle.Dockerfile b/bundle.Dockerfile index b9e4ddfab..e87f111f1 100644 --- a/bundle.Dockerfile +++ b/bundle.Dockerfile @@ -7,7 +7,7 @@ LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/ LABEL operators.operatorframework.io.bundle.package.v1=gitops-operator LABEL operators.operatorframework.io.bundle.channels.v1=latest,gitops-1.8 LABEL operators.operatorframework.io.bundle.channel.default.v1=latest -LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.22.2 +LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.32.0 LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1 LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3 diff --git a/bundle/manifests/gitops-operator.clusterserviceversion.yaml b/bundle/manifests/gitops-operator.clusterserviceversion.yaml index 73506ee6c..635fa7b1d 100644 --- a/bundle/manifests/gitops-operator.clusterserviceversion.yaml +++ b/bundle/manifests/gitops-operator.clusterserviceversion.yaml @@ -164,6 +164,7 @@ metadata: capabilities: Deep Insights console.openshift.io/plugins: '["gitops-plugin"]' containerImage: quay.io/redhat-developer/gitops-operator + createdAt: "2024-07-15T07:28:44Z" description: Enables teams to adopt GitOps principles for managing cluster configurations and application delivery across hybrid multi-cluster Kubernetes environments. features.operators.openshift.io/disconnected: "true" @@ -176,7 +177,7 @@ metadata: operatorframework.io/cluster-monitoring: "true" operatorframework.io/suggested-namespace: openshift-gitops-operator operators.openshift.io/infrastructure-features: '["disconnected"]' - operators.operatorframework.io/builder: operator-sdk-v1.22.2 + operators.operatorframework.io/builder: operator-sdk-v1.32.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 repository: https://github.com/redhat-developer/gitops-operator support: Red Hat @@ -971,6 +972,8 @@ spec: strategy: {} template: metadata: + annotations: + kubectl.kubernetes.io/default-container: manager labels: control-plane: gitops-operator spec: @@ -1007,7 +1010,13 @@ spec: port: 8081 initialDelaySeconds: 5 periodSeconds: 10 - resources: {} + resources: + limits: + cpu: 500m + memory: 768Mi + requests: + cpu: 10m + memory: 256Mi securityContext: allowPrivilegeEscalation: false capabilities: @@ -1028,6 +1037,7 @@ spec: ports: - containerPort: 8443 name: metrics + protocol: TCP resources: limits: cpu: 500m diff --git a/bundle/manifests/openshift-gitops-operator-metrics-service_v1_service.yaml b/bundle/manifests/openshift-gitops-operator-metrics-service_v1_service.yaml index 2e729b72d..e6ff79c93 100644 --- a/bundle/manifests/openshift-gitops-operator-metrics-service_v1_service.yaml +++ b/bundle/manifests/openshift-gitops-operator-metrics-service_v1_service.yaml @@ -11,6 +11,7 @@ spec: ports: - name: metrics port: 8443 + protocol: TCP targetPort: metrics selector: control-plane: gitops-operator diff --git a/bundle/metadata/annotations.yaml b/bundle/metadata/annotations.yaml index 58b2f6615..9cb5bc4d1 100644 --- a/bundle/metadata/annotations.yaml +++ b/bundle/metadata/annotations.yaml @@ -6,7 +6,7 @@ annotations: operators.operatorframework.io.bundle.package.v1: gitops-operator operators.operatorframework.io.bundle.channels.v1: latest,gitops-1.8 operators.operatorframework.io.bundle.channel.default.v1: latest - operators.operatorframework.io.metrics.builder: operator-sdk-v1.22.2 + operators.operatorframework.io.metrics.builder: operator-sdk-v1.32.0 operators.operatorframework.io.metrics.mediatype.v1: metrics+v1 operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3 diff --git a/config/default/manager_auth_proxy_patch.yaml b/config/default/manager_auth_proxy_patch.yaml index 3fff47200..af3f86bd2 100644 --- a/config/default/manager_auth_proxy_patch.yaml +++ b/config/default/manager_auth_proxy_patch.yaml @@ -24,6 +24,7 @@ spec: - --http2-disable ports: - containerPort: 8443 + protocol: TCP name: metrics resources: limits: diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 12896105e..c0a987165 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -19,6 +19,8 @@ spec: replicas: 1 template: metadata: + annotations: + kubectl.kubernetes.io/default-container: manager labels: control-plane: gitops-operator spec: @@ -48,7 +50,13 @@ spec: port: 8081 initialDelaySeconds: 5 periodSeconds: 10 - resources: {} + resources: + limits: + cpu: 500m + memory: 768Mi + requests: + cpu: 10m + memory: 256Mi securityContext: allowPrivilegeEscalation: false capabilities: diff --git a/config/rbac/auth_proxy_service.yaml b/config/rbac/auth_proxy_service.yaml index 3a7e2b4b0..dfaaf9f52 100644 --- a/config/rbac/auth_proxy_service.yaml +++ b/config/rbac/auth_proxy_service.yaml @@ -11,6 +11,7 @@ spec: ports: - name: metrics port: 8443 + protocol: TCP targetPort: metrics selector: control-plane: gitops-operator diff --git a/test/e2e/suite_test.go b/test/e2e/suite_test.go index b6b239ebf..4d59ff9c0 100644 --- a/test/e2e/suite_test.go +++ b/test/e2e/suite_test.go @@ -94,7 +94,7 @@ var _ = BeforeSuite(func() { useActualCluster := true testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{ - filepath.Join("../..", "config", "crd", "bases"), + filepath.Join("..", "..", "config", "crd", "bases"), }, UseExistingCluster: &useActualCluster, // use an actual OpenShift cluster specified in kubeconfig ErrorIfCRDPathMissing: true, diff --git a/test/nondefaulte2e/suite_test.go b/test/nondefaulte2e/suite_test.go index de65fcfb0..f0968bbc1 100644 --- a/test/nondefaulte2e/suite_test.go +++ b/test/nondefaulte2e/suite_test.go @@ -78,7 +78,7 @@ var _ = BeforeSuite(func() { useActualCluster := true testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{ - filepath.Join("../..", "config", "crd", "bases"), + filepath.Join("..", "..", "config", "crd", "bases"), }, UseExistingCluster: &useActualCluster, // use an actual OpenShift cluster specified in kubeconfig ErrorIfCRDPathMissing: true,