Skip to content

Commit

Permalink
Merge pull request #289 from abays/olm_webhook_cleanup
Browse files Browse the repository at this point in the history
Automate OLM cleanup for running local operator w/ webhooks
  • Loading branch information
openshift-merge-bot[bot] authored Oct 16, 2024
2 parents 4fc474b + 4bdbb96 commit b9247e5
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 10 deletions.
15 changes: 5 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -359,16 +359,11 @@ operator-lint: gowork ## Runs operator-lint
go vet -vettool=$(LOCALBIN)/operator-lint ./... ./apis/...

# Used for webhook testing
# Please ensure the infra-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 validatingwebhookconfiguration/vmemcached.kb.io
# $oc delete mutatingwebhookconfiguration/mmemcached.kb.io
# $oc delete validatingwebhookconfiguration/vdnsmasq.kb.io
# $oc delete mutatingwebhookconfiguration/mdnsmasq.kb.io
# $oc delete validatingwebhookconfiguration/vredis.kb.io
# $oc delete mutatingwebhookconfiguration/mredis.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
Expand Down
2 changes: 2 additions & 0 deletions hack/clean_local_webhook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ oc delete validatingwebhookconfiguration/vreservation.kb.io --ignore-not-found
oc delete mutatingwebhookconfiguration/mreservation.kb.io --ignore-not-found
oc delete validatingwebhookconfiguration/vipset.kb.io --ignore-not-found
oc delete mutatingwebhookconfiguration/mipset.kb.io --ignore-not-found
oc delete validatingwebhookconfiguration/vinstanceha.kb.io --ignore-not-found
oc delete mutatingwebhookconfiguration/minstanceha.kb.io --ignore-not-found
64 changes: 64 additions & 0 deletions hack/configure_local_webhook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,70 @@ webhooks:
scope: '*'
sideEffects: None
timeoutSeconds: 10
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
name: vinstanceha.kb.io
webhooks:
- admissionReviewVersions:
- v1
clientConfig:
caBundle: ${CA_BUNDLE}
url: https://${CRC_IP}:9443/validate-instanceha-openstack-org-v1beta1-instanceha
failurePolicy: Fail
matchPolicy: Equivalent
name: vinstanceha.kb.io
objectSelector: {}
rules:
- apiGroups:
- instanceha.openstack.org
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- instancehas
scope: '*'
sideEffects: None
timeoutSeconds: 10
---
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: minstanceha.kb.io
webhooks:
- admissionReviewVersions:
- v1
clientConfig:
caBundle: ${CA_BUNDLE}
url: https://${CRC_IP}:9443/mutate-instanceha-openstack-org-v1beta1-instanceha
failurePolicy: Fail
matchPolicy: Equivalent
name: minstanceha.kb.io
objectSelector: {}
rules:
- apiGroups:
- instanceha.openstack.org
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- instancehas
scope: '*'
sideEffects: None
timeoutSeconds: 10
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/infra-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

0 comments on commit b9247e5

Please sign in to comment.