diff --git a/Makefile.core.mk b/Makefile.core.mk index 2b43d8801..fd4c3b243 100644 --- a/Makefile.core.mk +++ b/Makefile.core.mk @@ -442,6 +442,10 @@ CONTROLLER_TOOLS_VERSION ?= v0.15.0 OPM_VERSION ?= v1.45.0 GITLEAKS_VERSION ?= v8.18.4 +# GENERATE_RELATED_IMAGES defines whether `spec.relatedImages` is going to be generated or not +# To disable set flag to false +GENERATE_RELATED_IMAGES ?= true + .PHONY: helm $(HELM) helm: $(HELM) ## Download helm to bin directory. If wrong version is installed, it will be overwritten. $(HELM): $(LOCALBIN) @@ -483,6 +487,10 @@ $(GITLEAKS): $(LOCALBIN) bundle: gen helm operator-sdk ## Generate bundle manifests and metadata, then validate generated files. $(HELM) template chart chart $(HELM_TEMPL_DEF_FLAGS) --set image='$(IMAGE)' --set platform=openshift --set bundleGeneration=true | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS) +ifeq ($(GENERATE_RELATED_IMAGES), true) + @hack/patch-csv.sh bundle/manifests/$(OPERATOR_NAME).clusterserviceversion.yaml +endif + # update CSV's spec.customresourcedefinitions.owned field. ideally we could do this straight in ./bundle, but # sadly this is only possible if the file lives in a `bases` directory mkdir -p _tmp/bases @@ -499,6 +507,7 @@ bundle: gen helm operator-sdk ## Generate bundle manifests and metadata, then va git checkout "$$csvPath" || echo "failed to revert timestamp change. assuming we're in the middle of a merge"; \ fi \ fi + $(OPERATOR_SDK) bundle validate ./bundle .PHONY: bundle-build diff --git a/bundle/manifests/sailoperator.clusterserviceversion.yaml b/bundle/manifests/sailoperator.clusterserviceversion.yaml index 2776e3da8..1b93b9733 100644 --- a/bundle/manifests/sailoperator.clusterserviceversion.yaml +++ b/bundle/manifests/sailoperator.clusterserviceversion.yaml @@ -34,7 +34,7 @@ metadata: capabilities: Seamless Upgrades categories: OpenShift Optional, Integration & Delivery, Networking, Security containerImage: quay.io/maistra-dev/sail-operator:0.1-latest - createdAt: "2024-08-01T14:16:13Z" + createdAt: "2024-08-05T12:57:49Z" description: Experimental operator for installing Istio service mesh features.operators.openshift.io/cnf: "false" features.operators.openshift.io/cni: "true" @@ -524,6 +524,46 @@ spec: metadata: annotations: kubectl.kubernetes.io/default-container: manager + olm.relatedImage.latest.cni: gcr.io/istio-testing/install-cni:1.24-alpha.52c9097444fc8e7fe04be557ebffe55bd31120db + olm.relatedImage.latest.pilot: gcr.io/istio-testing/pilot:1.24-alpha.52c9097444fc8e7fe04be557ebffe55bd31120db + olm.relatedImage.latest.proxy: gcr.io/istio-testing/proxyv2:1.24-alpha.52c9097444fc8e7fe04be557ebffe55bd31120db + olm.relatedImage.latest.ztunnel: gcr.io/istio-testing/ztunnel:1.24-alpha.52c9097444fc8e7fe04be557ebffe55bd31120db + olm.relatedImage.v1_21_0.cni: docker.io/istio/install-cni:1.21.0 + olm.relatedImage.v1_21_0.pilot: docker.io/istio/pilot:1.21.0 + olm.relatedImage.v1_21_0.proxy: docker.io/istio/proxyv2:1.21.0 + olm.relatedImage.v1_21_0.ztunnel: docker.io/istio/ztunnel:1.21.0 + olm.relatedImage.v1_21_2.cni: docker.io/istio/install-cni:1.21.2 + olm.relatedImage.v1_21_2.pilot: docker.io/istio/pilot:1.21.2 + olm.relatedImage.v1_21_2.proxy: docker.io/istio/proxyv2:1.21.2 + olm.relatedImage.v1_21_2.ztunnel: docker.io/istio/ztunnel:1.21.2 + olm.relatedImage.v1_21_3.cni: docker.io/istio/install-cni:1.21.3 + olm.relatedImage.v1_21_3.pilot: docker.io/istio/pilot:1.21.3 + olm.relatedImage.v1_21_3.proxy: docker.io/istio/proxyv2:1.21.3 + olm.relatedImage.v1_21_3.ztunnel: docker.io/istio/ztunnel:1.21.3 + olm.relatedImage.v1_21_4.cni: docker.io/istio/install-cni:1.21.4 + olm.relatedImage.v1_21_4.pilot: docker.io/istio/pilot:1.21.4 + olm.relatedImage.v1_21_4.proxy: docker.io/istio/proxyv2:1.21.4 + olm.relatedImage.v1_21_4.ztunnel: docker.io/istio/ztunnel:1.21.4 + olm.relatedImage.v1_21_5.cni: docker.io/istio/install-cni:1.21.5 + olm.relatedImage.v1_21_5.pilot: docker.io/istio/pilot:1.21.5 + olm.relatedImage.v1_21_5.proxy: docker.io/istio/proxyv2:1.21.5 + olm.relatedImage.v1_21_5.ztunnel: docker.io/istio/ztunnel:1.21.5 + olm.relatedImage.v1_22_0.cni: docker.io/istio/install-cni:1.22.0 + olm.relatedImage.v1_22_0.pilot: docker.io/istio/pilot:1.22.0 + olm.relatedImage.v1_22_0.proxy: docker.io/istio/proxyv2:1.22.0 + olm.relatedImage.v1_22_0.ztunnel: docker.io/istio/ztunnel:1.22.0 + olm.relatedImage.v1_22_1.cni: docker.io/istio/install-cni:1.22.1 + olm.relatedImage.v1_22_1.pilot: docker.io/istio/pilot:1.22.1 + olm.relatedImage.v1_22_1.proxy: docker.io/istio/proxyv2:1.22.1 + olm.relatedImage.v1_22_1.ztunnel: docker.io/istio/ztunnel:1.22.1 + olm.relatedImage.v1_22_2.cni: docker.io/istio/install-cni:1.22.2 + olm.relatedImage.v1_22_2.pilot: docker.io/istio/pilot:1.22.2 + olm.relatedImage.v1_22_2.proxy: docker.io/istio/proxyv2:1.22.2 + olm.relatedImage.v1_22_2.ztunnel: docker.io/istio/ztunnel:1.22.2 + olm.relatedImage.v1_22_3.cni: docker.io/istio/install-cni:1.22.3 + olm.relatedImage.v1_22_3.pilot: docker.io/istio/pilot:1.22.3 + olm.relatedImage.v1_22_3.proxy: docker.io/istio/proxyv2:1.22.3 + olm.relatedImage.v1_22_3.ztunnel: docker.io/istio/ztunnel:1.22.3 labels: app.kubernetes.io/created-by: sailoperator app.kubernetes.io/part-of: sailoperator @@ -675,4 +715,85 @@ spec: maturity: alpha provider: name: Red Hat, Inc. + relatedImages: + - image: gcr.io/istio-testing/install-cni:1.24-alpha.52c9097444fc8e7fe04be557ebffe55bd31120db + name: latest.cni + - image: gcr.io/istio-testing/pilot:1.24-alpha.52c9097444fc8e7fe04be557ebffe55bd31120db + name: latest.pilot + - image: gcr.io/istio-testing/proxyv2:1.24-alpha.52c9097444fc8e7fe04be557ebffe55bd31120db + name: latest.proxy + - image: gcr.io/istio-testing/ztunnel:1.24-alpha.52c9097444fc8e7fe04be557ebffe55bd31120db + name: latest.ztunnel + - image: docker.io/istio/install-cni:1.21.0 + name: v1_21_0.cni + - image: docker.io/istio/pilot:1.21.0 + name: v1_21_0.pilot + - image: docker.io/istio/proxyv2:1.21.0 + name: v1_21_0.proxy + - image: docker.io/istio/ztunnel:1.21.0 + name: v1_21_0.ztunnel + - image: docker.io/istio/install-cni:1.21.2 + name: v1_21_2.cni + - image: docker.io/istio/pilot:1.21.2 + name: v1_21_2.pilot + - image: docker.io/istio/proxyv2:1.21.2 + name: v1_21_2.proxy + - image: docker.io/istio/ztunnel:1.21.2 + name: v1_21_2.ztunnel + - image: docker.io/istio/install-cni:1.21.3 + name: v1_21_3.cni + - image: docker.io/istio/pilot:1.21.3 + name: v1_21_3.pilot + - image: docker.io/istio/proxyv2:1.21.3 + name: v1_21_3.proxy + - image: docker.io/istio/ztunnel:1.21.3 + name: v1_21_3.ztunnel + - image: docker.io/istio/install-cni:1.21.4 + name: v1_21_4.cni + - image: docker.io/istio/pilot:1.21.4 + name: v1_21_4.pilot + - image: docker.io/istio/proxyv2:1.21.4 + name: v1_21_4.proxy + - image: docker.io/istio/ztunnel:1.21.4 + name: v1_21_4.ztunnel + - image: docker.io/istio/install-cni:1.21.5 + name: v1_21_5.cni + - image: docker.io/istio/pilot:1.21.5 + name: v1_21_5.pilot + - image: docker.io/istio/proxyv2:1.21.5 + name: v1_21_5.proxy + - image: docker.io/istio/ztunnel:1.21.5 + name: v1_21_5.ztunnel + - image: docker.io/istio/install-cni:1.22.0 + name: v1_22_0.cni + - image: docker.io/istio/pilot:1.22.0 + name: v1_22_0.pilot + - image: docker.io/istio/proxyv2:1.22.0 + name: v1_22_0.proxy + - image: docker.io/istio/ztunnel:1.22.0 + name: v1_22_0.ztunnel + - image: docker.io/istio/install-cni:1.22.1 + name: v1_22_1.cni + - image: docker.io/istio/pilot:1.22.1 + name: v1_22_1.pilot + - image: docker.io/istio/proxyv2:1.22.1 + name: v1_22_1.proxy + - image: docker.io/istio/ztunnel:1.22.1 + name: v1_22_1.ztunnel + - image: docker.io/istio/install-cni:1.22.2 + name: v1_22_2.cni + - image: docker.io/istio/pilot:1.22.2 + name: v1_22_2.pilot + - image: docker.io/istio/proxyv2:1.22.2 + name: v1_22_2.proxy + - image: docker.io/istio/ztunnel:1.22.2 + name: v1_22_2.ztunnel + - image: docker.io/istio/install-cni:1.22.3 + name: v1_22_3.cni + - image: docker.io/istio/pilot:1.22.3 + name: v1_22_3.pilot + - image: docker.io/istio/proxyv2:1.22.3 + name: v1_22_3.proxy + - image: docker.io/istio/ztunnel:1.22.3 + name: v1_22_3.ztunnel version: 0.1.0 diff --git a/hack/patch-csv.sh b/hack/patch-csv.sh new file mode 100755 index 000000000..4058e2070 --- /dev/null +++ b/hack/patch-csv.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +# Copyright Istio Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -euo pipefail + +VERSIONS_YAML_FILE=${VERSIONS_YAML_FILE:-"versions.yaml"} + +: "${YQ:=yq}" + +# Map containing all components +declare -A COMPONENTS=( + ["istiod"]="pilot" + ["proxy"]="proxy" + ["cni"]="cni" + ["ztunnel"]="ztunnel" +) + +function is_empty_or_null() { + if [ $# -ne 1 ]; then + echo "Usage: is_empty_or_null " + exit 1 + fi + field="${1}" + [ -z "${field}" ] || [ "${field}" = "null" ] +} + +function get_field() { + if [ $# -ne 3 ]; then + echo "Usage: get_field " + exit 1 + fi + + local version="${1}" + local field_name="${2}" + local component_name="${3}" + + component_dir="${component_name}" + if [ "${component_name}" = "proxy" ]; then + component_dir="istiod" + fi + + # Set if non null order .defaults. + # then .defaults.. + # then .defaults.global. + # finally .defaults.global.. + # Example: + # .defaults.hub == null + # .defaults.istiod.hub == "" + # .defaults.global.hub == "gcr.io/istio-testing" + # .defaults.global.istiod.hub == null + field="$(${YQ} ".defaults.${field_name}" resources/"${version}"/charts/"${component_dir}"/values.yaml)" + if is_empty_or_null "${field}"; then + field="$(${YQ} ".defaults.${COMPONENTS[$component_name]}.${field_name}" resources/"${version}"/charts/"${component_dir}"/values.yaml)" + if is_empty_or_null "${field}"; then + field="$(${YQ} ".defaults.global.${field_name}" resources/"${version}"/charts/"${component_dir}"/values.yaml)" + if is_empty_or_null "${field}"; then + field="$(${YQ} ".defaults.global.${COMPONENTS[$component_name]}.${field_name}" resources/"${version}"/charts/"${component_dir}"/values.yaml)" + fi + fi + fi + + echo "${field}" +} + +## MAIN +if [ $# -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi +clusterserviceversion_file_path="$1" + +versions="$( ${YQ} '.versions[].name' "${VERSIONS_YAML_FILE}" )" + +for version in ${versions}; do + version_underscore=${version//./_} + for component_name in "${!COMPONENTS[@]}"; do + name="${version_underscore}.${COMPONENTS[$component_name]}" + hub=$(get_field "${version}" "hub" "${component_name}") + image=$(get_field "${version}" "image" "${component_name}") + tag=$(get_field "${version}" "tag" "${component_name}") + + # Add .spec.install.spec.deployments[0].spec.template.metadata.annotations with olm.relatedImage + ${YQ} -i '.spec.install.spec.deployments[0].spec.template.metadata.annotations |= (. + {"olm.relatedImage.'"${name}"'": "'"${hub}"'/'"${image}"':'"${tag}"'"})' "${clusterserviceversion_file_path}" + + # Add .spec.relatedImages for every Istio components in all supported versions + # BUG: yq indents the arrays with 2 more spaces (cf. https://mikefarah.gitbook.io/yq/usage/output-format#indent) + ${YQ} -i ".spec.relatedImages |= (. + [ {\"name\": \"${name}\", \"image\": \"${hub}/${image}:${tag}\"} ] | unique | sort_by(.name))" "${clusterserviceversion_file_path}" + done +done \ No newline at end of file