-
Notifications
You must be signed in to change notification settings - Fork 5
/
generate-configs.sh
executable file
·191 lines (166 loc) · 8.04 KB
/
generate-configs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
# Copyright 2017-2020 Authors of Cilium
# SPDX-License-Identifier: Apache-2.0
set -o errexit
set -o pipefail
set -o nounset
set -x
shopt -s expand_aliases
alias yq='docker run --rm -v "${PWD}":/workdir --user "$(id -u):$(id -g)" mikefarah/yq:4.27.3'
cilium_version="${2}"
root_dir="$(git rev-parse --show-toplevel)"
case "${cilium_version}" in
*-rc*)
operator_image="$(head -1 "${1}")"
;;
*)
operator_image="registry.connect.redhat.com/isovalent/cilium-olm:$(head -1 "${1}" | cut -d ':' -f 2)"
;;
esac
function get_image() {
local image="$1"
local tag="$2"
local manifest
local hash
manifest="$(docker manifest inspect "$image:$tag" -v)"
hash="$(echo "$manifest" | jq -r '.Descriptor.digest' 2>/dev/null || echo "$manifest" | jq -r '.[0].Descriptor.digest' 2> /dev/null || "")"
if [[ "$hash" ]]; then
echo "$image""@$hash"
else
docker pull "$image:$tag" > /dev/null
echo "$image""@$(docker inspect "$image:$tag" | jq -r '.[0].RepoDigests[0]' | cut -d'@' -f2)"
fi
}
cd "${root_dir}"
rm -rf "manifests/cilium.v${cilium_version}" "bundles/cilium.v${cilium_version}/manifests" "bundles/cilium.v${cilium_version}/metadata" "bundles/cilium.v${cilium_version}/tests"
values_file="operator/cilium.v${cilium_version}/cilium/values.yaml"
cilium_image="$(yq e '.image.repository' "$values_file")@$(yq e '.image.digest' "$values_file")"
hubble_relay_image="$(yq e '.hubble.relay.image.repository' "$values_file")@$(yq e '.hubble.relay.image.digest' "$values_file")"
cilium_operator_image="$(yq e '.operator.image.repository' "$values_file")-generic@$(yq e '.operator.image.genericDigest' "$values_file")"
preflight_image="$(yq e '.preflight.image.repository' "$values_file")@$(yq e '.preflight.image.digest' "$values_file")"
clustermesh_image="$(yq e '.clustermesh.apiserver.image.repository' "$values_file")@$(yq e '.clustermesh.apiserver.image.digest' "$values_file")"
# These images don't have their digests in the values file, we need to retrieve them
certgen_image="$(get_image "$(yq e '.certgen.image.repository' "$values_file")" "$(yq e '.certgen.image.tag' "$values_file")")"
hubble_ui_be_image="$(get_image "$(yq e '.hubble.ui.backend.image.repository' "$values_file")" "$(yq e '.hubble.ui.backend.image.tag' "$values_file")")"
hubble_ui_fe_image="$(get_image "$(yq e '.hubble.ui.frontend.image.repository' "$values_file")" "$(yq e '.hubble.ui.frontend.image.tag' "$values_file")")"
etcd_operator_image="$(get_image "$(yq e '.etcd.image.repository' "$values_file")" "$(yq e '.etcd.image.tag' "$values_file")")"
nodeinit_image="$(get_image "$(yq e '.nodeinit.image.repository' "$values_file")" "$(yq e '.nodeinit.image.tag' "$values_file")")"
# quay.io/coreos/etcd is not included in Cilium >= 1.15 Helm charts.
# Ref: https://github.com/cilium/cilium/blob/v1.15.1/install/kubernetes/cilium/values.yaml
cilium_minor_number=$(cut -d '.' -f 2 <<< "$cilium_version")
if [[ $cilium_minor_number -lt 15 ]]; then
clustermesh_etcd_image="$(get_image "$(yq e '.clustermesh.apiserver.etcd.image.repository' "$values_file")" "$(yq e '.clustermesh.apiserver.etcd.image.tag' "$values_file")")"
fi
cilium_major_minor="$(echo "${cilium_version}" | cut -d . -f -2)"
# to not make 1.13.0 as previous release cause failure
set +o pipefail
set +o errexit
#shellcheck disable=SC2003
previous_version="${cilium_major_minor}.$(expr "$(echo "${cilium_version}" | cut -d . -f 3)" - 1)"
#shellcheck disable=SC2003
previous_version="${cilium_major_minor}.$(expr "$(echo "${cilium_version}" | cut -d . -f 3)" - 1)"
set -o pipefail
set -o errexit
if [[ -d "bundles/cilium.v${previous_version}" ]]; then
previous_name="$(yq .metadata.name "bundles/cilium.v${previous_version}/manifests/cilium.clusterserviceversion.yaml")"
fi
generate_instaces_cue() {
cat << EOF
package operator
instances: [
{
output: "manifests/cilium.v${cilium_version}/cluster-network-06-cilium-%s.yaml"
parameters: {
replaces: "${previous_name:-nothing}"
image: "${operator_image}"
test: false
onlyCSV: false
ciliumVersion: "${cilium_version}"
ciliumMajorMinor: "${cilium_major_minor}"
configVersionSuffix: "${1:-}"
ciliumVersion: "${cilium_version}"
ciliumImage: "${cilium_image}"
hubbleRelayImage: "${hubble_relay_image}"
operatorImage: "${cilium_operator_image}"
preflightImage: "${preflight_image}"
clustermeshImage: "${clustermesh_image}"
certgenImage: "${certgen_image}"
hubbleUIBackendImage: "${hubble_ui_be_image}"
hubbleUIFrontendImage: "${hubble_ui_fe_image}"
etcdOperatorImage: "${etcd_operator_image}"
nodeInitImage: "${nodeinit_image}"
clustermeshEtcdImage: "${clustermesh_etcd_image:-nothing}"
}
},
{
output: "bundles/cilium.v${cilium_version}/manifests/cilium.clusterserviceversion.yaml"
parameters: {
replaces: "${previous_name:-nothing}"
namespace: "placeholder"
image: "${operator_image}"
test: false
onlyCSV: true
ciliumVersion: "${cilium_version}"
ciliumMajorMinor: "${cilium_major_minor}"
configVersionSuffix: "${1:-}"
ciliumImage: "${cilium_image}"
hubbleRelayImage: "${hubble_relay_image}"
operatorImage: "${cilium_operator_image}"
preflightImage: "${preflight_image}"
clustermeshImage: "${clustermesh_image}"
certgenImage: "${certgen_image}"
hubbleUIBackendImage: "${hubble_ui_be_image}"
hubbleUIFrontendImage: "${hubble_ui_fe_image}"
etcdOperatorImage: "${etcd_operator_image}"
nodeInitImage: "${nodeinit_image}"
clustermeshEtcdImage: "${clustermesh_etcd_image:-nothing}"
}
},
]
EOF
}
combined_hash_sources() {
generate_instaces_cue
cat "bundles/cilium.v${cilium_version}/Dockerfile"
cat "config/operator/operator.cue"
cat "config/operator/rbac.cue"
cat "config/operator/olm.cue"
}
config_version_suffix_hash="$(combined_hash_sources | git hash-object --stdin)"
generate_instaces_cue "${config_version_suffix_hash:0:7}" > config/operator/instances.cue
if [ -n "${GOPATH+x}" ] ; then
export PATH="${PATH}:${GOPATH}/bin"
fi
kuegen -input-directory ./config/operator -output-directory ./
cp ./config/crd/cilium.io_cilumconfigs.yaml "manifests/cilium.v${cilium_version}/cluster-network-03-cilium-ciliumconfigs-crd.yaml"
cilium_minor_version=$(cut -d '.' -f 1,2 <<< "$cilium_version")
ciliumconfig="ciliumconfig.v${cilium_minor_version}.yaml"
if [ ! -f "${ciliumconfig}" ]
then
echo "ERROR: You need to create ${ciliumconfig} first"
exit 1
fi
cp "${ciliumconfig}" "manifests/cilium.v${cilium_version}/cluster-network-07-cilium-ciliumconfig.yaml"
cp ./config/crd/cilium.io_cilumconfigs.yaml "bundles/cilium.v${cilium_version}/manifests/cilium.operator.cilium.io.crd.yaml"
mkdir -p "bundles/cilium.v${cilium_version}/metadata"
cat > "bundles/cilium.v${cilium_version}/metadata/annotations.yaml" << EOF
annotations:
operators.operatorframework.io.bundle.channel.default.v1: "${cilium_major_minor}"
operators.operatorframework.io.bundle.channels.v1: "${cilium_major_minor}"
operators.operatorframework.io.bundle.manifests.v1: manifests/
operators.operatorframework.io.bundle.mediatype.v1: registry+v1
operators.operatorframework.io.bundle.metadata.v1: metadata/
operators.operatorframework.io.bundle.package.v1: cilium
operators.operatorframework.io.metrics.builder: operator-sdk-v1.0.1
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
operators.operatorframework.io.metrics.project_layout: helm.sdk.operatorframework.io/v1
com.redhat.openshift.versions: "v4.9"
EOF
# We use yq to modify bundle and manifest files as a part of the release process.
# It produces large diffs because these yaml files are indented differently than
# how yq indents them. Run bundle and manifest yaml files through yq here so that
# using yq later on these files doesn't produce unnecessary diffs.
#
# Ref: https://github.com/mikefarah/yq/issues/825
find "bundles/cilium.v${cilium_version}" -name "*.yaml" | while read -r file; do yq e -i "$file"; done
find "manifests/cilium.v${cilium_version}" -name "*.yaml" | while read -r file; do yq e -i "$file"; done