|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: Apache-2.0 |
| 6 | + |
| 7 | +set -o nounset |
| 8 | +set -o pipefail |
| 9 | + |
| 10 | +GARDENER_KUBECONFIG_PATH=$1 |
| 11 | +NAMESPACE=$2 |
| 12 | +VERSION=$3 |
| 13 | +PR_ID=$4 |
| 14 | + |
| 15 | +MAX_NUM_CLUSTERS=20 |
| 16 | +NUM_CLUSTERS_START_DELETE_OLDEST=15 |
| 17 | +DURATION_FOR_CLUSTER_DELETION=48h |
| 18 | + |
| 19 | +PROJECT_ROOT="$(realpath $(dirname $0)/..)" |
| 20 | + |
| 21 | +make -C $PROJECT_ROOT revendor |
| 22 | + |
| 23 | +echo "Run integration tests with cluster and registry creation" |
| 24 | +echo "Source path: ${PROJECT_ROOT}" |
| 25 | +echo "Gardener kubeconfig path: ${GARDENER_KUBECONFIG_PATH}" |
| 26 | +echo "Shoot cluster namespace: ${NAMESPACE}" |
| 27 | +echo "Landscaper version: ${VERSION}" |
| 28 | + |
| 29 | +TMP="${PROJECT_ROOT}/tmp-int-test-cluster" |
| 30 | +rm -f -r $TMP |
| 31 | +mkdir -p $TMP |
| 32 | +TARGET_SHOOT_DIR="${TMP}/target-shoot" |
| 33 | +RESOURCE_SHOOT_DIR="${TMP}/resource-shoot" |
| 34 | +mkdir -p $TARGET_SHOOT_DIR |
| 35 | +mkdir -p $RESOURCE_SHOOT_DIR |
| 36 | +echo "Config directory: ${TMP}" |
| 37 | + |
| 38 | +exit_on_error() { |
| 39 | + if [ "$1" -ne 0 ]; then |
| 40 | + echo -e "Error: $2" |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | +} |
| 44 | + |
| 45 | +"${PROJECT_ROOT}/hack/int-test-helper/install-missing-software" |
| 46 | +exit_on_error $? "install software failed" |
| 47 | + |
| 48 | +CREATE_SHOOT_PIDS=() |
| 49 | + |
| 50 | +echo "Creating Target Shoot Cluster" |
| 51 | +NGINX_INGRESS_ENABLED=true |
| 52 | +DISABLE_SHOOT_DELETION=false |
| 53 | +WORKERLESS=false |
| 54 | +timeout -k 30m 30m "${PROJECT_ROOT}/hack/int-test-helper/create-shoot-cluster" $GARDENER_KUBECONFIG_PATH \ |
| 55 | + $NAMESPACE \ |
| 56 | + $TARGET_SHOOT_DIR \ |
| 57 | + $MAX_NUM_CLUSTERS \ |
| 58 | + $NUM_CLUSTERS_START_DELETE_OLDEST \ |
| 59 | + $DURATION_FOR_CLUSTER_DELETION \ |
| 60 | + $PR_ID \ |
| 61 | + $NGINX_INGRESS_ENABLED \ |
| 62 | + $DISABLE_SHOOT_DELETION \ |
| 63 | + $WORKERLESS \ |
| 64 | + &>"${TARGET_SHOOT_DIR}/create-shoot-cluster.log" & |
| 65 | + |
| 66 | +CREATE_SHOOT_PIDS+=($!) |
| 67 | + |
| 68 | +# When both create-shoot-cluster calls are started at the same time, |
| 69 | +# the resource shoot may be cleaned-up by the target shoot create call. |
| 70 | +# To prevent this, the target shoot create gets a head start before the |
| 71 | +# resource shoot is being created. |
| 72 | +# The sleep also improves the entropy when generating a Shoot name. |
| 73 | +sleep 15 |
| 74 | + |
| 75 | +echo "Creating Resource Shoot Cluster" |
| 76 | +NGINX_INGRESS_ENABLED=false |
| 77 | +DISABLE_SHOOT_DELETION=true |
| 78 | +WORKERLESS=false |
| 79 | +timeout -k 30m 30m "${PROJECT_ROOT}/hack/int-test-helper/create-shoot-cluster" $GARDENER_KUBECONFIG_PATH \ |
| 80 | + $NAMESPACE \ |
| 81 | + $RESOURCE_SHOOT_DIR \ |
| 82 | + $MAX_NUM_CLUSTERS \ |
| 83 | + $NUM_CLUSTERS_START_DELETE_OLDEST \ |
| 84 | + $DURATION_FOR_CLUSTER_DELETION \ |
| 85 | + $PR_ID \ |
| 86 | + $NGINX_INGRESS_ENABLED \ |
| 87 | + $DISABLE_SHOOT_DELETION \ |
| 88 | + $WORKERLESS \ |
| 89 | + &>"${RESOURCE_SHOOT_DIR}/create-shoot-cluster.log" & |
| 90 | + |
| 91 | +CREATE_SHOOT_PIDS+=($!) |
| 92 | + |
| 93 | +echo "Waiting until shoot clusters are ready" |
| 94 | +wait "${CREATE_SHOOT_PIDS[@]}" |
| 95 | + |
| 96 | +if [[ $? != 0 ]]; then |
| 97 | + echo "Creating the shoot clusters failed" |
| 98 | + echo "###### TARGET SHOOT LOG ######" |
| 99 | + cat "${TARGET_SHOOT_DIR}/create-shoot-cluster.log" |
| 100 | + echo "###### RESOURCE SHOOT LOG ######" |
| 101 | + cat "${RESOURCE_SHOOT_DIR}/create-shoot-cluster.log" |
| 102 | + exit 1 |
| 103 | +fi |
| 104 | + |
| 105 | +TARGET_SHOOT_KUBECONFIG_PATH="${TARGET_SHOOT_DIR}/kubeconfig.yaml" |
| 106 | +RESOURCE_SHOOT_KUBECONFIG_PATH="${RESOURCE_SHOOT_DIR}/kubeconfig.yaml" |
| 107 | +OIDC_ISSUER_URL_PATH="${RESOURCE_SHOOT_DIR}/oidc-issuer-url" |
| 108 | + |
| 109 | +echo "Target Shoot Cluster Name: $(cat ${TARGET_SHOOT_DIR}/clustername)" |
| 110 | +echo "Resource Shoot Cluster Name: $(cat ${RESOURCE_SHOOT_DIR}/clustername)" |
| 111 | + |
| 112 | +"${PROJECT_ROOT}/hack/int-test-helper/create-registry" $TARGET_SHOOT_KUBECONFIG_PATH $TARGET_SHOOT_DIR |
| 113 | +exit_on_error $? "create-registry failed" |
| 114 | + |
| 115 | +echo "Installing Landscaper" |
| 116 | +"${PROJECT_ROOT}/hack/int-test-helper/install-landscaper-dual" \ |
| 117 | + -w $TARGET_SHOOT_DIR \ |
| 118 | + -v $VERSION \ |
| 119 | + -t $TARGET_SHOOT_KUBECONFIG_PATH \ |
| 120 | + -r $RESOURCE_SHOOT_KUBECONFIG_PATH \ |
| 121 | + -i "$(cat ${TARGET_SHOOT_DIR}/ingress-domain)" |
| 122 | + |
| 123 | +exit_on_error $? "installing landscaper failed" |
| 124 | + |
| 125 | +"${PROJECT_ROOT}/hack/int-test-helper/run-tests" $RESOURCE_SHOOT_KUBECONFIG_PATH ${TARGET_SHOOT_DIR}/docker.config $VERSION true "$OIDC_ISSUER_URL_PATH" |
| 126 | +exit_on_error $? "run-tests failed" |
| 127 | + |
| 128 | +"${PROJECT_ROOT}/hack/int-test-helper/delete-shoot-cluster" $GARDENER_KUBECONFIG_PATH $NAMESPACE $TARGET_SHOOT_DIR |
| 129 | +"${PROJECT_ROOT}/hack/int-test-helper/delete-shoot-cluster" $GARDENER_KUBECONFIG_PATH $NAMESPACE $RESOURCE_SHOOT_DIR |
0 commit comments