diff --git a/Makefile b/Makefile index ed97e50..51759f5 100644 --- a/Makefile +++ b/Makefile @@ -371,3 +371,17 @@ tidy: ## Run go mod tidy on every mod file in the repo operator-lint: gowork ## Runs operator-lint GOBIN=$(LOCALBIN) go install github.com/gibizer/operator-lint@v0.1.0 go vet -vettool=$(LOCALBIN)/operator-lint ./... ./api/... + +# Used for webhook testing +# 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 +run-with-webhook: export HEALTH_PORT?=8081 +run-with-webhook: manifests generate fmt vet ## Run a controller from your host. + /bin/bash hack/configure_local_webhook.sh + OPERATOR_TEMPLATES=./templates go run ./main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)" diff --git a/hack/clean_local_webhook.sh b/hack/clean_local_webhook.sh new file mode 100755 index 0000000..8888085 --- /dev/null +++ b/hack/clean_local_webhook.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -ex + +oc delete validatingwebhookconfiguration/vopenstackbaremetalset.kb.io --ignore-not-found +oc delete validatingwebhookconfiguration/vopenstackprovisionserver.kb.io --ignore-not-found +oc delete mutatingwebhookconfiguration/mopenstackprovisionserver.kb.io --ignore-not-found diff --git a/hack/configure_local_webhook.sh b/hack/configure_local_webhook.sh new file mode 100755 index 0000000..2d6a6ab --- /dev/null +++ b/hack/configure_local_webhook.sh @@ -0,0 +1,126 @@ +#!/bin/bash +set -ex + +TMPDIR=${TMPDIR:-"/tmp/k8s-webhook-server/serving-certs"} +SKIP_CERT=${SKIP_CERT:-false} +CRC_IP=${CRC_IP:-$(/sbin/ip -o -4 addr list crc | awk '{print $4}' | cut -d/ -f1)} +FIREWALL_ZONE=${FIREWALL_ZONE:-"libvirt"} + +#Open 9443 +sudo firewall-cmd --zone=${FIREWALL_ZONE} --add-port=9443/tcp +sudo firewall-cmd --runtime-to-permanent + +# Generate the certs and the ca bundle +if [ "$SKIP_CERT" = false ] ; then + mkdir -p ${TMPDIR} + rm -rf ${TMPDIR}/* || true + + openssl req -newkey rsa:2048 -days 3650 -nodes -x509 \ + -subj "/CN=${HOSTNAME}" \ + -addext "subjectAltName = IP:${CRC_IP}" \ + -keyout ${TMPDIR}/tls.key \ + -out ${TMPDIR}/tls.crt + + cat ${TMPDIR}/tls.crt ${TMPDIR}/tls.key | base64 -w 0 > ${TMPDIR}/bundle.pem + +fi + +CA_BUNDLE=`cat ${TMPDIR}/bundle.pem` + +# Patch the webhook(s) +cat >> ${TMPDIR}/patch_webhook_configurations.yaml <