Skip to content

Commit

Permalink
Add relatedImages to ClusterServiceVersion (istio-ecosystem#243)
Browse files Browse the repository at this point in the history
* Add relatedImages to ClusterServiceVersion

Signed-off-by: bmangoen <bmangoen@redhat.com>

* Change patch-csv order for avoiding reformatting

Signed-off-by: bmangoen <bmangoen@redhat.com>

* Add possibility to not generate relatedImages

Signed-off-by: bmangoen <bmangoen@redhat.com>

---------

Signed-off-by: bmangoen <bmangoen@redhat.com>
Signed-off-by: Daniel Grimm <dgrimm@redhat.com>
  • Loading branch information
bmangoen authored and dgn committed Aug 13, 2024
1 parent bc562a6 commit 24adff8
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 30 deletions.
9 changes: 9 additions & 0 deletions Makefile.core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,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)
Expand Down Expand Up @@ -471,6 +475,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
Expand All @@ -487,6 +495,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
3 changes: 0 additions & 3 deletions api/v1alpha1/values_types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions bundle/manifests/operator.istio.io_istiorevisions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ spec:
format: int32
type: integer
type: object
autoscalingv2API:
description: |-
TODO: remove this?
No longer used.
type: boolean
caAddress:
description: The address of the CA for CSR.
type: string
Expand Down
5 changes: 0 additions & 5 deletions bundle/manifests/operator.istio.io_istios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,6 @@ spec:
format: int32
type: integer
type: object
autoscalingv2API:
description: |-
TODO: remove this?
No longer used.
type: boolean
caAddress:
description: The address of the CA for CSR.
type: string
Expand Down
99 changes: 98 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-13T10:05:44Z"
createdAt: "2024-08-13T10:08:59Z"
description: Experimental operator for installing Istio service mesh
features.operators.openshift.io/cnf: "false"
features.operators.openshift.io/cni: "true"
Expand Down Expand Up @@ -517,6 +517,38 @@ spec:
metadata:
annotations:
kubectl.kubernetes.io/default-container: manager
olm.relatedImage.latest.cni: gcr.io/istio-testing/install-cni:1.24-alpha.cc81ac1f8216ef57087e90fc4707fa2e7ab94980
olm.relatedImage.latest.pilot: gcr.io/istio-testing/pilot:1.24-alpha.cc81ac1f8216ef57087e90fc4707fa2e7ab94980
olm.relatedImage.latest.proxy: gcr.io/istio-testing/pilot:1.24-alpha.cc81ac1f8216ef57087e90fc4707fa2e7ab94980
olm.relatedImage.latest.ztunnel: gcr.io/istio-testing/ztunnel:1.24-alpha.cc81ac1f8216ef57087e90fc4707fa2e7ab94980
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_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_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 @@ -668,4 +700,69 @@ spec:
maturity: alpha
provider:
name: Red Hat, Inc.
relatedImages:
- image: gcr.io/istio-testing/install-cni:1.24-alpha.cc81ac1f8216ef57087e90fc4707fa2e7ab94980
name: latest.cni
- image: gcr.io/istio-testing/pilot:1.24-alpha.cc81ac1f8216ef57087e90fc4707fa2e7ab94980
name: latest.pilot
- image: gcr.io/istio-testing/pilot:1.24-alpha.cc81ac1f8216ef57087e90fc4707fa2e7ab94980
name: latest.proxy
- image: gcr.io/istio-testing/ztunnel:1.24-alpha.cc81ac1f8216ef57087e90fc4707fa2e7ab94980
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.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.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
5 changes: 0 additions & 5 deletions chart/crds/operator.istio.io_istiorevisions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ spec:
format: int32
type: integer
type: object
autoscalingv2API:
description: |-
TODO: remove this?
No longer used.
type: boolean
caAddress:
description: The address of the CA for CSR.
type: string
Expand Down
5 changes: 0 additions & 5 deletions chart/crds/operator.istio.io_istios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,6 @@ spec:
format: int32
type: integer
type: object
autoscalingv2API:
description: |-
TODO: remove this?
No longer used.
type: boolean
caAddress:
description: The address of the CA for CSR.
type: string
Expand Down
1 change: 0 additions & 1 deletion docs/api-reference/operator.istio.io.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ _Appears in:_
| `externalIstiod` _boolean_ | Controls whether one external istiod is enabled. | | |
| `configCluster` _boolean_ | Controls whether a remote cluster is the config cluster for an external istiod | | |
| `caName` _string_ | The name of the CA for workloads.<br />For example, when caName=GkeWorkloadCertificate, GKE workload certificates<br />will be used as the certificates for workloads.<br />The default value is "" and when caName="", the CA will be configured by other<br />mechanisms (e.g., environmental variable CA_PROVIDER). | | |
| `autoscalingv2API` _boolean_ | TODO: remove this?<br />No longer used. | | |
| `platform` _string_ | Platform in which Istio is deployed. Possible values are: "openshift" and "gcp"<br />An empty value means it is a vanilla Kubernetes distribution, therefore no special<br />treatment will be considered. | | |
| `ipFamilies` _string array_ | Defines which IP family to use for single stack or the order of IP families for dual-stack.<br />Valid list items are "IPv4", "IPv6".<br />More info: https://kubernetes.io/docs/concepts/services-networking/dual-stack/#services | | |
| `ipFamilyPolicy` _string_ | Controls whether Services are configured to use IPv4, IPv6, or both. Valid options<br />are PreferDualStack, RequireDualStack, and SingleStack.<br />More info: https://kubernetes.io/docs/concepts/services-networking/dual-stack/#services | | |
Expand Down
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

0 comments on commit 24adff8

Please sign in to comment.