From ae0632c1f04244a48ba80b314b30f49cd1318f18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Valais?= Date: Mon, 28 Mar 2022 15:40:46 +0200 Subject: [PATCH] make: add "make e2e-setup-kind-update-images" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .gitignore | 1 + make/cluster.sh | 46 ++++++++++++++----- .../kind/kind_cluster_node_versions.env | 22 --------- make/tools.mk | 4 ++ 4 files changed, 40 insertions(+), 33 deletions(-) delete mode 100644 make/config/kind/kind_cluster_node_versions.env diff --git a/.gitignore b/.gitignore index 26f97b110..1b4ea2f0a 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ _artifacts/ /vendor/ bin/ user.bazelrc +*.bak diff --git a/make/cluster.sh b/make/cluster.sh index d705b2d06..3cbc3cf9b 100755 --- a/make/cluster.sh +++ b/make/cluster.sh @@ -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 </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 diff --git a/make/config/kind/kind_cluster_node_versions.env b/make/config/kind/kind_cluster_node_versions.env deleted file mode 100644 index 91a58053f..000000000 --- a/make/config/kind/kind_cluster_node_versions.env +++ /dev/null @@ -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 \ No newline at end of file diff --git a/make/tools.mk b/make/tools.mk index 91e77c67f..7d406f6d5 100644 --- a/make/tools.mk +++ b/make/tools.mk @@ -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