|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2026 The Knative Authors |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# Adds the conversion webhook stanza that controller-gen does not emit for the |
| 18 | +# operator's single-version CRDs. The release operator.yaml consumes these bases |
| 19 | +# directly, so this must run before any chart or release manifest generation. |
| 20 | + |
| 21 | +set -o errexit |
| 22 | +set -o nounset |
| 23 | +set -o pipefail |
| 24 | + |
| 25 | +REPO_ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 26 | +CRD_BASES_DIR="${REPO_ROOT_DIR}/config/crd/bases" |
| 27 | + |
| 28 | +echo "Updating CRD conversion webhooks in ${CRD_BASES_DIR}" |
| 29 | + |
| 30 | +for crd_file in \ |
| 31 | + "${CRD_BASES_DIR}/operator.knative.dev_knativeeventings.yaml" \ |
| 32 | + "${CRD_BASES_DIR}/operator.knative.dev_knativeservings.yaml"; do |
| 33 | + if [[ ! -f "${crd_file}" ]]; then |
| 34 | + echo "ERROR: CRD file not found: ${crd_file}" >&2 |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | + |
| 38 | + echo " Updating $(basename "${crd_file}")" |
| 39 | + tmp="$(mktemp "${crd_file}.XXXXXX")" |
| 40 | + if ! awk ' |
| 41 | + function emit_conversion() { |
| 42 | + print " conversion:" |
| 43 | + print " strategy: Webhook" |
| 44 | + print " webhook:" |
| 45 | + print " conversionReviewVersions: [\"v1beta1\"]" |
| 46 | + print " clientConfig:" |
| 47 | + print " service:" |
| 48 | + print " name: operator-webhook" |
| 49 | + print " namespace: knative-operator" |
| 50 | + print " path: /resource-conversion" |
| 51 | + } |
| 52 | +
|
| 53 | + $0 == " conversion:" { |
| 54 | + emit_conversion() |
| 55 | + inserted = 1 |
| 56 | + skipping = 1 |
| 57 | + next |
| 58 | + } |
| 59 | +
|
| 60 | + skipping && $0 == " versions:" { |
| 61 | + skipping = 0 |
| 62 | + print |
| 63 | + next |
| 64 | + } |
| 65 | +
|
| 66 | + skipping { |
| 67 | + next |
| 68 | + } |
| 69 | +
|
| 70 | + $0 == " versions:" && !inserted { |
| 71 | + emit_conversion() |
| 72 | + inserted = 1 |
| 73 | + print |
| 74 | + next |
| 75 | + } |
| 76 | +
|
| 77 | + { |
| 78 | + print |
| 79 | + } |
| 80 | +
|
| 81 | + END { |
| 82 | + if (!inserted) { |
| 83 | + print "ERROR: could not find CRD spec.versions anchor" > "/dev/stderr" |
| 84 | + exit 1 |
| 85 | + } |
| 86 | + } |
| 87 | + ' "${crd_file}" > "${tmp}"; then |
| 88 | + rm -f "${tmp}" |
| 89 | + exit 1 |
| 90 | + fi |
| 91 | + mv "${tmp}" "${crd_file}" |
| 92 | +done |
| 93 | + |
| 94 | +echo "Done. CRD conversion webhooks updated." |
0 commit comments