github.com/verrazzano/verrazzano@v1.7.1/ci/scripts/setup_kind.sh (about)

     1  #!/usr/bin/env bash
     2  #
     3  # Copyright (c) 2022, 2023, Oracle and/or its affiliates.
     4  # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     5  #
     6  
     7  # $1 Boolean indicates whether to setup and install Calico or not
     8  
     9  set -o pipefail
    10  
    11  #set -xv
    12  
    13  if [ -z "$GO_REPO_PATH" ] ; then
    14    echo "GO_REPO_PATH must be set"
    15    exit 1
    16  fi
    17  if [ -z "$TESTS_EXECUTED_FILE" ]; then
    18    echo "TESTS_EXECUTED_FILE mark file path not set, required to indicate if tests have run"
    19    exit 1
    20  fi
    21  if [ -z "$WORKSPACE" ]; then
    22    echo "WORKSPACE must be set"
    23    exit 1
    24  fi
    25  if [ -z "$TEST_SCRIPTS_DIR" ]; then
    26    echo "TEST_SCRIPTS_DIR must be set to the E2E test script directory location"
    27    exit 1
    28  fi
    29  
    30  scriptHome=$(dirname ${BASH_SOURCE[0]})
    31  
    32  set -e
    33  
    34  if [ -n "${VZ_TEST_DEBUG}" ]; then
    35    set -xv
    36  fi
    37  
    38  export KUBECONFIG=${KUBECONFIG:-"${WORKSPACE}/test_kubeconfig"}
    39  export KUBERNETES_CLUSTER_VERSION=${KUBERNETES_CLUSTER_VERSION:-"1.24"}
    40  
    41  CONNECT_JENKINS_RUNNER_TO_NETWORK=false
    42  if [ -n "${JENKINS_URL}" ]; then
    43    echo "Running in Jenkins, URL=${JENKINS_URL}"
    44    CONNECT_JENKINS_RUNNER_TO_NETWORK=true
    45  fi
    46  
    47  INSTALL_CALICO=${1:-false}
    48  CLUSTER_NAME=${CLUSTER_NAME:="kind"}
    49  KIND_NODE_COUNT=${KIND_NODE_COUNT:-1}
    50  VERRAZZANO_OPERATOR_IMAGE=${VERRAZZANO_OPERATOR_IMAGE:-"NONE"}
    51  
    52  BRANCH_NAME=${BRANCH_NAME:-$(git branch --show-current)}
    53  SHORT_COMMIT_HASH=${SHORT_COMMIT_HASH:-$(git rev-parse --short=8 HEAD)}
    54  OCI_OS_LOCATION=${OCI_OS_LOCATION:-ephemeral/${BRANCH_NAME}/${SHORT_COMMIT_HASH}}
    55  
    56  KIND_CACHING=${KIND_CACHING:="false"}
    57  KIND_NODE_COUNT=${KIND_NODE_COUNT:-1}
    58  
    59  mkdir -p $WORKSPACE || true
    60  
    61  echo "tests will execute" > ${TESTS_EXECUTED_FILE}
    62  echo "Create Kind cluster"
    63  ${scriptHome}/create_kind_clusters.sh "${CLUSTER_NAME}" "${GO_REPO_PATH}/verrazzano/platform-operator" "${KUBECONFIG}" "${KUBERNETES_CLUSTER_VERSION}" true ${CONNECT_JENKINS_RUNNER_TO_NETWORK} true $INSTALL_CALICO "NONE" ${KIND_NODE_COUNT}
    64  if [ $? -ne 0 ]; then
    65      mkdir -p $WORKSPACE/kind-logs``
    66      kind export logs $WORKSPACE/kind-logs
    67      echo "Kind cluster creation failed"
    68      exit 1
    69  fi
    70  
    71  if [ $INSTALL_CALICO == true ]; then
    72      echo "Install Calico"
    73      #cd ${GO_REPO_PATH}/verrazzano
    74      ${scriptHome}/install_calico.sh "${CLUSTER_NAME}"
    75  fi
    76  
    77  # With the Calico configuration to set disableDefaultCNI to true in the KIND configuration, the control plane node will
    78  # be ready only after applying calico.yaml. So wait for the KIND control plane node to be ready, before proceeding further,
    79  # with maximum wait period of 5 minutes.
    80  kubectl  wait --for=condition=ready nodes/${CLUSTER_NAME}-control-plane --timeout=5m --all
    81  kubectl wait --for=condition=ready pods/kube-controller-manager-${CLUSTER_NAME}-control-plane -n kube-system --timeout=5m
    82  echo "Listing pods in kube-system namespace ..."
    83  kubectl get pods -n kube-system
    84  
    85  echo "Install metallb"
    86  METALLB_ADDRESS_RANGE=${METALLB_ADDRESS_RANGE:-"172.18.0.230-172.18.0.254"}
    87  ${TEST_SCRIPTS_DIR}/install-metallb.sh "${METALLB_ADDRESS_RANGE}"
    88  
    89  exit 0