Skip to content

Commit

Permalink
Address #321: Finegrained repo location patching.
Browse files Browse the repository at this point in the history
So we copy the capi knowledge of whether kube-proxy is at the old location
(k8s.gcr.io) or at the new one (registry.k8s.io).
As the logic became somewhat involed, split it out into a separate
script that can be tested more easily.

Signed-off-by: Kurt Garloff <[email protected]>
  • Loading branch information
garloff committed Feb 1, 2023
1 parent 0f93a9e commit 57e9cad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 1 addition & 4 deletions terraform/files/bin/create_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ if test "$CONTROL_PLANE_MACHINE_COUNT" -gt 0 && grep '^ *OPENSTACK_ANTI_AFFINIT
fi

# Patch registry location for k8s >= 1.21
K8S_MAJMIN=$(grep '^KUBERNETES_VERSION:' $CCCFG | sed 's/^KUBERNETES_VERSION: v\([0-9]*\)\.\([0-9]*\).*$/\1\2/')
if test "$K8S_MAJMIN" -ge 121 && grep 'k8s\.gcr\.io' ${CLUSTERAPI_TEMPLATE} >/dev/null 2>&1; then
sed -i 's/k8s\.gcr\.io/registry.k8s.io/g' ${CLUSTERAPI_TEMPLATE}
fi
fixup_k8sregistry.sh "$CCCFG" "${CLUSTERAPI_TEMPLATE}"

cp -p "$CCCFG" $HOME/.cluster-api/clusterctl.yaml
KCCCFG="--config $CCCFG"
Expand Down
20 changes: 20 additions & 0 deletions terraform/files/bin/fixup_k8sregistry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# fixup_k8s_version.sh
# Patch $2 (cluster-template.yaml) with fixed up k8s imageRepo if needed
# This is to find old kube-proxy images on k8s.gcr.io and new ones on registry.k8s.io
# See https://github.com/kubernetes-sigs/cluster-api/blob/main/internal/util/kubeadm/kubeadm.go#L40
# (c) Kurt Garloff, Roman Hros, 02/2023
# SPDX-License-Identifier: Apache-2.0

if test -z "$2"; then echo "ERROR: Need clusterctl.yaml cluster-template args" 1>&2; exit 1; fi
K8SVER=$(grep '^KUBERNETES_VERSION:' "$1" | sed 's/^KUBERNETES_VERSION: v\([0-9.]*\)/\1/')
K8SMINOR=${K8SVER#*.}
K8SVER=${K8SVER%%.*}${K8SMINOR%%.*}$(printf %02i 0${K8SVER##*.})
echo $K8SVER
if grep 'k8s\.gcr\.io' "$2" >/dev/null 2>&1; then
if test "$K8SVER" -ge 12409 \
|| test "$K8SVER" -lt 12400 -a "$K8SVER" -ge 12315 \
|| test "$K8SVER" -lt 12300 -a "$K8SVER" -ge 12217; then
sed -i 's/k8s\.gcr\.io/registry.k8s.io/g' "$2"
fi
fi

0 comments on commit 57e9cad

Please sign in to comment.