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

[Automate-Release-1] Add image-source-of-truth.yaml and update-truth-sidecars scripts #1791

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,7 @@ generate-kustomize: bin/helm
cd charts/aws-ebs-csi-driver && ../../bin/helm template kustomize . -s templates/serviceaccount-csi-node.yaml | sed -e "/namespace: /d" > ../../deploy/kubernetes/base/serviceaccount-csi-node.yaml
cd charts/aws-ebs-csi-driver && ../../bin/helm template kustomize . -s templates/role-leases.yaml | sed -e "/namespace: /d" > ../../deploy/kubernetes/base/role-leases.yaml
cd charts/aws-ebs-csi-driver && ../../bin/helm template kustomize . -s templates/rolebinding-leases.yaml | sed -e "/namespace: /d" > ../../deploy/kubernetes/base/rolebinding-leases.yaml

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Targets should not depend on the files they update, remove hack/release-scripts/image-source-of-truth.yaml

hack/release-scripts/update-truth-sidecars
42 changes: 42 additions & 0 deletions hack/release-scripts/image-source-of-truth.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file acts as the source of truth for the driver and sidecar image tags and digests used by the rest of the repository.
# It is to be updated through the use of scripts in `hack/release-scripts` or Makefile targets.
driver:
name: "aws-ebs-csi-driver"
version: "v1.24.0"
gcrStagingImage: "gcr.io/k8s-staging-provider-aws/aws-ebs-csi-driver"
manifestDigest: ""
gcrImage: "registry.k8s.io/provider-aws/aws-ebs-csi-driver"
ecrImage: "public.ecr.aws/ebs-csi-driver/aws-ebs-csi-driver"
sidecars: # sidecar names match upstream helm chart values.yaml
snapshotter:
image: "public.ecr.aws/eks-distro/kubernetes-csi/external-snapshotter/csi-snapshotter"
tag: ""
manifestDigest: ""
attacher:
image: "public.ecr.aws/eks-distro/kubernetes-csi/external-attacher"
tag: ""
manifestDigest: ""
provisioner:
image: "public.ecr.aws/eks-distro/kubernetes-csi/external-provisioner"
tag: ""
manifestDigest: ""
resizer:
image: "public.ecr.aws/eks-distro/kubernetes-csi/external-resizer"
tag: ""
manifestDigest: ""
livenessProbe:
image: "public.ecr.aws/eks-distro/kubernetes-csi/livenessprobe"
tag: ""
manifestDigest: ""
nodeDriverRegistrar:
image: "public.ecr.aws/eks-distro/kubernetes-csi/node-driver-registrar"
tag: ""
manifestDigest: ""
volumemodifier:
image: "public.ecr.aws/ebs-csi-driver/volume-modifier-for-k8s"
tag: ""
manifestDigest: ""
snapshotController:
image: "public.ecr.aws/eks-distro/kubernetes-csi/external-snapshotter/snapshot-controller"
tag: ""
manifestDigest: ""
68 changes: 68 additions & 0 deletions hack/release-scripts/update-truth-sidecars
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash
AndrewSirenko marked this conversation as resolved.
Show resolved Hide resolved
# This script updates the image-source-of-truth.yaml with the latest tags and associated manifest digests for each sidecar image.

# --- Environment Variables
export ROOT_DIRECTORY TRUTH_FILEPATH
ROOT_DIRECTORY=${ROOT_DIRECTORY:=$(git rev-parse --show-toplevel)}
TRUTH_FILEPATH=${TRUTH_FILEPATH:="$ROOT_DIRECTORY/hack/release-scripts/image-source-of-truth.yaml"}

tmp_filename="tmp_$RANDOM.txt"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use mktemp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like mktemp suffers from some Linux/MacOS incompatibilities. I think the current way of creating a temporary file is more readable for this non-mission-critical use-case compared to mktemp fix.

# --- 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" "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

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 | .[]' "$TRUTH_FILEPATH" > $tmp_filename

for sidecar in $(cat $tmp_filename)
do
log "Updating $sidecar in $TRUTH_FILEPATH"
image=$(yq ".sidecars.$sidecar.image" "$TRUTH_FILEPATH")

export TAG
crane_get_latest_image_tag "$image"
yq ".sidecars.$sidecar.tag = env(TAG)" -i "$TRUTH_FILEPATH"

export DIGEST
DIGEST=$(crane digest "$image:$TAG")
yq ".sidecars.$sidecar.manifestDigest = env(DIGEST)" -i "$TRUTH_FILEPATH"
done
}

main () {
check_dependencies
update_sidecars_source_of_truth
}

main