sigs.k8s.io/cluster-api-provider-aws@v1.5.5/hack/ensure-go.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  # Ensure the go tool exists and is a viable version.
    22  verify_go_version() {
    23    if [[ -z "$(command -v go)" ]]; then
    24      cat <<EOF
    25  Can't find 'go' in PATH, please fix and retry.
    26  See http://golang.org/doc/install for installation instructions.
    27  EOF
    28      return 2
    29    fi
    30  
    31    local go_version
    32    IFS=" " read -ra go_version <<< "$(go version)"
    33    local minimum_go_version
    34    minimum_go_version=go1.17.0
    35    if [[ "${minimum_go_version}" != $(echo -e "${minimum_go_version}\n${go_version[2]}" | sort -s -t. -k 1,1 -k 2,2n -k 3,3n | head -n1) && "${go_version[2]}" != "devel" ]]; then
    36      cat <<EOF
    37  Detected go version: ${go_version[*]}.
    38  Kubernetes requires ${minimum_go_version} or greater.
    39  Please install ${minimum_go_version} or later.
    40  EOF
    41      return 2
    42    fi
    43  }
    44  
    45  verify_go_version
    46  
    47  # Explicitly opt into go modules, even though we're inside a GOPATH directory
    48  export GO111MODULE=on