From 666ed4f8429a3747fe2b110bfbf931b888fbfa03 Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Sat, 12 Oct 2024 22:41:27 +0200 Subject: [PATCH] scripts: add ignore-not-found for undeploy and uninstall to Makefile boiler plate This avoid failure of any of these two commands if for some reason one or more of the kustomized resource is missing. Part of 5195 Signed-off-by: Samuel Gaist --- ...sources-when-uninstalling-undeploying.yaml | 38 +++++++++++++++++++ .../scaffolds/internal/templates/makefile.go | 8 +++- testdata/helm/memcached-operator/Makefile | 8 +++- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 changelog/fragments/01-handle-missing-resources-when-uninstalling-undeploying.yaml diff --git a/changelog/fragments/01-handle-missing-resources-when-uninstalling-undeploying.yaml b/changelog/fragments/01-handle-missing-resources-when-uninstalling-undeploying.yaml new file mode 100644 index 00000000000..749f657e67a --- /dev/null +++ b/changelog/fragments/01-handle-missing-resources-when-uninstalling-undeploying.yaml @@ -0,0 +1,38 @@ +# entries is a list of entries to include in +# release notes and/or the migration guide +entries: + - description: > + The make uninstall and undeploy command from the generated Makefile + now properly handle missing kustomized resources. + + # kind is one of: + # - addition + # - change + # - deprecation + # - removal + # - bugfix + kind: "bugfix" + + # Is this a breaking change? + breaking: false + + # NOTE: ONLY USE `pull_request_override` WHEN ADDING THIS + # FILE FOR A PREVIOUSLY MERGED PULL_REQUEST! + # + # The generator auto-detects the PR number from the commit + # message in which this file was originally added. + # + # What is the pull request number (without the "#")? + # pull_request_override: 0 + + + # Migration can be defined to automatically add a section to + # the migration guide. This is required for breaking changes. + # migration: + # header: Header text for the migration section + # body: | + # Body of the migration section. This should be formatted as markdown and can + # span multiple lines. + # + # Using the YAML string '|' operator means that newlines in this string will + # be honored and interpretted as newlines in the rendered markdown. diff --git a/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go b/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go index dccaf36a5a4..93a98c3cca2 100644 --- a/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go +++ b/internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go @@ -118,13 +118,17 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform ##@ Deployment +ifndef ignore-not-found + ignore-not-found = false +endif + .PHONY: install install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. $(KUSTOMIZE) build config/crd | kubectl apply -f - .PHONY: uninstall uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. - $(KUSTOMIZE) build config/crd | kubectl delete -f - + $(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f - .PHONY: deploy deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. @@ -133,7 +137,7 @@ deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/c .PHONY: undeploy undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. - $(KUSTOMIZE) build config/default | kubectl delete -f - + $(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f - OS := $(shell uname -s | tr '[:upper:]' '[:lower:]') ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/') diff --git a/testdata/helm/memcached-operator/Makefile b/testdata/helm/memcached-operator/Makefile index 654a8040bc1..c3c28ab01f0 100644 --- a/testdata/helm/memcached-operator/Makefile +++ b/testdata/helm/memcached-operator/Makefile @@ -103,13 +103,17 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform ##@ Deployment +ifndef ignore-not-found + ignore-not-found = false +endif + .PHONY: install install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. $(KUSTOMIZE) build config/crd | kubectl apply -f - .PHONY: uninstall uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. - $(KUSTOMIZE) build config/crd | kubectl delete -f - + $(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f - .PHONY: deploy deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. @@ -118,7 +122,7 @@ deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/c .PHONY: undeploy undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. - $(KUSTOMIZE) build config/default | kubectl delete -f - + $(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f - OS := $(shell uname -s | tr '[:upper:]' '[:lower:]') ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')