@@ -62,6 +62,8 @@ CONTROLLER_GEN_PKG := sigs.k8s.io/controller-tools/cmd/controller-gen
6262IMG_PREFIX ?= controller
6363IMG_TAG ?= latest
6464
65+ ENABLE_METRICS ?= false
66+ ENABLE_TLS ?= false
6567
6668# Default value for ignore-not-found flag in undeploy target
6769ignore-not-found ?= true
@@ -208,10 +210,9 @@ docker-buildx-reporter: ## Build and push docker image for the reporter for cros
208210 - $(CONTAINER_TOOL ) buildx rm reporter-builder
209211
210212.PHONY : build-installer
211- build-installer : manifests generate $( KUSTOMIZE ) # # Generate a consolidated YAML with CRDs and deployment.
213+ build-installer : # # Generate a consolidated YAML with CRDs and deployment.
212214 mkdir -p dist
213- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG_PREFIX} :${IMG_TAG}
214- $(KUSTOMIZE ) build config/default > dist/install.yaml
215+ $(MAKE ) -s build-manifests-temp > dist/install.yaml
215216
216217# # --------------------------------------
217218# # Deployment
@@ -223,6 +224,32 @@ ifndef ignore-not-found
223224 ignore-not-found = false
224225endif
225226
227+ # Temporary directory for building manifests
228+ BUILD_DIR := $(ROOT_DIR ) /bin/build
229+
230+ # Internal target to build manifests in a temporary directory to keep the source config clean.
231+ # This prevents 'kustomize edit' from modifying your local git state.
232+ # Features (Metrics, TLS) are enabled by adding Kustomize Components to the temporary copy.
233+ # TODO: we can do better for prometheus metrics ports that are added by manager_prometheus_metrics.yaml
234+ .PHONY : build-manifests-temp
235+ build-manifests-temp : manifests $(KUSTOMIZE )
236+ @mkdir -p $(BUILD_DIR )
237+ @rm -rf $(BUILD_DIR ) /config
238+ @cp -r config $(BUILD_DIR ) /
239+ @cd $(BUILD_DIR ) /config/manager && $(KUSTOMIZE ) edit set image controller=${IMG_PREFIX} :${IMG_TAG}
240+ @if [ " $( ENABLE_METRICS) " = " true" ]; then \
241+ cd $(BUILD_DIR ) /config/default && $(KUSTOMIZE ) edit add component ../prometheus; \
242+ if [ " $( ENABLE_TLS) " = " true" ]; then \
243+ cd $(BUILD_DIR ) /config/default && $(KUSTOMIZE ) edit add component ../certmanager && \
244+ $(KUSTOMIZE ) edit add component ../prometheus/tls; \
245+ else \
246+ cd $(BUILD_DIR ) /config/prometheus && $(KUSTOMIZE ) edit add patch --path manager_prometheus_metrics.yaml --kind Deployment --name controller-manager; \
247+ fi ; \
248+ fi
249+ @$(KUSTOMIZE ) build $(BUILD_DIR ) /config/default
250+ @rm -rf $(BUILD_DIR ) /config
251+
252+
226253.PHONY : install
227254install : manifests $(KUSTOMIZE ) # # Install CRDs into the K8s cluster specified in ~/.kube/config.
228255 @out=" $$ ( $( KUSTOMIZE) build config/crd 2>/dev/null || true )" ; \
@@ -234,13 +261,17 @@ uninstall: manifests $(KUSTOMIZE) ## Uninstall CRDs from the K8s cluster specifi
234261 if [ -n " $$ out" ]; then echo " $$ out" | $( KUBECTL) delete --ignore-not-found=$( ignore-not-found) -f -; else echo " No CRDs to delete; skipping." ; fi
235262
236263.PHONY : deploy
237- deploy : manifests $(KUSTOMIZE ) # # Deploy controller to the K8s cluster specified in ~/.kube/config.
238- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG_PREFIX} :${IMG_TAG}
239- $(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
264+ deploy : # # Deploy controller to the K8s cluster. Use ENABLE_METRICS=true and ENABLE_TLS=true to enable features.
265+ $(MAKE ) -s build-manifests-temp | $(KUBECTL ) apply -f -
240266
241267.PHONY : undeploy
242- undeploy : $(KUSTOMIZE ) # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
243- $(KUSTOMIZE ) build config/default | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
268+ undeploy : # # Undeploy controller from the K8s cluster. Use ENABLE_METRICS=true and ENABLE_TLS=true if they were enabled during deploy.
269+ $(MAKE ) -s build-manifests-temp | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
270+
271+ .PHONY : debug-deploy
272+ debug-deploy : # # Build and save manifests to debug_manifests.yaml for inspection. Use ENABLE_METRICS=true and ENABLE_TLS=true to enable features.
273+ $(MAKE ) -s build-manifests-temp > debug_manifests.yaml
274+ @echo " Manifests generated in debug_manifests.yaml"
244275
245276# # --------------------------------------
246277# # Testing
@@ -345,7 +376,6 @@ docs-serve: ## Serve mdBook locally.
345376.PHONY : crd-ref-docs
346377crd-ref-docs :
347378 crd-ref-docs \
348- --source-path=${PWD} /api/v1alpha1/ \
349379 --config=crd-ref-docs.yaml \
350380 --renderer=markdown \
351381 --output-path=${PWD} /docs/book/src/reference/api-spec.md
0 commit comments