From de5bb357c5ebeb1d4b132f97cc6344bad9c66b74 Mon Sep 17 00:00:00 2001 From: Jont828 Date: Tue, 10 Oct 2023 21:41:51 -0400 Subject: [PATCH] Set ClusterctlMoveHierarchyLabel on HelmChartProxy CRD definition --- Makefile | 20 ++++++++++++++++--- config/crd/kustomization.yaml | 3 +++ ...terctl_move_label_in_helmchartproxies.yaml | 8 ++++++++ .../helmchartproxy_controller.go | 15 +++++--------- 4 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 config/crd/patches/clusterctl_move_label_in_helmchartproxies.yaml diff --git a/Makefile b/Makefile index 7c7d6c8e..e8862a6a 100644 --- a/Makefile +++ b/Makefile @@ -202,6 +202,12 @@ TAG ?= dev ARCH ?= $(shell go env GOARCH) ALL_ARCH = amd64 arm arm64 ppc64le s390x +# Allow overriding manifest generation destination directory +MANIFEST_ROOT ?= config +CRD_ROOT ?= $(MANIFEST_ROOT)/crd/bases +WEBHOOK_ROOT ?= $(MANIFEST_ROOT)/webhook +RBAC_ROOT ?= $(MANIFEST_ROOT)/rbac + # Allow overriding the imagePullPolicy PULL_POLICY ?= Always @@ -234,8 +240,17 @@ generate: ## Run all generate-* targets .PHONY: generate-manifests generate-manifests: $(CONTROLLER_GEN) $(KUSTOMIZE) ## Generate manifests e.g. CRD, RBAC etc. for core - # $(MAKE) clean-generated-yaml SRC_DIRS="./config/crd/bases" - $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases + $(CONTROLLER_GEN) \ + paths=./api/... \ + crd:crdVersions=v1 \ + rbac:roleName=manager-role \ + output:crd:dir=$(CRD_ROOT) \ + output:webhook:dir=$(WEBHOOK_ROOT) \ + webhook + $(CONTROLLER_GEN) \ + paths=./controllers/... \ + output:rbac:dir=$(RBAC_ROOT) \ + rbac:roleName=manager-role .PHONY: generate-go generate-go: $(CONTROLLER_GEN) $(MOCKGEN) $(KUSTOMIZE) ## Generate manifests e.g. CRD, RBAC etc. for core @@ -561,7 +576,6 @@ set-manifest-image: .PHONY: clean clean: ## Remove generated binaries, GitBook files, Helm charts, and Tilt build files $(MAKE) clean-bin - $(MAKE) clean-book $(MAKE) clean-charts $(MAKE) clean-tilt diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 67f1c82d..e4e8b123 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -19,6 +19,9 @@ patchesStrategicMerge: - patches/cainjection_in_helmreleaseproxies.yaml #+kubebuilder:scaffold:crdkustomizecainjectionpatch +# Adds clusterctl move hierarchy label to HelmChartProxies so they can be discovered by clusterctl move. +- patches/clusterctl_move_label_in_helmchartproxies.yaml + # the following config is for teaching kustomize how to do kustomization for CRDs. configurations: - kustomizeconfig.yaml diff --git a/config/crd/patches/clusterctl_move_label_in_helmchartproxies.yaml b/config/crd/patches/clusterctl_move_label_in_helmchartproxies.yaml new file mode 100644 index 00000000..0754059e --- /dev/null +++ b/config/crd/patches/clusterctl_move_label_in_helmchartproxies.yaml @@ -0,0 +1,8 @@ +# The following patch adds the `clusterctl.cluster.x-k8s.io/move-hierarchy` label to the HelmChartProxy CRD type. +# Note that this label will be present on the HelmChartProxy kind, not HelmChartProxy objects themselves. +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + labels: + clusterctl.cluster.x-k8s.io/move-hierarchy: "true" + name: helmchartproxies.addons.cluster.x-k8s.io diff --git a/controllers/helmchartproxy/helmchartproxy_controller.go b/controllers/helmchartproxy/helmchartproxy_controller.go index 441d3473..2f08f527 100644 --- a/controllers/helmchartproxy/helmchartproxy_controller.go +++ b/controllers/helmchartproxy/helmchartproxy_controller.go @@ -23,23 +23,18 @@ import ( apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" + addonsv1alpha1 "sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + "sigs.k8s.io/cluster-api/util/conditions" + "sigs.k8s.io/cluster-api/util/patch" + "sigs.k8s.io/cluster-api/util/predicates" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/source" - - addonsv1alpha1 "sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1" - - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/util/conditions" - "sigs.k8s.io/cluster-api/util/patch" - "sigs.k8s.io/cluster-api/util/predicates" - // "sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster" - // "sigs.k8s.io/cluster-api/cmd/clusterctl/client/config" ) // HelmChartProxyReconciler reconciles a HelmChartProxy object