From 928f026143872af386e3d1b32bff4718e5d88b64 Mon Sep 17 00:00:00 2001 From: Chris Bandy Date: Wed, 14 Feb 2024 11:44:54 -0600 Subject: [PATCH 1/3] Download the "controller-gen" tool in its own target The script in "hack/" is counter-intuitive to me now. Development tools and their versions are now in the Makefile. --- Makefile | 41 +++++++++++++++++++++++++++--------- hack/controller-generator.sh | 27 ------------------------ hack/generate-rbac.sh | 10 +-------- 3 files changed, 32 insertions(+), 46 deletions(-) delete mode 100755 hack/controller-generator.sh diff --git a/Makefile b/Makefile index cefc81d078..eacc3e4e65 100644 --- a/Makefile +++ b/Makefile @@ -269,23 +269,24 @@ generate: generate-deepcopy generate: generate-rbac .PHONY: generate-crd -generate-crd: ## Generate crd - GOBIN='$(CURDIR)/hack/tools' ./hack/controller-generator.sh \ +generate-crd: ## Generate Custom Resource Definitions (CRDs) +generate-crd: tools/controller-gen + $(CONTROLLER) \ crd:crdVersions='v1' \ paths='./pkg/apis/...' \ output:dir='build/crd/postgresclusters/generated' # build/crd/{plural}/generated/{group}_{plural}.yaml @ - GOBIN='$(CURDIR)/hack/tools' ./hack/controller-generator.sh \ + $(CONTROLLER) \ crd:crdVersions='v1' \ paths='./pkg/apis/...' \ output:dir='build/crd/pgupgrades/generated' # build/crd/{plural}/generated/{group}_{plural}.yaml @ - GOBIN='$(CURDIR)/hack/tools' ./hack/controller-generator.sh \ + $(CONTROLLER) \ crd:crdVersions='v1' \ paths='./pkg/apis/...' \ output:dir='build/crd/pgadmins/generated' # build/crd/{plural}/generated/{group}_{plural}.yaml @ - GOBIN='$(CURDIR)/hack/tools' ./hack/controller-generator.sh \ + $(CONTROLLER) \ crd:crdVersions='v1' \ paths='./pkg/apis/...' \ output:dir='build/crd/crunchybridgeclusters/generated' # build/crd/{plural}/generated/{group}_{plural}.yaml @@ -296,15 +297,35 @@ generate-crd: ## Generate crd kubectl kustomize ./build/crd/crunchybridgeclusters > ./config/crd/bases/postgres-operator.crunchydata.com_crunchybridgeclusters.yaml .PHONY: generate-deepcopy -generate-deepcopy: ## Generate deepcopy functions - GOBIN='$(CURDIR)/hack/tools' ./hack/controller-generator.sh \ +generate-deepcopy: ## Generate DeepCopy functions +generate-deepcopy: tools/controller-gen + $(CONTROLLER) \ object:headerFile='hack/boilerplate.go.txt' \ paths='./pkg/apis/postgres-operator.crunchydata.com/...' .PHONY: generate-rbac -generate-rbac: ## Generate rbac - GOBIN='$(CURDIR)/hack/tools' ./hack/generate-rbac.sh \ - './internal/...' 'config/rbac' +generate-rbac: ## Generate RBAC +generate-rbac: tools/controller-gen + $(CONTROLLER) \ + rbac:roleName='generated' \ + paths='./internal/...' \ + output:dir='config/rbac' # ${directory}/role.yaml + ./hack/generate-rbac.sh 'config/rbac' + +##@ Tools + +.PHONY: tools +tools: ## Download tools like controller-gen and kustomize if necessary. + +# go-get-tool will 'go install' any package $2 and install it to $1. +define go-get-tool +@[ -f '$(1)' ] || { echo Downloading '$(2)'; GOBIN='$(abspath $(dir $(1)))' $(GO) install '$(2)'; } +endef + +CONTROLLER ?= hack/tools/controller-gen +tools: tools/controller-gen +tools/controller-gen: + $(call go-get-tool,$(CONTROLLER),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0) ##@ Release diff --git a/hack/controller-generator.sh b/hack/controller-generator.sh deleted file mode 100755 index dd2c2f217b..0000000000 --- a/hack/controller-generator.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2021 - 2024 Crunchy Data Solutions, Inc. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -set -eu - -# Find the Go install path. -[ "${GOBIN:-}" ] || GOBIN="$(go env GOBIN)" -[ "${GOBIN:-}" ] || GOBIN="$(go env GOPATH)/bin" - -# Find `controller-gen` on the current PATH or install it to the Go install path. -tool="$(command -v controller-gen || true)" -[ -n "$tool" ] || tool="$GOBIN/controller-gen" -[ -x "$tool" ] || go install 'sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0' - -"$tool" "$@" diff --git a/hack/generate-rbac.sh b/hack/generate-rbac.sh index 4305ec75c3..4ad430a5e9 100755 --- a/hack/generate-rbac.sh +++ b/hack/generate-rbac.sh @@ -15,15 +15,7 @@ set -eu -declare -r paths="$1" directory="$2" - -# Use `controller-gen` to parse Go markers. -( set -x -"${BASH_SOURCE[0]%/*}/controller-generator.sh" \ - rbac:roleName='generated' \ - paths="${paths}" \ - output:dir="${directory}" # ${directory}/role.yaml -) +declare -r directory="$1" # NOTE(cbandy): `kustomize` v4.1 and `kubectl` v1.22 will be able to change the # kind of a resource: https://pr.k8s.io/101120 From 1f87ed74b4905bc60da8ffb0cbe03c93724787be Mon Sep 17 00:00:00 2001 From: Chris Bandy Date: Wed, 14 Feb 2024 11:47:25 -0600 Subject: [PATCH 2/3] Download the "setup-envtest" tool in its own target --- Makefile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index eacc3e4e65..5b8a097a77 100644 --- a/Makefile +++ b/Makefile @@ -194,10 +194,9 @@ check: get-pgmonitor # - KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT=true .PHONY: check-envtest check-envtest: ## Run check using envtest and a mock kube api -check-envtest: ENVTEST_USE = hack/tools/setup-envtest --bin-dir=$(CURDIR)/hack/tools/envtest use $(ENVTEST_K8S_VERSION) +check-envtest: ENVTEST_USE = $(ENVTEST) --bin-dir=$(CURDIR)/hack/tools/envtest use $(ENVTEST_K8S_VERSION) check-envtest: SHELL = bash -check-envtest: get-pgmonitor - GOBIN='$(CURDIR)/hack/tools' $(GO) install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest +check-envtest: get-pgmonitor tools/setup-envtest @$(ENVTEST_USE) --print=overview && echo source <($(ENVTEST_USE) --print=env) && PGO_NAMESPACE="postgres-operator" QUERIES_CONFIG_DIR="$(CURDIR)/${QUERIES_CONFIG_DIR}" \ $(GO_TEST) -count=1 -cover ./... @@ -327,6 +326,11 @@ tools: tools/controller-gen tools/controller-gen: $(call go-get-tool,$(CONTROLLER),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0) +ENVTEST ?= hack/tools/setup-envtest +tools: tools/setup-envtest +tools/setup-envtest: + $(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) + ##@ Release .PHONY: license licenses From 2481a7201d81b73ba31b436abffa0f4a521778cc Mon Sep 17 00:00:00 2001 From: Chris Bandy Date: Wed, 10 Apr 2024 13:11:29 -0500 Subject: [PATCH 3/3] Bump controller-tools to v0.9.0 This version supports CEL validation rules via Go markers. --- Makefile | 2 +- build/crd/crunchybridgeclusters/immutable.yaml | 11 ----------- .../crunchybridgeclusters/kustomization.yaml | 18 ------------------ build/crd/pgadmins/kustomization.yaml | 12 ------------ build/crd/pgupgrades/kustomization.yaml | 12 ------------ build/crd/postgresclusters/kustomization.yaml | 6 ------ build/crd/postgresclusters/status.yaml | 6 ------ ....crunchydata.com_crunchybridgeclusters.yaml | 2 +- ...gres-operator.crunchydata.com_pgadmins.yaml | 2 +- ...es-operator.crunchydata.com_pgupgrades.yaml | 2 +- ...rator.crunchydata.com_postgresclusters.yaml | 2 +- .../v1beta1/crunchy_bridgecluster_types.go | 2 ++ 12 files changed, 7 insertions(+), 70 deletions(-) delete mode 100644 build/crd/crunchybridgeclusters/immutable.yaml delete mode 100644 build/crd/postgresclusters/status.yaml diff --git a/Makefile b/Makefile index 5b8a097a77..fccd332bc4 100644 --- a/Makefile +++ b/Makefile @@ -324,7 +324,7 @@ endef CONTROLLER ?= hack/tools/controller-gen tools: tools/controller-gen tools/controller-gen: - $(call go-get-tool,$(CONTROLLER),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0) + $(call go-get-tool,$(CONTROLLER),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.0) ENVTEST ?= hack/tools/setup-envtest tools: tools/setup-envtest diff --git a/build/crd/crunchybridgeclusters/immutable.yaml b/build/crd/crunchybridgeclusters/immutable.yaml deleted file mode 100644 index 588d051e5d..0000000000 --- a/build/crd/crunchybridgeclusters/immutable.yaml +++ /dev/null @@ -1,11 +0,0 @@ -- op: add - path: /work - value: [{ message: 'immutable', rule: 'self == oldSelf'}] -- op: copy - from: /work - path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/provider/x-kubernetes-validations -- op: copy - from: /work - path: /spec/versions/0/schema/openAPIV3Schema/properties/spec/properties/region/x-kubernetes-validations -- op: remove - path: /work diff --git a/build/crd/crunchybridgeclusters/kustomization.yaml b/build/crd/crunchybridgeclusters/kustomization.yaml index 33e74bdef3..26454f3b07 100644 --- a/build/crd/crunchybridgeclusters/kustomization.yaml +++ b/build/crd/crunchybridgeclusters/kustomization.yaml @@ -5,18 +5,6 @@ resources: - generated/postgres-operator.crunchydata.com_crunchybridgeclusters.yaml patches: -# Remove the zero status field included by controller-gen@v0.8.0. These zero -# values conflict with the CRD controller in Kubernetes before v1.22. -# - https://github.com/kubernetes-sigs/controller-tools/pull/630 -# - https://pr.k8s.io/100970 -- target: - group: apiextensions.k8s.io - version: v1 - kind: CustomResourceDefinition - name: crunchybridgeclusters.postgres-operator.crunchydata.com - patch: |- - - op: remove - path: /status - target: group: apiextensions.k8s.io version: v1 @@ -29,9 +17,3 @@ patches: value: app.kubernetes.io/name: pgo app.kubernetes.io/version: latest -- target: - group: apiextensions.k8s.io - version: v1 - kind: CustomResourceDefinition - name: crunchybridgeclusters.postgres-operator.crunchydata.com - path: immutable.yaml diff --git a/build/crd/pgadmins/kustomization.yaml b/build/crd/pgadmins/kustomization.yaml index 78888103ef..ca67fb89fa 100644 --- a/build/crd/pgadmins/kustomization.yaml +++ b/build/crd/pgadmins/kustomization.yaml @@ -5,18 +5,6 @@ resources: - generated/postgres-operator.crunchydata.com_pgadmins.yaml patches: -# Remove the zero status field included by controller-gen@v0.8.0. These zero -# values conflict with the CRD controller in Kubernetes before v1.22. -# - https://github.com/kubernetes-sigs/controller-tools/pull/630 -# - https://pr.k8s.io/100970 -- target: - group: apiextensions.k8s.io - version: v1 - kind: CustomResourceDefinition - name: pgadmins.postgres-operator.crunchydata.com - patch: |- - - op: remove - path: /status - target: group: apiextensions.k8s.io version: v1 diff --git a/build/crd/pgupgrades/kustomization.yaml b/build/crd/pgupgrades/kustomization.yaml index 67bca8fca8..260b7e42cd 100644 --- a/build/crd/pgupgrades/kustomization.yaml +++ b/build/crd/pgupgrades/kustomization.yaml @@ -5,18 +5,6 @@ resources: - generated/postgres-operator.crunchydata.com_pgupgrades.yaml patches: -# Remove the zero status field included by controller-gen@v0.8.0. These zero -# values conflict with the CRD controller in Kubernetes before v1.22. -# - https://github.com/kubernetes-sigs/controller-tools/pull/630 -# - https://pr.k8s.io/100970 -- target: - group: apiextensions.k8s.io - version: v1 - kind: CustomResourceDefinition - name: pgupgrades.postgres-operator.crunchydata.com - patch: |- - - op: remove - path: /status - target: group: apiextensions.k8s.io version: v1 diff --git a/build/crd/postgresclusters/kustomization.yaml b/build/crd/postgresclusters/kustomization.yaml index 4e790295c4..eb8cb6540f 100644 --- a/build/crd/postgresclusters/kustomization.yaml +++ b/build/crd/postgresclusters/kustomization.yaml @@ -11,12 +11,6 @@ patchesJson6902: kind: CustomResourceDefinition name: postgresclusters.postgres-operator.crunchydata.com path: condition.yaml -- target: - group: apiextensions.k8s.io - version: v1 - kind: CustomResourceDefinition - name: postgresclusters.postgres-operator.crunchydata.com - path: status.yaml - target: group: apiextensions.k8s.io version: v1 diff --git a/build/crd/postgresclusters/status.yaml b/build/crd/postgresclusters/status.yaml deleted file mode 100644 index eacd47582f..0000000000 --- a/build/crd/postgresclusters/status.yaml +++ /dev/null @@ -1,6 +0,0 @@ -# Remove the zero status field included by controller-gen@v0.8.0. These zero -# values conflict with the CRD controller in Kubernetes before v1.22. -# - https://github.com/kubernetes-sigs/controller-tools/pull/630 -# - https://pr.k8s.io/100970 -- op: remove - path: /status diff --git a/config/crd/bases/postgres-operator.crunchydata.com_crunchybridgeclusters.yaml b/config/crd/bases/postgres-operator.crunchydata.com_crunchybridgeclusters.yaml index 8cc44b0881..e0bff0cc56 100644 --- a/config/crd/bases/postgres-operator.crunchydata.com_crunchybridgeclusters.yaml +++ b/config/crd/bases/postgres-operator.crunchydata.com_crunchybridgeclusters.yaml @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.8.0 + controller-gen.kubebuilder.io/version: v0.9.0 creationTimestamp: null labels: app.kubernetes.io/name: pgo diff --git a/config/crd/bases/postgres-operator.crunchydata.com_pgadmins.yaml b/config/crd/bases/postgres-operator.crunchydata.com_pgadmins.yaml index f0dae5f9c3..40a8330085 100644 --- a/config/crd/bases/postgres-operator.crunchydata.com_pgadmins.yaml +++ b/config/crd/bases/postgres-operator.crunchydata.com_pgadmins.yaml @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.8.0 + controller-gen.kubebuilder.io/version: v0.9.0 creationTimestamp: null labels: app.kubernetes.io/name: pgo diff --git a/config/crd/bases/postgres-operator.crunchydata.com_pgupgrades.yaml b/config/crd/bases/postgres-operator.crunchydata.com_pgupgrades.yaml index b35c209b37..08d1472582 100644 --- a/config/crd/bases/postgres-operator.crunchydata.com_pgupgrades.yaml +++ b/config/crd/bases/postgres-operator.crunchydata.com_pgupgrades.yaml @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.8.0 + controller-gen.kubebuilder.io/version: v0.9.0 creationTimestamp: null labels: app.kubernetes.io/name: pgo diff --git a/config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml b/config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml index 4b6a4f84a1..700b0e3173 100644 --- a/config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml +++ b/config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.8.0 + controller-gen.kubebuilder.io/version: v0.9.0 creationTimestamp: null labels: app.kubernetes.io/name: pgo diff --git a/pkg/apis/postgres-operator.crunchydata.com/v1beta1/crunchy_bridgecluster_types.go b/pkg/apis/postgres-operator.crunchydata.com/v1beta1/crunchy_bridgecluster_types.go index 0513a4fb6b..c72ca07471 100644 --- a/pkg/apis/postgres-operator.crunchydata.com/v1beta1/crunchy_bridgecluster_types.go +++ b/pkg/apis/postgres-operator.crunchydata.com/v1beta1/crunchy_bridgecluster_types.go @@ -64,10 +64,12 @@ type CrunchyBridgeClusterSpec struct { // Currently Bridge offers aws, azure, and gcp only // +kubebuilder:validation:Required // +kubebuilder:validation:Enum={aws,azure,gcp} + // +kubebuilder:validation:XValidation:rule=`self == oldSelf`,message="immutable" Provider string `json:"provider"` // The provider region where the cluster is located. // +kubebuilder:validation:Required + // +kubebuilder:validation:XValidation:rule=`self == oldSelf`,message="immutable" Region string `json:"region"` // Roles for which to create Secrets that contain their credentials which