github.com/openshift/installer@v1.4.17/hack/build-cluster-api.sh (about)

     1  #!/bin/sh
     2  
     3  set -e
     4  
     5  TARGET_OS_ARCH=$(go env GOOS)_$(go env GOARCH)
     6  CLUSTER_API_BIN_DIR="${PWD}/cluster-api/bin/${TARGET_OS_ARCH}"
     7  CLUSTER_API_MIRROR_DIR="${PWD}/pkg/clusterapi/mirror/"
     8  ENVTEST_K8S_VERSION="1.30.0"
     9  ENVTEST_ARCH=$(go env GOOS)-$(go env GOARCH)
    10  
    11  copy_cluster_api_to_mirror() {
    12    mkdir -p "${CLUSTER_API_BIN_DIR}"
    13    mkdir -p "${CLUSTER_API_MIRROR_DIR}"
    14  
    15    # Clean the mirror, but preserve the README file.
    16    rm -rf "${CLUSTER_API_MIRROR_DIR:?}/*.zip"
    17  
    18    if test "${SKIP_ENVTEST}" != y; then
    19      sync_envtest
    20    fi
    21  
    22    # Zip every binary in the folder into a single zip file.
    23    zip -j1 "${CLUSTER_API_MIRROR_DIR}/cluster-api.zip" "${CLUSTER_API_BIN_DIR}"/*
    24  }
    25  
    26  sync_envtest() {
    27    if [ -f "${CLUSTER_API_BIN_DIR}/kube-apiserver" ]; then
    28      if [ "$(go env GOOS)" != "$(go env GOHOSTOS)" ] || [ "$(go env GOARCH)" != "$(go env GOHOSTARCH)" ]; then
    29        echo "Found cross-compiled artifact: skipping envtest binaries version check"
    30        return
    31      fi
    32      version=$( ("${CLUSTER_API_BIN_DIR}/kube-apiserver" --version || echo "v0.0.0") | sed 's/Kubernetes //' )
    33      echo "Found envtest binaries with version: ${version}"
    34      if printf '%s\n%s' v${ENVTEST_K8S_VERSION} "${version}" | sort -V -C; then
    35        return
    36      fi
    37    fi
    38  
    39    bucket="https://github.com/kubernetes-sigs/controller-tools/releases/download/envtest-v${ENVTEST_K8S_VERSION}"
    40    tar_file="envtest-v${ENVTEST_K8S_VERSION}-${ENVTEST_ARCH}.tar.gz"
    41    dst="${CLUSTER_API_BIN_DIR}/${tar_file}"
    42    if ! [ -f "${CLUSTER_API_BIN_DIR}/${tar_file}" ]; then
    43      echo "Downloading envtest binaries"
    44      curl -fL "${bucket}/${tar_file}" -o "${dst}"
    45    fi
    46    tar -C "${CLUSTER_API_BIN_DIR}" -xzf "${dst}" --strip-components=2
    47    rm "${dst}" # Remove the tar file.
    48    rm "${CLUSTER_API_BIN_DIR}/kubectl" # Remove kubectl since we don't need it.
    49  }