github.phpd.cn/cilium/cilium@v1.6.12/test/provision/helpers.bash (about)

     1  #!/usr/bin/env bash
     2  
     3  function log_msg {
     4    MSG="$1"
     5    echo "***************************************"
     6    echo "*"
     7    echo "*"
     8    echo "* ${MSG}"
     9    echo "*"
    10    echo "*"
    11    echo "***************************************"
    12  }
    13  
    14  function retry_function {
    15    set +e
    16    FUNC="$1"
    17    COUNTER=0
    18    MAX_TRIES=10
    19    echo "beginning trying up to ${MAX_TRIES} times function \"${FUNC}\""
    20    while [ $COUNTER -lt $MAX_TRIES ]; do
    21      log_msg "on attempt ${COUNTER} of function \"${FUNC}\""
    22      ${FUNC}
    23      if [[ "$?" == "0" ]] ; then
    24        echo "running of \"${FUNC}\" successful"
    25        echo
    26        echo
    27        echo
    28        set -e
    29        return 0
    30      fi
    31      sleep 1
    32      let COUNTER=COUNTER+1
    33    done
    34  
    35    log_msg "running function \"${FUNC}\" ${MAX_TRIES} times did not succeed"
    36    set -e
    37    return 1
    38  }
    39  
    40  function install_using_apt {
    41      apt-get update
    42      apt-get install --allow-downgrades -y \
    43          "$@"
    44  }
    45  
    46  function install_k8s_using_packages {
    47      install_using_apt "$@"
    48  }
    49  
    50  function install_k8s_using_binary {
    51      local RELEASE=$1
    52      local CNI_VERSION=$2
    53      cd $(mktemp -d)
    54  
    55      mkdir -p /opt/cni/bin
    56      mkdir -p /etc/systemd/system/kubelet.service.d
    57  
    58      curl -sSL "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-amd64-${CNI_VERSION}.tgz" | tar -C /opt/cni/bin -xz
    59  
    60      wget -q https://storage.googleapis.com/kubernetes-release/release/$RELEASE/bin/linux/amd64/{kubectl,kubeadm,kubelet}
    61      chmod 777 ku*
    62      cp -fv ku* /usr/bin/
    63      rm -rf /etc/systemd/system/kubelet.service || true
    64      curl -sSL https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/kubelet.service > /etc/systemd/system/kubelet.service
    65  
    66  
    67      curl -sSL "https://raw.githubusercontent.com/kubernetes/kubernetes/${RELEASE}/build/debs/10-kubeadm.conf" > /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
    68      systemctl enable kubelet
    69  }