forked from kubernetes-sigs/aws-ebs-csi-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-latest-sidecar-images
executable file
·97 lines (77 loc) · 3.3 KB
/
get-latest-sidecar-images
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
#!/bin/bash
# Copyright 2023 The Kubernetes 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.
# ---
# Script generates a file with the latest tags and associated manifest digests for each sidecar image at OUTPUT_FILEPATH
set -euo pipefail # Exit on any error
# --- Environment Variables
export SCRIPT_PATH ROOT_DIRECTORY IMAGE_DIGESTS_TEMPLATE_FILEPATH OUTPUT_FILEPATH
SCRIPT_PATH=$(dirname $(realpath "$0"))
ROOT_DIRECTORY="$SCRIPT_PATH/../.."
OUTPUT_FILEPATH=${OUTPUT_FILEPATH:="$ROOT_DIRECTORY/hack/release-scripts/image-digests.yaml"}
tmp_filename=$(mktemp)
# --- Script Tools
log() {
printf "%s [INFO] - %s\n" "$(date +"%Y-%m-%d %H:%M:%S")" "${*}" >&2
}
check_dependencies() {
local readonly dependencies=("yq" "git" "crane")
for cmd in "${dependencies[@]}"; do
if ! command -v "${cmd}" &>/dev/null; then
log "${cmd} could not be found, please install it."
exit 1
fi
done
}
error_handler() {
printf "Error occurred in script: %s, at line: %s. Command: %s. Error: %s\n" "$1" "$2" "$BASH_COMMAND" "$3" >&2
exit 1
}
trap 'error_handler ${LINENO} $? "$BASH_COMMAND"' ERR
# --- Script
trap 'rm $tmp_filename' EXIT
generate_image_digests_file() {
touch "$OUTPUT_FILEPATH"
yq '.sidecars.snapshotter.image = "public.ecr.aws/eks-distro/kubernetes-csi/external-snapshotter/csi-snapshotter"' -i "$OUTPUT_FILEPATH"
yq '.sidecars.attacher.image = "public.ecr.aws/eks-distro/kubernetes-csi/external-attacher"' -i "$OUTPUT_FILEPATH"
yq '.sidecars.provisioner.image = "public.ecr.aws/eks-distro/kubernetes-csi/external-provisioner"' -i "$OUTPUT_FILEPATH"
yq '.sidecars.resizer.image = "public.ecr.aws/eks-distro/kubernetes-csi/external-resizer"' -i "$OUTPUT_FILEPATH"
yq '.sidecars.livenessProbe.image = "public.ecr.aws/eks-distro/kubernetes-csi/livenessprobe"' -i "$OUTPUT_FILEPATH"
yq '.sidecars.nodeDriverRegistrar.image = "public.ecr.aws/eks-distro/kubernetes-csi/node-driver-registrar"' -i "$OUTPUT_FILEPATH"
yq '.sidecars.volumemodifier.image = "public.ecr.aws/ebs-csi-driver/volume-modifier-for-k8s"' -i "$OUTPUT_FILEPATH"
}
crane_get_latest_image_tag() {
image=$1
export TAG
TAG=$(crane ls "$image" | sed '/latest/d' | sort -V | tail -1) # Get tag for $image with latest semvar
}
update_sidecars_source_of_truth() {
yq '.sidecars | keys | .[]' "$OUTPUT_FILEPATH" >"$tmp_filename"
for sidecar in $(cat "$tmp_filename"); do
log "Updating $sidecar in $OUTPUT_FILEPATH"
image=$(yq ".sidecars.$sidecar.image" "$OUTPUT_FILEPATH")
export TAG
crane_get_latest_image_tag "$image"
yq ".sidecars.$sidecar.tag = env(TAG)" -i "$OUTPUT_FILEPATH"
export DIGEST
DIGEST=$(crane digest "$image:$TAG")
yq ".sidecars.$sidecar.manifestDigest = env(DIGEST)" -i "$OUTPUT_FILEPATH"
done
}
main() {
check_dependencies
generate_image_digests_file
update_sidecars_source_of_truth
}
main