@@ -62,6 +62,10 @@ CONTROLLER_GEN_PKG := sigs.k8s.io/controller-tools/cmd/controller-gen
6262IMG_PREFIX ?= controller
6363IMG_TAG ?= latest
6464
65+ # ENABLE_METRICS: If set to true, includes Prometheus Service and ServiceMonitor resources.
66+ ENABLE_METRICS ?= false
67+ # ENABLE_TLS: If set to true (and ENABLE_METRICS is true), configures metrics to use HTTPS with CertManager.
68+ ENABLE_TLS ?= false
6569
6670# Default value for ignore-not-found flag in undeploy target
6771ignore-not-found ?= true
@@ -208,14 +212,13 @@ docker-buildx-reporter: ## Build and push docker image for the reporter for cros
208212 - $(CONTAINER_TOOL ) buildx rm reporter-builder
209213
210214.PHONY : build-installer
211- build-installer : manifests generate $( KUSTOMIZE ) # # Generate CRDs and deployment manifests for release.
215+ build-installer : build- manifests-temp # # Generate CRDs and deployment manifests for release.
212216 mkdir -p dist
213217 # Generate CRDs only
214218 $(KUSTOMIZE ) build config/crd > dist/crds.yaml
215219 @echo " Generated dist/crds.yaml"
216220 # Generate controller deployment without CRDs
217- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG_PREFIX} :${IMG_TAG}
218- $(KUSTOMIZE ) build config/default > dist/install.yaml
221+ cp $(BUILD_DIR ) /manifests.yaml dist/install.yaml
219222 @echo " Generated dist/install.yaml with image ${IMG_PREFIX} :${IMG_TAG} "
220223 @echo " NOTE: Install crds.yaml first, then install.yaml. Deployment runs on any available node by default."
221224
@@ -229,6 +232,32 @@ ifndef ignore-not-found
229232 ignore-not-found = false
230233endif
231234
235+ # Temporary directory for building manifests
236+ BUILD_DIR := $(ROOT_DIR ) /bin/build
237+
238+ # Internal target to build manifests in a temporary directory to keep the source config clean.
239+ # This prevents 'kustomize edit' from modifying your local git state.
240+ # Features (Metrics, TLS) are enabled by adding Kustomize Components to the temporary copy.
241+ # TODO: we can do better for prometheus metrics ports that are added by manager_prometheus_metrics.yaml
242+ .PHONY : build-manifests-temp
243+ build-manifests-temp : manifests $(KUSTOMIZE )
244+ @mkdir -p $(BUILD_DIR )
245+ @rm -rf $(BUILD_DIR ) /config
246+ @cp -r config $(BUILD_DIR ) /
247+ @cd $(BUILD_DIR ) /config/manager && $(KUSTOMIZE ) edit set image controller=${IMG_PREFIX} :${IMG_TAG}
248+ @if [ " $( ENABLE_METRICS) " = " true" ]; then \
249+ cd $(BUILD_DIR ) /config/default && $(KUSTOMIZE ) edit add component ../prometheus; \
250+ if [ " $( ENABLE_TLS) " = " true" ]; then \
251+ cd $(BUILD_DIR ) /config/default && $(KUSTOMIZE ) edit add component ../certmanager && \
252+ $(KUSTOMIZE ) edit add component ../prometheus/tls; \
253+ else \
254+ cd $(BUILD_DIR ) /config/prometheus && $(KUSTOMIZE ) edit add patch --path manager_prometheus_metrics.yaml --kind Deployment --name controller-manager; \
255+ fi ; \
256+ fi
257+ @$(KUSTOMIZE ) build $(BUILD_DIR ) /config/default > $(BUILD_DIR ) /manifests.yaml
258+ @rm -rf $(BUILD_DIR ) /config
259+
260+
232261.PHONY : install
233262install : manifests $(KUSTOMIZE ) # # Install CRDs into the K8s cluster specified in ~/.kube/config.
234263 @out=" $$ ( $( KUSTOMIZE) build config/crd 2>/dev/null || true )" ; \
@@ -240,13 +269,30 @@ uninstall: manifests $(KUSTOMIZE) ## Uninstall CRDs from the K8s cluster specifi
240269 if [ -n " $$ out" ]; then echo " $$ out" | $( KUBECTL) delete --ignore-not-found=$( ignore-not-found) -f -; else echo " No CRDs to delete; skipping." ; fi
241270
242271.PHONY : deploy
243- deploy : manifests $(KUSTOMIZE ) # # Deploy controller to the K8s cluster specified in ~/.kube/config.
244- cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG_PREFIX} :${IMG_TAG}
245- $(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
272+ deploy : build-manifests-temp # # Deploy controller to the K8s cluster. Use ENABLE_METRICS=true and ENABLE_TLS=true to enable features.
273+ $(KUBECTL ) apply -f $(BUILD_DIR ) /manifests.yaml
246274
247275.PHONY : undeploy
248- 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.
249- $(KUSTOMIZE ) build config/default | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
276+ undeploy : build-manifests-temp # # Undeploy controller from the K8s cluster. Use ENABLE_METRICS=true and ENABLE_TLS=true if they were enabled during deploy.
277+ $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f $(BUILD_DIR ) /manifests.yaml
278+
279+ .PHONY : deploy-with-metrics
280+ deploy-with-metrics : ENABLE_METRICS=true
281+ deploy-with-metrics : deploy # # Deploy with metrics enabled.
282+
283+ .PHONY : undeploy-with-metrics
284+ undeploy-with-metrics : ENABLE_METRICS=true
285+ undeploy-with-metrics : undeploy # # Undeploy with metrics enabled.
286+
287+ .PHONY : deploy-with-metrics-tls-enabled
288+ deploy-with-metrics-tls-enabled : ENABLE_TLS=true
289+ deploy-with-metrics-tls-enabled : ENABLE_METRICS=true
290+ deploy-with-metrics-tls-enabled : deploy # # Deploy with metrics and TLS enabled.
291+
292+ .PHONY : undeploy-with-metrics-tls-enabled
293+ undeploy-with-metrics-tls-enabled : ENABLE_TLS=true
294+ undeploy-with-metrics-tls-enabled : ENABLE_METRICS=true
295+ undeploy-with-metrics-tls-enabled : undeploy # # Undeploy with metrics and TLS enabled.
250296
251297# # --------------------------------------
252298# # Testing
0 commit comments