sigs.k8s.io/cluster-api-provider-azure@v1.14.3/scripts/ci-e2e.sh (about)

     1  #!/bin/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  ###############################################################################
    18  
    19  # This script is executed by presubmit `pull-cluster-api-provider-azure-e2e`
    20  # To run locally, set AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_SUBSCRIPTION_ID, AZURE_TENANT_ID
    21  
    22  set -o errexit
    23  set -o nounset
    24  set -o pipefail
    25  
    26  # Install kubectl
    27  REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
    28  KUBECTL="${REPO_ROOT}/hack/tools/bin/kubectl"
    29  KIND="${REPO_ROOT}/hack/tools/bin/kind"
    30  make --directory="${REPO_ROOT}" "${KUBECTL##*/}" "${KIND##*/}"
    31  
    32  # shellcheck source=hack/ensure-go.sh
    33  source "${REPO_ROOT}/hack/ensure-go.sh"
    34  # shellcheck source=hack/ensure-tags.sh
    35  source "${REPO_ROOT}/hack/ensure-tags.sh"
    36  # shellcheck source=hack/parse-prow-creds.sh
    37  source "${REPO_ROOT}/hack/parse-prow-creds.sh"
    38  # shellcheck source=hack/util.sh
    39  source "${REPO_ROOT}/hack/util.sh"
    40  
    41  # Verify the required Environment Variables are present.
    42  capz::util::ensure_azure_envs
    43  
    44  export LOCAL_ONLY=${LOCAL_ONLY:-"true"}
    45  export USE_LOCAL_KIND_REGISTRY=${USE_LOCAL_KIND_REGISTRY:-${LOCAL_ONLY}} 
    46  export BUILD_MANAGER_IMAGE=${BUILD_MANAGER_IMAGE:-"true"}
    47  
    48  if [[ "${USE_LOCAL_KIND_REGISTRY}" == "false" ]]; then
    49    : "${REGISTRY:?Environment variable empty or not defined.}"
    50    "${REPO_ROOT}/hack/ensure-acr-login.sh"
    51  else
    52    export REGISTRY="localhost:5000/ci-e2e"
    53  fi
    54  
    55  if [[ "${BUILD_MANAGER_IMAGE}" == "true" ]]; then
    56    defaultTag=$(date -u '+%Y%m%d%H%M%S')
    57    export TAG="${defaultTag:-dev}"
    58  fi
    59  
    60  if [[ "$(capz::util::should_build_ccm)" == "true" ]]; then
    61    # shellcheck source=scripts/ci-build-azure-ccm.sh
    62    source "${REPO_ROOT}/scripts/ci-build-azure-ccm.sh"
    63    echo "Will use the ${IMAGE_REGISTRY}/${CCM_IMAGE_NAME}:${IMAGE_TAG_CCM} cloud-controller-manager image for external cloud-provider-cluster"
    64    echo "Will use the ${IMAGE_REGISTRY}/${CNM_IMAGE_NAME}:${IMAGE_TAG_CNM} cloud-node-manager image for external cloud-provider-azure cluster"
    65  fi
    66  
    67  export GINKGO_NODES=10
    68  
    69  export AZURE_LOCATION="${AZURE_LOCATION:-$(capz::util::get_random_region)}"
    70  export AZURE_LOCATION_GPU="${AZURE_LOCATION_GPU:-$(capz::util::get_random_region_gpu)}"
    71  export AZURE_LOCATION_EDGEZONE="${AZURE_LOCATION_EDGEZONE:-$(capz::util::get_random_region_edgezone)}"
    72  export AZURE_CONTROL_PLANE_MACHINE_TYPE="${AZURE_CONTROL_PLANE_MACHINE_TYPE:-"Standard_B2s"}"
    73  export AZURE_NODE_MACHINE_TYPE="${AZURE_NODE_MACHINE_TYPE:-"Standard_B2s"}"
    74  CALICO_VERSION=$(make get-calico-version)
    75  export CALICO_VERSION
    76  
    77  
    78  capz::util::generate_ssh_key
    79  
    80  capz::ci-e2e::cleanup() {
    81      "${REPO_ROOT}/hack/log/redact.sh" || true
    82  }
    83  
    84  trap capz::ci-e2e::cleanup EXIT
    85  # Image is configured as `${CONTROLLER_IMG}-${ARCH}:${TAG}` where `CONTROLLER_IMG` is defaulted to `${REGISTRY}/${IMAGE_NAME}`.
    86  if [[ "${BUILD_MANAGER_IMAGE}" == "false" ]]; then
    87    # Load an existing image, skip docker-build and docker-push.
    88    make test-e2e-skip-build-and-push
    89  elif [[ "${USE_LOCAL_KIND_REGISTRY}" == "true" ]]; then
    90    # Build an image with kind local registry, skip docker-push. REGISTRY is set to `localhost:5000/ci-e2e`. TAG is set to `$(date -u '+%Y%m%d%H%M%S')`.
    91    make test-e2e-skip-push
    92  else
    93    # Build an image and push to the registry. TAG is set to `$(date -u '+%Y%m%d%H%M%S')`.
    94    make test-e2e
    95  fi