github.com/abayer/test-infra@v0.0.5/images/kubekins-e2e/kops-e2e-runner.sh (about)

     1  #!/bin/bash
     2  # Copyright 2016 The Kubernetes Authors.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #     http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  # Download the latest version of kops, then run the e2e tests using e2e.sh.
    17  
    18  set -o errexit
    19  set -o nounset
    20  set -o pipefail
    21  set -o xtrace
    22  
    23  for i in {1..10}; do
    24    echo 'WARNING: kops-e2e-runner.sh is deprecated, migrate logic to kubetest'
    25  done
    26  
    27  if [[ -z "${KOPS_BASE_URL:-}" ]]; then
    28    readonly KOPS_LATEST=${KOPS_LATEST:-"latest-ci.txt"}
    29    readonly LATEST_URL="https://storage.googleapis.com/kops-ci/bin/${KOPS_LATEST}"
    30    export KOPS_BASE_URL=$(curl -fsS --retry 3 "${LATEST_URL}")
    31    if [[ -z "${KOPS_BASE_URL}" ]]; then
    32      echo "Can't fetch kops latest URL" >&2
    33      exit 1
    34    fi
    35  fi
    36  
    37  curl -fsS --retry 3 -o "/workspace/kops" "${KOPS_BASE_URL}/linux/amd64/kops"
    38  chmod +x "/workspace/kops"
    39  
    40  # Get kubectl on the path (works after e2e-runner.sh:unpack_binaries)
    41  export PRIORITY_PATH="${WORKSPACE}/kubernetes/platforms/linux/amd64"
    42  
    43  e2e_args=( \
    44    --deployment=kops \
    45    --kops=/workspace/kops \
    46  )
    47  
    48  # TODO(zmerlynn): This is duplicating some logic in e2e-runner.sh, but
    49  # I'd rather keep it isolated for now.
    50  if [[ "${KOPS_DEPLOY_LATEST_KUBE:-}" =~ ^[yY]$ ]]; then
    51    readonly KOPS_KUBE_LATEST_URL=${KOPS_DEPLOY_LATEST_URL:-"https://storage.googleapis.com/kubernetes-release-dev/ci/latest.txt"}
    52    readonly KOPS_KUBE_LATEST=$(curl -fsS --retry 3 "${KOPS_KUBE_LATEST_URL}")
    53    if [[ -z "${KOPS_KUBE_LATEST}" ]]; then
    54      echo "Can't fetch kube latest URL" >&2
    55      exit 1
    56    fi
    57    readonly KOPS_KUBE_RELEASE_URL=${KOPS_KUBE_RELEASE_URL:-"https://storage.googleapis.com/kubernetes-release-dev/ci"}
    58  
    59    e2e_args+=(--kops-kubernetes-version="${KOPS_KUBE_RELEASE_URL}/${KOPS_KUBE_LATEST}")
    60  fi
    61  
    62  EXTERNAL_IP=$(curl -SsL -H 'Metadata-Flavor: Google' 'http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip' || true)
    63  if [[ -z "${EXTERNAL_IP}" ]]; then
    64    # Running outside GCE
    65    echo
    66    echo "WARNING: Getting external IP from instance metadata failed, assuming not running on GCE."
    67    echo
    68    EXTERNAL_IP=$(curl 'http://v4.ifconfig.co')
    69  fi
    70  e2e_args+=(--kops-admin-access="${EXTERNAL_IP}/32")
    71  
    72  # Define a custom instance lister for cluster/log-dump/log-dump.sh.
    73  function log_dump_custom_get_instances() {
    74    local -r role=$1
    75    local kops_regions
    76    IFS=', ' read -r -a kops_regions <<< "${KOPS_REGIONS:-us-west-2}"
    77    for region in "${kops_regions[@]}"; do
    78      aws ec2 describe-instances \
    79        --region "${region}" \
    80        --filter \
    81          "Name=tag:KubernetesCluster,Values=$(kubectl config current-context)" \
    82          "Name=tag:k8s.io/role/${role},Values=1" \
    83          "Name=instance-state-name,Values=running" \
    84        --query "Reservations[].Instances[].PublicDnsName" \
    85        --output text
    86    done
    87  }
    88  pip install awscli # Only needed for log_dump_custom_get_instances
    89  export -f log_dump_custom_get_instances # Export to cluster/log-dump/log-dump.sh
    90  
    91  kubetest "${e2e_args[@]}" "${@}"
    92  
    93  if [[ -n "${KOPS_PUBLISH_GREEN_PATH:-}" ]]; then
    94  
    95    if ! which gsutil; then
    96      export PATH=/google-cloud-sdk/bin:${PATH}
    97      if ! which gsutil; then
    98        echo "Can't find gsutil" >&2
    99        exit 1
   100      fi
   101    fi
   102  
   103    # TODO(krzyzacy) - debugging
   104    gcloud config list
   105    gcloud auth list
   106  
   107    echo "Publish version to ${KOPS_PUBLISH_GREEN_PATH}: ${KOPS_BASE_URL}"
   108    echo "${KOPS_BASE_URL}" | gsutil -h "Cache-Control:private, max-age=0, no-transform" cp - "${KOPS_PUBLISH_GREEN_PATH}"
   109  fi