From 82ba7194a4a5fbe9b0cf97a2aa7d7a5c5942b752 Mon Sep 17 00:00:00 2001 From: Muhammad Faizan Date: Thu, 18 Jan 2024 15:56:09 +0100 Subject: [PATCH] updated --- .../e2e-backend-switching-reuseable.yml | 7 ++-- .github/workflows/e2e.yml | 2 +- scripts/gardener/aws/get_random_region.sh | 35 +++++++++++++++++++ scripts/gardener/aws/provision.sh | 15 ++++++-- scripts/utils/utils.sh | 20 ++++++++++- 5 files changed, 72 insertions(+), 7 deletions(-) create mode 100755 scripts/gardener/aws/get_random_region.sh diff --git a/.github/workflows/e2e-backend-switching-reuseable.yml b/.github/workflows/e2e-backend-switching-reuseable.yml index e81ea464..cb6f9eb4 100644 --- a/.github/workflows/e2e-backend-switching-reuseable.yml +++ b/.github/workflows/e2e-backend-switching-reuseable.yml @@ -43,8 +43,6 @@ jobs: env: GARDENER_CLUSTER_VERSION: ${{ inputs.kube-version }} CLUSTER_PREFIX: ${{ inputs.cluster-name-prefix }} - GARDENER_REGION: "eu-west-1" - GARDENER_ZONES: "eu-west-1a" GARDENER_PROJECT_NAME: ${{ vars.GARDENER_PROJECT_NAME }} GARDENER_PROVIDER_SECRET_NAME: ${{ vars.GARDENER_PROVIDER_SECRET_NAME_AWS }} MACHINE_TYPE: "c4.xlarge" @@ -60,8 +58,11 @@ jobs: # generate cluster name and export it to Github env for cleanup step to access it. export CLUSTER_NAME="${CLUSTER_PREFIX}$(openssl rand -hex 2)" echo "CLUSTER_NAME=${CLUSTER_NAME}" >> $GITHUB_ENV + # set random region and zone information. + export GARDENER_REGION=$(./scripts/gardener/aws/get_random_region.sh) + export GARDENER_ZONES="${GARDENER_REGION}a" # provision gardener cluster. - make -C hack/ci/ provision-gardener-cluster + # make -C hack/ci/ provision-gardener-cluster kubectl version kubectl cluster-info kubectl get nodes diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 5ef450f2..c2f74155 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -182,7 +182,7 @@ jobs: backend-switching: needs: wait-until-build-succeeds - if: github.event_name == 'push' +# if: github.event_name == 'push' uses: "./.github/workflows/e2e-backend-switching-reuseable.yml" with: eventing-manager-image: ${{ needs.wait-until-build-succeeds.outputs.image-name }} diff --git a/scripts/gardener/aws/get_random_region.sh b/scripts/gardener/aws/get_random_region.sh new file mode 100755 index 00000000..7c28b7eb --- /dev/null +++ b/scripts/gardener/aws/get_random_region.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# This script returns a random AWS region name for Gardener cluster. +# Usage: No parameters are required to run this script. Simply call this script to get the region name. + +source "$(pwd)/scripts/utils/utils.sh" + +# standard bash error handling +set -o nounset # treat unset variables as an error and exit immediately. +set -E # needs to be set if we want the ERR trap. +set -o pipefail # prevents errors in a pipeline from being masked. +set -o errexit # exit immediately when a command fails. + +AWS_REGIONS=( + "eu-west-1" + "eu-west-2" + "eu-west-3" + "eu-central-1" + "eu-north-1" + "us-east-1" + "us-east-2" + "us-west-1" + "us-west-2" + "ca-central-1" + "sa-east-1" + "ap-northeast-1" + "ap-northeast-2" + "ap-northeast-3" +) + +## MAIN Logic +# NOTE: This script should only echo the result. +RAND_INDEX=$(utils::generate_random_number 0 $(( ${#AWS_REGIONS[@]} - 1 ))) +# print the random region name +echo ${AWS_REGIONS[$RAND_INDEX]} diff --git a/scripts/gardener/aws/provision.sh b/scripts/gardener/aws/provision.sh index c7f06ff8..e90b97d5 100755 --- a/scripts/gardener/aws/provision.sh +++ b/scripts/gardener/aws/provision.sh @@ -60,12 +60,23 @@ gardener::validate_and_default() { if [ -z "$GARDENER_CLUSTER_VERSION" ]; then # grep the default kube-version defined in kyma CLI. export GARDENER_CLUSTER_VERSION="$(${KYMA_CLI} provision gardener aws --help | grep "kube-version string" | awk -F "\"" '{print $2}')" - log::info "Using GARDENER_CLUSTER_VERSION=${GARDENER_CLUSTER_VERSION}" fi + + # print configurations for debugging purposes: + log::banner "Configurations:" + echo "CLUSTER_NAME${CLUSTER_NAME}" + echo "GARDENER_PROJECT_NAME: ${GARDENER_PROJECT_NAME}" + echo "GARDENER_REGION: ${GARDENER_REGION}" + echo "GARDENER_ZONES: ${GARDENER_ZONES}" + echo "MACHINE_TYPE: ${MACHINE_TYPE}" + echo "SCALER_MIN: ${SCALER_MIN}" + echo "SCALER_MAX: ${SCALER_MAX}" + echo "GARDENER_CLUSTER_VERSION: ${GARDENER_CLUSTER_VERSION}" + echo "RETRY_ATTEMPTS ${RETRY_ATTEMPTS}" } gardener::provision_cluster() { - log::info "Provision cluster: \"${CLUSTER_NAME}\"" + log::banner "Provision cluster: \"${CLUSTER_NAME}\"" # decreasing attempts to 2 because we will try to create new cluster from scratch on exit code other than 0 ${KYMA_CLI} provision gardener aws \ diff --git a/scripts/utils/utils.sh b/scripts/utils/utils.sh index d299bc5d..9ab17c26 100755 --- a/scripts/utils/utils.sh +++ b/scripts/utils/utils.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source "${PROJECT_ROOT}/scripts/utils/log.sh" +source "$(pwd)/scripts/utils/log.sh" # utils::check_required_vars checks if all provided variables are initialized # Arguments @@ -18,3 +18,21 @@ function utils::check_required_vars() { exit 1 fi } + +# utils::generate_random_number generates a random number between provided range. +# Arguments +# $1 - minimum +# $2 - maximum +# Example: utils::generate_random_number +function utils::generate_random_number() { + # NOTE: This method should only echo the result. + if [ "$#" -ne 2 ] + then + log::error "Invalid arguments. Usage: utils::generate_random_number " + exit 1 + fi + + local min=$1 + local max=$2 + echo $(awk -v seed=$RANDOM "BEGIN{srand(seed); print int(rand()*($max-$min+1))+$min}") +}