From 72d2d374a0749c76cd1ef70e1c5da4799e548bf1 Mon Sep 17 00:00:00 2001 From: Andrew Bays Date: Wed, 16 Oct 2024 15:25:44 +0000 Subject: [PATCH] Automate OLM cleanup for running local operator w/ webhooks --- Makefile | 11 +++++------ hack/configure_local_webhook.sh | 8 ++++++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index ce9a7b91..4e8f3b82 100644 --- a/Makefile +++ b/Makefile @@ -344,12 +344,11 @@ operator-lint: gowork ## Runs operator-lint go vet -vettool=$(LOCALBIN)/operator-lint ./... ./api/... # Used for webhook testing -# Please ensure the ironic-controller-manager deployment and -# webhook definitions are removed from the csv before running -# this. Also, cleanup the webhook configuration for local testing -# before deplying with olm again. -# $oc delete -n openstack validatingwebhookconfiguration/vironic.kb.io -# $oc delete -n openstack mutatingwebhookconfiguration/mironic.kb.io +# The configure_local_webhooks.sh script below will remove any OLM webhooks +# for the operator and also scale its deployment replicas down to 0 so that +# the operator can run locally. +# Make sure to cleanup the webhook configuration for local testing by running +# ./hack/clean_local_webhook.sh before deplying with OLM again. SKIP_CERT ?=false .PHONY: run-with-webhook run-with-webhook: export METRICS_PORT?=8080 diff --git a/hack/configure_local_webhook.sh b/hack/configure_local_webhook.sh index 2031c69b..661ec88b 100755 --- a/hack/configure_local_webhook.sh +++ b/hack/configure_local_webhook.sh @@ -87,3 +87,11 @@ webhooks: EOF_CAT oc apply -n openstack -f ${TMPDIR}/patch_webhook_configurations.yaml + +# Scale-down operator deployment replicas to zero and remove OLM webhooks +CSV_NAME="$(oc get csv -n openstack-operators -l operators.coreos.com/ironic-operator.openstack-operators -o name)" + +if [ -n "${CSV_NAME}" ]; then + oc patch "${CSV_NAME}" -n openstack-operators --type=json -p="[{'op': 'replace', 'path': '/spec/install/spec/deployments/0/spec/replicas', 'value': 0}]" + oc patch "${CSV_NAME}" -n openstack-operators --type=json -p="[{'op': 'replace', 'path': '/spec/webhookdefinitions', 'value': []}]" +fi