Skip to content

Commit

Permalink
Add make target and scripts for upgrading sidecar dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSirenko committed Oct 19, 2023
1 parent b87eea0 commit 06a3360
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,11 @@ generate-kustomize: bin/helm

.PHONY: update-truth-sidecars
update-truth-sidecars: hack/release-scripts/image-source-of-truth.yaml hack/release-scripts/update-truth-sidecars
hack/release-scripts/update-truth-sidecars
./hack/release-scripts/update-truth-sidecars

.PHONY: generate-sidecar-tags
generate-sidecar-tags: hack/release-scripts/image-source-of-truth.yaml charts/aws-ebs-csi-driver/values.yaml deploy/kubernetes/overlays/stable/gcr/kustomization.yaml hack/release-scripts/generate-sidecar-tags
./hack/release-scripts/generate-sidecar-tags

.PHONY: update-sidecar-dependencies
update-sidecar-dependencies: update-truth-sidecars generate-sidecar-tags generate-kustomize
87 changes: 87 additions & 0 deletions hack/release-scripts/generate-sidecar-tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
# This script generates the sidecar image tags in `deploy/kubernetes/overlays/stable/gcr/kustomization.yaml`and
# `charts/aws-ebs-csi-driver/values.yaml` based off of the values in `hack/release-scripts/image-source-of-truth.yaml`

# --- Environment Variables
export ROOT_DIRECTORY TRUTH_FILEPATH HELM_VALUES_FILEPATH KUSTOMIZE_FILEPATH
ROOT_DIRECTORY=${ROOT_DIRECTORY:=$(git rev-parse --show-toplevel)}
TRUTH_FILEPATH=${TRUTH_FILEPATH:="$ROOT_DIRECTORY/hack/release-scripts/image-source-of-truth.yaml"}
HELM_VALUES_FILEPATH=${HELM_VALUES_FILEPATH:="$ROOT_DIRECTORY/charts/aws-ebs-csi-driver/values.yaml"}
KUSTOMIZE_FILEPATH=${KUSTOMIZE_FILEPATH:="$ROOT_DIRECTORY/deploy/kubernetes/overlays/stable/gcr/kustomization.yaml"}

tmp_filename="tmp_$RANDOM.txt"

# --- Script Tools
set -euo pipefail # Exit on any error

log() {
printf "%s [INFO] - %s\n" "$(date +"%Y-%m-%d %H:%M:%S")" "${*}" >&2
}

check_dependencies() {
local readonly dependencies=("yq" "git")

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

update_gcr_kustomize_sidecar_tag () {
sidecar_name=$1
line_above=$2

tag=$(yq ".sidecars.$sidecar_name.tag" "$TRUTH_FILEPATH" | awk -F- '{print $1}') # Cut off -eks-1... off of tag
log "Updating gcr kustomize $sidecar_name to $tag"
sed -i "" "\|$line_above|{n;s/.*/ newTag: $tag/;}" "$KUSTOMIZE_FILEPATH"
}

update_helm_chart_sidecar_tag () {
sidecar_name=$1

export TAG
TAG=$(yq ".sidecars.$sidecar_name.tag" "$TRUTH_FILEPATH")
log "Updating helm $sidecar_name sidecar to $TAG"
yq ".sidecars.$sidecar_name.image.tag = env(TAG)" -i "$HELM_VALUES_FILEPATH"
}

generate_gcr_kustomize () {
update_gcr_kustomize_sidecar_tag "provisioner" "newName: registry.k8s.io/sig-storage/csi-provisioner"
update_gcr_kustomize_sidecar_tag "attacher" "newName: registry.k8s.io/sig-storage/csi-attacher"
update_gcr_kustomize_sidecar_tag "livenessProbe" "newName: registry.k8s.io/sig-storage/livenessprobe"
update_gcr_kustomize_sidecar_tag "snapshotter" "newName: registry.k8s.io/sig-storage/csi-snapshotter"
update_gcr_kustomize_sidecar_tag "resizer" "newName: registry.k8s.io/sig-storage/csi-resizer"
update_gcr_kustomize_sidecar_tag "nodeDriverRegistrar" "newName: registry.k8s.io/sig-storage/csi-node-driver-registrar"

log "Success: All sidecar tags in $KUSTOMIZE_FILEPATH updated"
}

generate_helm_sidecars () {
yq '.sidecars | keys | .[]' "$TRUTH_FILEPATH" > $tmp_filename

for sidecar in $(cat $tmp_filename)
do
update_helm_chart_sidecar_tag "$sidecar"
done

log "Success: All sidecar tags in $HELM_VALUES_FILEPATH updated"
}

main () {
generate_gcr_kustomize
generate_helm_sidecars
}

main

0 comments on commit 06a3360

Please sign in to comment.