|
1 | 1 | #!/bin/bash |
2 | 2 | set -ex |
3 | 3 |
|
| 4 | +# Define a cleanup function |
| 5 | +cleanup() { |
| 6 | + echo "Caught signal, cleaning up local webhooks..." |
| 7 | + ./hack/clean_local_webhook.sh |
| 8 | + exit 0 |
| 9 | +} |
| 10 | + |
| 11 | +# Set trap to catch SIGINT and SIGTERM |
| 12 | +trap cleanup SIGINT SIGTERM |
| 13 | + |
4 | 14 | TMPDIR=${TMPDIR:-"/tmp/k8s-webhook-server/serving-certs"} |
5 | 15 | SKIP_CERT=${SKIP_CERT:-false} |
6 | 16 | CRC_IP=${CRC_IP:-$(/sbin/ip -o -4 addr list crc | awk '{print $4}' | cut -d/ -f1)} |
@@ -367,3 +377,29 @@ webhooks: |
367 | 377 | EOF_CAT |
368 | 378 |
|
369 | 379 | oc apply -n openstack -f ${TMPDIR}/patch_webhook_configurations.yaml |
| 380 | + |
| 381 | +# Scale-down operator deployment replicas to zero and remove OLM webhooks |
| 382 | +CSV_NAME="$(oc get csv -n openstack-operators -l operators.coreos.com/openstack-operator.openstack-operators -o name)" |
| 383 | + |
| 384 | +if [ -n "${CSV_NAME}" ]; then |
| 385 | + CUR_REPLICAS=$(oc get -n openstack-operators "${CSV_NAME}" -o=jsonpath='{.spec.install.spec.deployments[0].spec.replicas}') |
| 386 | + CUR_WEBHOOK_DEFS=$(oc get -n openstack-operators "${CSV_NAME}" -o=jsonpath='{.spec.webhookdefinitions}') |
| 387 | + |
| 388 | + # Back-up CSV if it currently uses OLM defaults for deployment replicas or webhook definitions |
| 389 | + if [[ "${CUR_REPLICAS}" -gt 0 || ( -n "${CUR_WEBHOOK_DEFS}" && "${CUR_WEBHOOK_DEFS}" != "[]" ) ]]; then |
| 390 | + CSV_FILE=$(mktemp -t "$(echo "${CSV_NAME}" | cut -d "/" -f 2).XXXXXX" --suffix .json) |
| 391 | + oc get -n openstack-operators "${CSV_NAME}" -o json | \ |
| 392 | + jq -r 'del(.metadata.generation, .metadata.resourceVersion, .metadata.uid)' > "${CSV_FILE}" |
| 393 | + |
| 394 | + printf \ |
| 395 | + "\n\tNow patching operator CSV to remove its OLM deployment and associated webhooks. |
| 396 | + The original OLM version of the operator's CSV has been copied to %s. To restore it, use: |
| 397 | + oc patch -n openstack-operators %s --type=merge --patch-file=%s\n\n" "${CSV_FILE}" "${CSV_NAME}" "${CSV_FILE}" |
| 398 | + fi |
| 399 | + |
| 400 | + oc patch "${CSV_NAME}" -n openstack-operators --type=json -p="[{'op': 'replace', 'path': '/spec/install/spec/deployments/0/spec/replicas', 'value': 0}]" |
| 401 | + oc patch "${CSV_NAME}" -n openstack-operators --type=json -p="[{'op': 'replace', 'path': '/spec/webhookdefinitions', 'value': []}]" |
| 402 | +fi |
| 403 | + |
| 404 | +source hack/export_related_images.sh && \ |
| 405 | +go run ./main.go -metrics-bind-address ":${METRICS_PORT}" -health-probe-bind-address ":${HEALTH_PORT}" |
0 commit comments