make: add "make e2e-setup-kind-update-images"

I think having a separate file for storing the various kind image
digest isn't necessary. From now on, make/cluster.sh is the "source of
truth" for everything related to kind. If you would like to see the
image that is going to be used for creating the kind cluster, you can
run:

  make/cluster.sh --show-image

To self-update the digests with the latest available digests, run:

  make/cluster.sh --update-images

Signed-off-by: Maël Valais <mael@vls.dev>
This commit is contained in:
Maël Valais 2022-03-28 15:40:46 +02:00
parent c4e6ebd1a8
commit ae0632c1f0
4 changed files with 40 additions and 33 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@ _artifacts/
/vendor/
bin/
user.bazelrc
*.bak

View File

@ -23,7 +23,6 @@ set -e
mode=kind
k8s_version=1.23
kind_image_repo=docker.io/kindest/node
kind_cluster_name=kind
help() {
@ -45,6 +44,8 @@ Flags:
--show-image
Show the image that will be used for the cluster and exit with 0. The
image will be of the form docker.io/kindest/node:1.23@sha256:498...81ac.
--update-images
Update the kind images to the latest version.
Environment variables:
${green}K8S_VERSION${end}
@ -53,7 +54,21 @@ EOF
exit
}
# The below image digests can be refreshed with the command:
# make/cluster.sh --update-images
images=$(
cat <<EOF
docker.io/kindest/node:v1.18.0@sha256:0e20578828edd939d25eb98496a685c76c98d54084932f76069f886ec315d694
docker.io/kindest/node:v1.19.0@sha256:3b0289b2d1bab2cb9108645a006939d2f447a10ad2bb21919c332d06b548bbc6
docker.io/kindest/node:v1.20.0@sha256:b40ecf8bcb188f6a0d0f5d406089c48588b75edc112c6f635d26be5de1c89040
docker.io/kindest/node:v1.21.1@sha256:f08bcc2d38416fa58b9857a1000dd69062b0c3024dcbd696373ea026abe38bbc
docker.io/kindest/node:v1.22.0@sha256:b8bda84bb3a190e6e028b1760d277454a72267a5454b57db34437c34a588d047
docker.io/kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac
EOF
)
show_image=
update_images=
while [ $# -ne 0 ]; do
case "$1" in
--*=*)
@ -75,7 +90,7 @@ while [ $# -ne 0 ]; do
eval "$var=$2"
shift
;;
--show-image)
--show-image | --update-images)
var=$1
var=${var/--/}
var=${var//-/_}
@ -97,16 +112,25 @@ if printenv K8S_VERSION >/dev/null && [ -n "$K8S_VERSION" ]; then
k8s_version="$K8S_VERSION"
fi
# NB: Kind cluster image digests are autogenerated by
# hack/update-kind-images.sh.
source "${here}/config/kind/kind_cluster_node_versions.env"
if [ -n "$update_images" ]; then
for img in $images; do
sha=$(crane digest "$(cut -d@ -f1 <<<"$img")")
if [ "$(cut -d@ -f2 <<<"$img")" != "$sha" ]; then
trace sed -i.bak "s|^$img$|$(cut -d@ -f1 <<<"$img")@$sha|" "$0"
else
printf "${green}${greencheck}Info${end}: $img already uses the latest digest\n" >&2
fi
done
exit 0
fi
case "$k8s_version" in
1.18*) image="${kind_image_repo}:v1.18.0@$KIND_IMAGE_SHA_K8S_118" ;;
1.19*) image="${kind_image_repo}:v1.19.0@$KIND_IMAGE_SHA_K8S_119" ;;
1.20*) image="${kind_image_repo}:v1.20.0@$KIND_IMAGE_SHA_K8S_120" ;;
1.21*) image="${kind_image_repo}:v1.21.0@$KIND_IMAGE_SHA_K8S_121" ;;
1.22*) image="${kind_image_repo}:v1.22.0@$KIND_IMAGE_SHA_K8S_122" ;;
1.23*) image="${kind_image_repo}:v1.23.0@$KIND_IMAGE_SHA_K8S_123" ;;
1.18*) image=$(grep -F 1.18 <<<"$images") ;;
1.19*) image=$(grep -F 1.19 <<<"$images") ;;
1.20*) image=$(grep -F 1.20 <<<"$images") ;;
1.21*) image=$(grep -F 1.21 <<<"$images") ;;
1.22*) image=$(grep -F 1.22 <<<"$images") ;;
1.23*) image=$(grep -F 1.23 <<<"$images") ;;
v*) printf "${red}${redcross}Error${end}: the Kubernetes version must be given without the leading 'v'\n" >&2 && exit 1 ;;
*) printf "${red}${redcross}Error${end}: unsupported Kubernetes version ${yel}${k8s_version}${end}\n" >&2 && exit 1 ;;
esac

View File

@ -1,22 +0,0 @@
# Copyright 2021 The cert-manager 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.
# generated by ./hack/latest-kind-images.sh
KIND_IMAGE_SHA_K8S_118=sha256:f4bcc97a0ad6e7abaf3f643d890add7efe6ee4ab90baeb374b4f41a4c95567eb
KIND_IMAGE_SHA_K8S_119=sha256:a70639454e97a4b733f9d9b67e12c01f6b0297449d5b9cbbef87473458e26dca
KIND_IMAGE_SHA_K8S_120=sha256:cbeaf907fc78ac97ce7b625e4bf0de16e3ea725daf6b04f930bd14c67c671ff9
KIND_IMAGE_SHA_K8S_121=sha256:0fda882e43d425622f045b492f8bd83c2e0b4984fc03e2e05ec101ca1a685fb7
KIND_IMAGE_SHA_K8S_122=sha256:f240c00ffb1d82a2a2225ca0f5c85d1c45aa2b97921327cb3f6da4eee7eae5c3
KIND_IMAGE_SHA_K8S_123=sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac

View File

@ -409,3 +409,7 @@ ifneq ($(MISSING),)
$(error Missing required tools: $(MISSING))
endif
endif
.PHONY: e2e-setup-kind-update-images
e2e-setup-kind-update-images: make/cluster.sh bin/tools/crane
make/cluster.sh --update-images