Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add relatedImages to ClusterServiceVersion #243

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile.core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,8 @@ $(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)

@hack/patch-csv.sh bundle/manifests/$(OPERATOR_NAME).clusterserviceversion.yaml

# 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
Expand All @@ -499,6 +501,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
Expand Down
123 changes: 122 additions & 1 deletion bundle/manifests/sailoperator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
102 changes: 102 additions & 0 deletions hack/patch-csv.sh
Original file line number Diff line number Diff line change
@@ -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 <field>"
exit 1
fi
field="${1}"
[ -z "${field}" ] || [ "${field}" = "null" ]
}

function get_field() {
if [ $# -ne 3 ]; then
echo "Usage: get_field <version> <field_name> <component_name>"
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.<field>
# then .defaults.<component>.<field>
# then .defaults.global.<field>
# finally .defaults.global.<component>.<field>
# 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 <clusterserviceversion_file_path>"
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