sigs.k8s.io/cluster-api@v1.7.1/hack/ensure-kind.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2019 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 set -o errexit 18 set -o nounset 19 set -o pipefail 20 21 if [[ "${TRACE-0}" == "1" ]]; then 22 set -o xtrace 23 fi 24 25 # shellcheck source=./hack/utils.sh 26 source "$(dirname "${BASH_SOURCE[0]}")/utils.sh" 27 28 GOPATH_BIN="$(go env GOPATH)/bin" 29 goarch="$(go env GOARCH)" 30 goos="$(go env GOOS)" 31 32 # Note: When updating the MINIMUM_KIND_VERSION new shas MUST be added in `preBuiltMappings` at `test/infrastructure/kind/mapper.go` 33 MINIMUM_KIND_VERSION=v0.22.0 34 35 36 # Ensure the kind tool exists and is a viable version, or installs it 37 verify_kind_version() { 38 39 # If kind is not available on the path, get it 40 if ! [ -x "$(command -v kind)" ]; then 41 if [ "$goos" == "linux" ] || [ "$goos" == "darwin" ]; then 42 echo 'kind not found, installing' 43 if ! [ -d "${GOPATH_BIN}" ]; then 44 mkdir -p "${GOPATH_BIN}" 45 fi 46 curl -sLo "${GOPATH_BIN}/kind" "https://github.com/kubernetes-sigs/kind/releases/download/${MINIMUM_KIND_VERSION}/kind-${goos}-${goarch}" 47 chmod +x "${GOPATH_BIN}/kind" 48 verify_gopath_bin 49 else 50 echo "Missing required binary in path: kind" 51 return 2 52 fi 53 fi 54 55 local kind_version 56 kind_version="v$(kind version -q)" 57 if [[ "${MINIMUM_KIND_VERSION}" != $(echo -e "${MINIMUM_KIND_VERSION}\n${kind_version}" | sort -s -t. -k 1,1n -k 2,2n -k 3,3n | head -n1) ]]; then 58 cat <<EOF 59 Detected kind version: ${kind_version}. 60 Requires ${MINIMUM_KIND_VERSION} or greater. 61 Please install ${MINIMUM_KIND_VERSION} or later. 62 EOF 63 return 2 64 fi 65 } 66 67 verify_kind_version