|
14 | 14 | # See the License for the specific language governing permissions and
|
15 | 15 | # limitations under the License.
|
16 | 16 |
|
| 17 | +# This has been copied from https://github.com/kubernetes-sigs/cluster-api/blob/v1.6.0/hack/ensure-kubectl.sh |
| 18 | + |
17 | 19 | set -o errexit
|
18 | 20 | set -o nounset
|
19 | 21 | set -o pipefail
|
20 | 22 |
|
| 23 | +if [[ "${TRACE-0}" == "1" ]]; then |
| 24 | + set -o xtrace |
| 25 | +fi |
| 26 | + |
| 27 | + |
| 28 | +# shellcheck source=./hack/utils.sh |
| 29 | +source "$(dirname "${BASH_SOURCE[0]}")/utils.sh" |
| 30 | + |
21 | 31 | GOPATH_BIN="$(go env GOPATH)/bin/"
|
22 |
| -MINIMUM_KUBECTL_VERSION=v1.19.0 |
23 |
| -GOARCH="$(go env GOARCH)" |
24 |
| -GOOS="$(go env GOOS)" |
| 32 | +MINIMUM_KUBECTL_VERSION=v1.28.0 |
| 33 | +goarch="$(go env GOARCH)" |
| 34 | +goos="$(go env GOOS)" |
25 | 35 |
|
26 | 36 | # Ensure the kubectl tool exists and is a viable version, or installs it
|
27 | 37 | verify_kubectl_version() {
|
28 | 38 |
|
29 | 39 | # If kubectl is not available on the path, get it
|
30 | 40 | if ! [ -x "$(command -v kubectl)" ]; then
|
31 |
| - if [ "$GOOS" == "linux" ] || [ "$GOOS" == "darwin" ]; then |
| 41 | + if [ "$goos" == "linux" ] || [ "$goos" == "darwin" ]; then |
32 | 42 | if ! [ -d "${GOPATH_BIN}" ]; then
|
33 | 43 | mkdir -p "${GOPATH_BIN}"
|
34 | 44 | fi
|
35 | 45 | echo 'kubectl not found, installing'
|
36 |
| - curl -sLo "${GOPATH_BIN}/kubectl" "https://dl.k8s.io/release/${MINIMUM_KUBECTL_VERSION}/bin/${GOOS}/${GOARCH}/kubectl" |
| 46 | + curl -sLo "${GOPATH_BIN}/kubectl" "https://dl.k8s.io/release/${MINIMUM_KUBECTL_VERSION}/bin/${goos}/${goarch}/kubectl" |
37 | 47 | chmod +x "${GOPATH_BIN}/kubectl"
|
| 48 | + verify_gopath_bin |
38 | 49 | else
|
39 | 50 | echo "Missing required binary in path: kubectl"
|
40 | 51 | return 2
|
41 | 52 | fi
|
42 | 53 | fi
|
43 | 54 |
|
44 | 55 | local kubectl_version
|
45 |
| - IFS=" " read -ra kubectl_version <<< "$(kubectl version --client --short 2>/dev/null `# "--short" was removed` || kubectl version --client)" |
| 56 | + IFS=" " read -ra kubectl_version <<< "$(kubectl version --client)" |
46 | 57 | if [[ "${MINIMUM_KUBECTL_VERSION}" != $(echo -e "${MINIMUM_KUBECTL_VERSION}\n${kubectl_version[2]}" | sort -s -t. -k 1,1 -k 2,2n -k 3,3n | head -n1) ]]; then
|
47 | 58 | cat <<EOF
|
48 | 59 | Detected kubectl version: ${kubectl_version[2]}.
|
|
0 commit comments