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

     1  #!/usr/bin/env bash
     2  #
     3  # Copyright (c) 2021, 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 "$JENKINS_URL" ] || [ -z "$GO_REPO_PATH" ] || [ -z "$TESTS_EXECUTED_FILE" ] || [ -z "$WORKSPACE" ] || [ -z "$VERRAZZANO_OPERATOR_IMAGE" ] || [ -z "$INSTALL_CONFIG_FILE_KIND" ] || [ -z "$OCI_OS_LOCATION" ] || [ -z "$OCI_OS_COMMIT_BUCKET" ] || [ -z "$TEST_SCRIPTS_DIR" ]; then
    14    echo "This script must only be called from Jenkins and requires a number of environment variables are set"
    15    exit 1
    16  fi
    17  
    18  if ! [ -x "$(command -v go)" ]; then
    19    echo "vz command-line tool requires go which does not appear to be installed"
    20    exit 1
    21  fi
    22  
    23  INSTALL_CALICO=${1:-false}
    24  WILDCARD_DNS_DOMAIN=${2:-"x=nip.io"}
    25  USE_DB_FOR_GRAFANA=${3:-false}
    26  KIND_NODE_COUNT=${KIND_NODE_COUNT:-1}
    27  TEST_OVERRIDE_CONFIGMAP_FILE="./tests/e2e/config/scripts/pre-install-overrides/test-overrides-configmap.yaml"
    28  TEST_OVERRIDE_SECRET_FILE="./tests/e2e/config/scripts/pre-install-overrides/test-overrides-secret.yaml"
    29  INSTALL_TIMEOUT_VALUE=${INSTALL_TIMEOUT:-30m}
    30  ENABLE_THANOS_STORE_GATEWAY=${ENABLE_THANOS_STORE_GATEWAY:-false}
    31  ENABLE_THANOS_COMPACTOR=${ENABLE_THANOS_COMPACTOR:-false}
    32  ENABLE_THANOS_RULER=${ENABLE_THANOS_RULER:-false}
    33  INSTALL_EXTERNAL_CERT_MANAGER=${INSTALL_EXTERNAL_CERT_MANAGER:-false}
    34  ENABLE_DEX=${ENABLE_DEX:-false}
    35  
    36  clusterNames=$(kind get clusters)
    37  if [[ $clusterNames == *"${CLUSTER_NAME}"* ]]; then
    38      echo "${CLUSTER_NAME} already exists"
    39      echo "Skipping kind cluster creation"
    40  else
    41    cd ${GO_REPO_PATH}/verrazzano
    42    echo "tests will execute" > ${TESTS_EXECUTED_FILE}
    43    echo "Create Kind cluster"
    44    cd ${TEST_SCRIPTS_DIR}
    45    ./create_kind_cluster.sh "${CLUSTER_NAME}" "${GO_REPO_PATH}/verrazzano/platform-operator" "${KUBECONFIG}" "${KIND_KUBERNETES_CLUSTER_VERSION}" true true true $INSTALL_CALICO "NONE" ${KIND_NODE_COUNT}
    46    if [ $? -ne 0 ]; then
    47        mkdir $WORKSPACE/kind-logs
    48        kind export logs $WORKSPACE/kind-logs
    49        echo "Kind cluster creation failed"
    50        exit 1
    51    fi
    52  
    53    if [ $INSTALL_CALICO == true ]; then
    54      echo "Install Calico"
    55      cd ${GO_REPO_PATH}/verrazzano
    56      ./ci/scripts/install_calico.sh "${CLUSTER_NAME}"
    57    fi
    58    # With the Calico configuration to set disableDefaultCNI to true in the KIND configuration, the control plane node will
    59    # be ready only after applying calico.yaml. So wait for the KIND control plane node to be ready, before proceeding further,
    60    # with maximum wait period of 5 minutes.
    61    kubectl wait --for=condition=ready nodes/${CLUSTER_NAME}-control-plane --timeout=5m --all
    62    kubectl wait --for=condition=ready pods/kube-controller-manager-${CLUSTER_NAME}-control-plane -n kube-system --timeout=5m
    63    echo "Listing pods in kube-system namespace ..."
    64    kubectl get pods -n kube-system
    65  
    66    echo "Install metallb"
    67    cd ${GO_REPO_PATH}/verrazzano
    68    ./tests/e2e/config/scripts/install-metallb.sh
    69    if [ $? -ne 0 ]; then
    70        mkdir $WORKSPACE/kind-logs
    71        kind export logs $WORKSPACE/kind-logs
    72        echo "Metalllb installation failed"
    73        exit 1
    74    fi
    75  
    76    echo "Create Image Pull Secrets"
    77    cd ${GO_REPO_PATH}/verrazzano
    78    ./tests/e2e/config/scripts/create-image-pull-secret.sh "${IMAGE_PULL_SECRET}" "${DOCKER_REPO}" "${DOCKER_CREDS_USR}" "${DOCKER_CREDS_PSW}"
    79    ./tests/e2e/config/scripts/create-image-pull-secret.sh github-packages "${DOCKER_REPO}" "${DOCKER_CREDS_USR}" "${DOCKER_CREDS_PSW}"
    80    ./tests/e2e/config/scripts/create-image-pull-secret.sh ocr "${OCR_REPO}" "${OCR_CREDS_USR}" "${OCR_CREDS_PSW}"
    81  
    82    echo "Determine which yaml file to use to install the Verrazzano Platform Operator"
    83    cd ${GO_REPO_PATH}/verrazzano
    84  
    85    VZ_CLI_TARGZ="vz-linux-amd64.tar.gz"
    86    echo "Downloading VZ CLI from object storage"
    87    if [[ -z "$OCI_OS_LOCATION" ]]; then
    88      OCI_OS_LOCATION="$BRANCH_NAME/$(git rev-parse --short=8 HEAD)"
    89    fi
    90    oci --region us-phoenix-1 os object get --namespace ${OCI_OS_NAMESPACE} -bn ${OCI_OS_COMMIT_BUCKET} --name ${OCI_OS_LOCATION}/$VZ_CLI_TARGZ --file ${WORKSPACE}/$VZ_CLI_TARGZ
    91    tar xzf "$WORKSPACE"/$VZ_CLI_TARGZ -C "$WORKSPACE"
    92  
    93    # Create the verrazzano-install namespace
    94    kubectl create namespace verrazzano-install
    95  
    96    # if enabled, deploy the Grafana MySQL instance and create the Grafana DB secret
    97    if [ $USE_DB_FOR_GRAFANA == true ]; then
    98      # create the necessary secrets
    99      MYSQL_ROOT_PASSWORD=$(openssl rand -base64 12)
   100      MYSQL_PASSWORD=$(openssl rand -base64 12)
   101      ROOT_SECRET=$(echo -n $MYSQL_ROOT_PASSWORD | base64)
   102      USER_SECRET=$(echo -n $MYSQL_PASSWORD | base64)
   103      USER=$(echo -n "grafana" | base64)
   104  
   105      kubectl apply -f - <<-EOF
   106        apiVersion: v1
   107        kind: Secret
   108        metadata:
   109          name: grafana-db
   110          namespace: verrazzano-install
   111        type: Opaque
   112        data:
   113          root-password: $ROOT_SECRET
   114          username: $USER
   115          password: $USER_SECRET
   116  EOF
   117      # deploy MySQL instance
   118      kubectl apply -f $WORKSPACE/tests/testdata/grafana/grafana-mysql.yaml
   119    fi
   120  
   121    # create verrazzano-github-token secret in verrazzano-install ns
   122    if [ -n "${GITHUB_TOKEN}" ]; then
   123      ./tests/e2e/config/scripts/create-github-token-secret.sh "verrazzano-github-token" "${GITHUB_TOKEN}" "verrazzano-install"
   124    fi
   125  
   126    # create secret in verrazzano-install ns
   127    ./tests/e2e/config/scripts/create-image-pull-secret.sh "${IMAGE_PULL_SECRET}" "${DOCKER_REPO}" "${DOCKER_CREDS_USR}" "${DOCKER_CREDS_PSW}" "verrazzano-install"
   128  
   129    # optionally create a cluster dump snapshot for verifying uninstalls
   130    if [ -n "${CLUSTER_SNAPSHOT_DIR}" ]; then
   131      ./tests/e2e/config/scripts/looping-test/dump_cluster.sh ${CLUSTER_SNAPSHOT_DIR} false
   132    fi
   133  
   134  
   135    echo "Creating Override ConfigMap"
   136    kubectl create cm test-overrides --from-file=${TEST_OVERRIDE_CONFIGMAP_FILE}
   137    if [ $? -ne 0 ]; then
   138      echo "Could not create Override ConfigMap"
   139      exit 1
   140    fi
   141  
   142    echo "Creating Override Secret"
   143    kubectl create secret generic test-overrides --from-file=${TEST_OVERRIDE_SECRET_FILE}
   144    if [ $? -ne 0 ]; then
   145      echo "Could not create Override Secret"
   146      exit 1
   147    fi
   148  
   149    if [ $INSTALL_EXTERNAL_CERT_MANAGER == true ]; then
   150      echo "Configuring installation with external cert-manger and NGINX"
   151      ./ci/scripts/install_third_party_components.sh
   152    fi
   153  fi
   154  
   155  # Configure the custom resource to install Verrazzano on Kind
   156  VZ_INSTALL_FILE=${VZ_INSTALL_FILE:-"${WORKSPACE}/acceptance-test-config.yaml"}
   157  ./tests/e2e/config/scripts/process_kind_install_yaml.sh ${INSTALL_CONFIG_FILE_KIND} ${WILDCARD_DNS_DOMAIN}
   158  # If grafana is using a DB add the database configuration to the VZ file
   159  if [ $USE_DB_FOR_GRAFANA == true ]; then
   160    ./tests/e2e/config/scripts/process_grafana_db_install_yaml.sh ${INSTALL_CONFIG_FILE_KIND}
   161  fi
   162  # Create the storage provider secret and update the Thanos overrides in the VZ file
   163  ./tests/e2e/config/scripts/configure_thanos_install_storage.sh ${INSTALL_CONFIG_FILE_KIND}
   164  cp -v ${INSTALL_CONFIG_FILE_KIND} ${VZ_INSTALL_FILE}
   165  
   166  TARGET_OPERATOR_FILE=${TARGET_OPERATOR_FILE:-"${WORKSPACE}/acceptance-test-operator.yaml"}
   167  if [ -z "$OPERATOR_YAML" ] && [ "" = "${OPERATOR_YAML}" ]; then
   168    # Derive the name of the operator.yaml file, copy or generate the file, then install
   169    if [ "NONE" = "${VERRAZZANO_OPERATOR_IMAGE}" ]; then
   170      echo "Using operator.yaml from object storage"
   171      oci --region us-phoenix-1 os object get --namespace ${OCI_OS_NAMESPACE} -bn ${OCI_OS_COMMIT_BUCKET} --name ${OCI_OS_LOCATION}/operator.yaml --file ${WORKSPACE}/downloaded-operator.yaml
   172      cp -v ${WORKSPACE}/downloaded-operator.yaml ${TARGET_OPERATOR_FILE}
   173    else
   174      echo "Generating operator.yaml based on image name provided: ${VERRAZZANO_OPERATOR_IMAGE}"
   175      env IMAGE_PULL_SECRETS=verrazzano-container-registry DOCKER_IMAGE=${VERRAZZANO_OPERATOR_IMAGE} ./tools/scripts/generate_operator_yaml.sh > ${TARGET_OPERATOR_FILE}
   176    fi
   177  else
   178    # The operator.yaml filename was provided, install using that file.
   179    echo "Using provided operator.yaml file: " ${OPERATOR_YAML}
   180    TARGET_OPERATOR_FILE=${OPERATOR_YAML}
   181  fi
   182  
   183  
   184  if [[ ${SKIP_VERRAZZANO_INSTALL} == "true" ]]; then
   185    echo "Skipping Verrazzano install"
   186    exit 0
   187  fi
   188  
   189  # This flag is defaulted to false so that the VZ install proceeds as usual
   190  if [[ ${SKIP_VERRAZZANO_INSTALL} == "false" || ${SKIP_VERRAZZANO_INSTALL} == "" ]]; then
   191    echo "Installing Verrazzano on Kind"
   192    if [ -f "$WORKSPACE/vz" ]; then
   193      cd $WORKSPACE
   194      ./vz install --filename ${WORKSPACE}/acceptance-test-config.yaml --manifests ${TARGET_OPERATOR_FILE} --timeout ${INSTALL_TIMEOUT_VALUE}
   195    else
   196      cd ${GO_REPO_PATH}/verrazzano/tools/vz
   197      GO111MODULE=on GOPRIVATE=github.com/verrazzano go run main.go install --filename ${VZ_INSTALL_FILE} --manifests ${TARGET_OPERATOR_FILE} --timeout ${INSTALL_TIMEOUT_VALUE}
   198    fi
   199    result=$?
   200    if [[ $result -ne 0 ]]; then
   201      exit 1
   202    fi
   203  fi
   204  exit 0