From 73df2332a3aca209f54e09255fb22592e29efacd Mon Sep 17 00:00:00 2001 From: Nicholas Baker Date: Fri, 16 Aug 2024 12:38:14 -0700 Subject: [PATCH] Remove empty string fallback on cached image list --- templates/al2/provisioners/install-worker.sh | 35 +++++++++++--------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/templates/al2/provisioners/install-worker.sh b/templates/al2/provisioners/install-worker.sh index 2d3802763..311289a7c 100644 --- a/templates/al2/provisioners/install-worker.sh +++ b/templates/al2/provisioners/install-worker.sh @@ -446,6 +446,7 @@ if [[ "$CACHE_CONTAINER_IMAGES" == "true" ]] && ! [[ ${ISOLATED_REGIONS} =~ $BIN REGIONS=$(aws ec2 describe-regions --all-regions --output text --query 'Regions[].[RegionName]') for img in "${CACHE_IMGS[@]:-}"; do + if [ -z "${img}" ]; then continue; fi ## only kube-proxy-minimal is vended for K8s 1.24+ if [[ "${img}" == *"kube-proxy:"* ]] && [[ "${img}" != *"-minimal-"* ]] && vercmp "${K8S_MINOR_VERSION}" gteq "1.24"; then continue @@ -458,6 +459,7 @@ if [[ "$CACHE_CONTAINER_IMAGES" == "true" ]] && ! [[ ${ISOLATED_REGIONS} =~ $BIN ## iterate through decrementing the build version each time for build_version in $(seq "${eksbuild_version}" -1 1); do img=$(echo "${img}" | sed -E "s/eksbuild.[0-9]+/eksbuild.${build_version}/") + echo "Pulling image [${img}]" if /etc/eks/containerd/pull-image.sh "${img}"; then PULLED_IMGS+=("${img}") break @@ -469,21 +471,24 @@ if [[ "$CACHE_CONTAINER_IMAGES" == "true" ]] && ! [[ ${ISOLATED_REGIONS} =~ $BIN #### Tag the pulled down image for all other regions in the partition for region in ${REGIONS[*]}; do - for img in "${PULLED_IMGS[@]:-}"; do - region_uri=$(/etc/eks/get-ecr-uri.sh "${region}" "${AWS_DOMAIN}") - regional_img="${img/$ECR_URI/$region_uri}" - sudo ctr -n k8s.io image tag "${img}" "${regional_img}" || : - ## Tag ECR fips endpoint for supported regions - if [[ "${region}" =~ (us-east-1|us-east-2|us-west-1|us-west-2|us-gov-east-1|us-gov-west-1) ]]; then - regional_fips_img="${regional_img/.ecr./.ecr-fips.}" - sudo ctr -n k8s.io image tag "${img}" "${regional_fips_img}" || : - sudo ctr -n k8s.io image tag "${img}" "${regional_fips_img/-eksbuild.1/}" || : - fi - ## Cache the non-addon VPC CNI images since "v*.*.*-eksbuild.1" is equivalent to leaving off the eksbuild suffix - if [[ "${img}" == *"-cni"*"-eksbuild.1" ]]; then - sudo ctr -n k8s.io image tag "${img}" "${regional_img/-eksbuild.1/}" || : - fi - done + if [ "${#PULLED_IMGS[@]:-}" -gt 0 ]; then + for img in "${PULLED_IMGS[@]:-}"; do + if [ -z "${img}" ]; then continue; fi + region_uri=$(/etc/eks/get-ecr-uri.sh "${region}" "${AWS_DOMAIN}") + regional_img="${img/$ECR_URI/$region_uri}" + sudo ctr -n k8s.io image tag "${img}" "${regional_img}" || : + ## Tag ECR fips endpoint for supported regions + if [[ "${region}" =~ (us-east-1|us-east-2|us-west-1|us-west-2|us-gov-east-1|us-gov-west-1) ]]; then + regional_fips_img="${regional_img/.ecr./.ecr-fips.}" + sudo ctr -n k8s.io image tag "${img}" "${regional_fips_img}" || : + sudo ctr -n k8s.io image tag "${img}" "${regional_fips_img/-eksbuild.1/}" || : + fi + ## Cache the non-addon VPC CNI images since "v*.*.*-eksbuild.1" is equivalent to leaving off the eksbuild suffix + if [[ "${img}" == *"-cni"*"-eksbuild.1" ]]; then + sudo ctr -n k8s.io image tag "${img}" "${regional_img/-eksbuild.1/}" || : + fi + done + fi done fi