|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2020 The Kubernetes Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +## Please note that this file needs to be escaped for envsubst to function |
| 18 | + |
| 19 | +# shellcheck disable=SC1083,SC2034,SC2066,SC2193 |
| 20 | + |
| 21 | +set -o nounset |
| 22 | +set -o pipefail |
| 23 | +set -o errexit |
| 24 | + |
| 25 | +function retry { |
| 26 | + attempt=0 |
| 27 | + max_attempts=$${1} |
| 28 | + interval=$${2} |
| 29 | + shift; shift |
| 30 | + until [[ $${attempt} -ge "$${max_attempts}" ]] ; do |
| 31 | + attempt=$((attempt+1)) |
| 32 | + set +e |
| 33 | + eval "$*" && return || echo "failed $${attempt} times: $*" |
| 34 | + set -e |
| 35 | + sleep "$${interval}" |
| 36 | + done |
| 37 | + echo "error: reached max attempts at retry($*)" |
| 38 | + return 1 |
| 39 | +} |
| 40 | + |
| 41 | +[[ $(id -u) != 0 ]] && SUDO="sudo" || SUDO="" |
| 42 | + |
| 43 | +USE_CI_ARTIFACTS=${USE_CI_ARTIFACTS:=false} |
| 44 | + |
| 45 | +if [ ! "${USE_CI_ARTIFACTS}" = true ]; then |
| 46 | + echo "No CI Artifacts installation, exiting" |
| 47 | + exit 0 |
| 48 | +fi |
| 49 | + |
| 50 | +# This test installs release packages or binaries that are a result of the CI and release builds. |
| 51 | +# It runs '... --version' commands to verify that the binaries are correctly installed |
| 52 | +# and finally uninstalls the packages. |
| 53 | +# For the release packages it tests all versions in the support skew. |
| 54 | +LINE_SEPARATOR="*************************************************" |
| 55 | +echo "$${LINE_SEPARATOR}" |
| 56 | + |
| 57 | +## Clusterctl set variables |
| 58 | +## |
| 59 | +# $${KUBERNETES_VERSION} will be replaced by clusterctl |
| 60 | +KUBERNETES_VERSION=${KUBERNETES_VERSION} |
| 61 | +## |
| 62 | +## End clusterctl set variables |
| 63 | + |
| 64 | +if [[ "$${KUBERNETES_VERSION}" != "" ]]; then |
| 65 | + CI_DIR=/tmp/k8s-ci |
| 66 | + mkdir -p "$${CI_DIR}" |
| 67 | + declare -a PACKAGES_TO_TEST=("kubectl" "kubelet" "kubeadm") |
| 68 | + declare -a CONTAINERS_TO_TEST=("kube-proxy") |
| 69 | + CONTAINER_EXT="tar" |
| 70 | + echo "* testing CI version $${KUBERNETES_VERSION}" |
| 71 | + # Check for semver |
| 72 | + if [[ "$${KUBERNETES_VERSION}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 73 | + CI_URL="https://storage.googleapis.com/kubernetes-release/release/$${KUBERNETES_VERSION}/bin/linux/amd64" |
| 74 | + VERSION_WITHOUT_PREFIX="$${KUBERNETES_VERSION#v}" |
| 75 | + export DEBIAN_FRONTEND=noninteractive |
| 76 | + # sometimes the network is not immediately available, so we have to retry the apt-get update |
| 77 | + retry 10 5 "apt-get update" |
| 78 | + apt-get install -y apt-transport-https ca-certificates curl |
| 79 | + curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - |
| 80 | + echo 'deb https://apt.kubernetes.io/ kubernetes-xenial main' >/etc/apt/sources.list.d/kubernetes.list |
| 81 | + apt-get update |
| 82 | + # replace . with \. |
| 83 | + VERSION_REGEX="$${VERSION_WITHOUT_PREFIX//./\\.}" |
| 84 | + PACKAGE_VERSION="$(apt-cache madison kubelet | grep "$${VERSION_REGEX}-" | head -n1 | cut -d '|' -f 2 | tr -d '[:space:]')" |
| 85 | + for CI_PACKAGE in "$${PACKAGES_TO_TEST[@]}"; do |
| 86 | + echo "* installing package: $${CI_PACKAGE} $${PACKAGE_VERSION}" |
| 87 | + apt-get install -y "$${CI_PACKAGE}=$${PACKAGE_VERSION}" |
| 88 | + done |
| 89 | + else |
| 90 | + CI_URL="https://storage.googleapis.com/kubernetes-release-dev/ci/$${KUBERNETES_VERSION}/bin/linux/amd64" |
| 91 | + for CI_PACKAGE in "$${PACKAGES_TO_TEST[@]}"; do |
| 92 | + # Browser: https://console.cloud.google.com/storage/browser/kubernetes-release-dev?project=kubernetes-release-dev |
| 93 | + # e.g.: https://storage.googleapis.com/kubernetes-release-dev/ci/v1.21.0-beta.1.378+cf3374e43491c5/bin/linux/amd64/kubectl |
| 94 | + echo "* downloading binary: $${CI_URL}/$${CI_PACKAGE}" |
| 95 | + wget "$${CI_URL}/$${CI_PACKAGE}" -O "$${CI_DIR}/$${CI_PACKAGE}" |
| 96 | + chmod +x "$${CI_DIR}/$${CI_PACKAGE}" |
| 97 | + mv "$${CI_DIR}/$${CI_PACKAGE}" "/usr/bin/$${CI_PACKAGE}" |
| 98 | + done |
| 99 | + systemctl restart kubelet |
| 100 | + fi |
| 101 | + for CI_CONTAINER in "$${CONTAINERS_TO_TEST[@]}"; do |
| 102 | + # Browser: https://console.cloud.google.com/storage/browser/kubernetes-release?project=kubernetes-release |
| 103 | + # e.g.: https://storage.googleapis.com/kubernetes-release/release/v1.20.4/bin/linux/amd64/kube-apiserver.tar |
| 104 | + echo "* downloading package: $${CI_URL}/$${CI_CONTAINER}.$${CONTAINER_EXT}" |
| 105 | + wget "$${CI_URL}/$${CI_CONTAINER}.$${CONTAINER_EXT}" -O "$${CI_DIR}/$${CI_CONTAINER}.$${CONTAINER_EXT}" |
| 106 | + $${SUDO} ctr -n k8s.io images import "$${CI_DIR}/$${CI_CONTAINER}.$${CONTAINER_EXT}" || echo "* ignoring expected 'ctr images import' result" |
| 107 | + $${SUDO} ctr -n k8s.io images tag "k8s.gcr.io/$${CI_CONTAINER}-amd64:$${KUBERNETES_VERSION//+/_}" "k8s.gcr.io/$${CI_CONTAINER}:$${KUBERNETES_VERSION//+/_}" |
| 108 | + $${SUDO} ctr -n k8s.io images tag "k8s.gcr.io/$${CI_CONTAINER}-amd64:$${KUBERNETES_VERSION//+/_}" "gcr.io/kubernetes-ci-images/$${CI_CONTAINER}:$${KUBERNETES_VERSION//+/_}" |
| 109 | + done |
| 110 | +fi |
| 111 | +echo "* checking binary versions" |
| 112 | +echo "ctr version: " "$(ctr version)" |
| 113 | +echo "kubeadm version: " "$(kubeadm version -o=short)" |
| 114 | +echo "kubectl version: " "$(kubectl version --client=true --short=true)" |
| 115 | +echo "kubelet version: " "$(kubelet --version)" |
| 116 | +echo "$${LINE_SEPARATOR}" |
0 commit comments