You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.8 KiB

  1. #!/bin/bash
  2. set -eo pipefail
  3. CURRENT_DIR=$(cd $(dirname $0); pwd)
  4. TEMP_DIR="${CURRENT_DIR}/temp"
  5. REPO_ROOT_DIR="${CURRENT_DIR%/contrib/offline}"
  6. : ${IMAGE_ARCH:="amd64"}
  7. : ${ANSIBLE_SYSTEM:="linux"}
  8. : ${ANSIBLE_ARCHITECTURE:="x86_64"}
  9. : ${DOWNLOAD_YML:="roles/download/defaults/main.yml"}
  10. : ${KUBE_VERSION_YAML:="roles/kubespray-defaults/defaults/main.yaml"}
  11. mkdir -p ${TEMP_DIR}
  12. # ARCH used in convert {%- if image_arch != 'amd64' -%}-{{ image_arch }}{%- endif -%} to {{arch}}
  13. if [ "${IMAGE_ARCH}" != "amd64" ]; then ARCH="${IMAGE_ARCH}"; fi
  14. cat > ${TEMP_DIR}/generate.sh << EOF
  15. arch=${ARCH}
  16. image_arch=${IMAGE_ARCH}
  17. ansible_system=${ANSIBLE_SYSTEM}
  18. ansible_architecture=${ANSIBLE_ARCHITECTURE}
  19. EOF
  20. # generate all component version by $DOWNLOAD_YML
  21. grep 'kube_version:' ${REPO_ROOT_DIR}/${KUBE_VERSION_YAML} \
  22. | sed 's/: /=/g' >> ${TEMP_DIR}/generate.sh
  23. grep '_version:' ${REPO_ROOT_DIR}/${DOWNLOAD_YML} \
  24. | sed 's/: /=/g;s/{{/${/g;s/}}/}/g' | tr -d ' ' >> ${TEMP_DIR}/generate.sh
  25. sed -i 's/kube_major_version=.*/kube_major_version=${kube_version%.*}/g' ${TEMP_DIR}/generate.sh
  26. sed -i 's/crictl_version=.*/crictl_version=${kube_version%.*}.0/g' ${TEMP_DIR}/generate.sh
  27. # generate all download files url
  28. grep 'download_url:' ${REPO_ROOT_DIR}/${DOWNLOAD_YML} \
  29. | sed 's/: /=/g;s/ //g;s/{{/${/g;s/}}/}/g;s/|lower//g;s/^.*_url=/echo /g' >> ${TEMP_DIR}/generate.sh
  30. # generate all images list
  31. grep -E '_repo:|_tag:' ${REPO_ROOT_DIR}/${DOWNLOAD_YML} \
  32. | sed "s#{%- if image_arch != 'amd64' -%}-{{ image_arch }}{%- endif -%}#{{arch}}#g" \
  33. | sed 's/: /=/g;s/{{/${/g;s/}}/}/g' | tr -d ' ' >> ${TEMP_DIR}/generate.sh
  34. sed -n '/^downloads:/,/download_defaults:/p' ${REPO_ROOT_DIR}/${DOWNLOAD_YML} \
  35. | sed -n "s/repo: //p;s/tag: //p" | tr -d ' ' | sed 's/{{/${/g;s/}}/}/g' \
  36. | sed 'N;s#\n# #g' | tr ' ' ':' | sed 's/^/echo /g' >> ${TEMP_DIR}/generate.sh
  37. # special handling for https://github.com/kubernetes-sigs/kubespray/pull/7570
  38. sed -i 's#^coredns_image_repo=.*#coredns_image_repo=${kube_image_repo}$(if printf "%s\\n%s\\n" v1.21 ${kube_version%.*} | sort --check=quiet --version-sort; then echo -n /coredns/coredns;else echo -n /coredns; fi)#' ${TEMP_DIR}/generate.sh
  39. sed -i 's#^coredns_image_tag=.*#coredns_image_tag=$(if printf "%s\\n%s\\n" v1.21 ${kube_version%.*} | sort --check=quiet --version-sort; then echo -n ${coredns_version};else echo -n ${coredns_version/v/}; fi)#' ${TEMP_DIR}/generate.sh
  40. # add kube-* images to images list
  41. KUBE_IMAGES="kube-apiserver kube-controller-manager kube-scheduler kube-proxy"
  42. echo "${KUBE_IMAGES}" | tr ' ' '\n' | xargs -L1 -I {} \
  43. echo 'echo ${kube_image_repo}/{}:${kube_version}' >> ${TEMP_DIR}/generate.sh
  44. # print files.list and images.list
  45. bash ${TEMP_DIR}/generate.sh | grep 'https' | sort > ${TEMP_DIR}/files.list
  46. bash ${TEMP_DIR}/generate.sh | grep -v 'https' | sort > ${TEMP_DIR}/images.list