Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
mfaizanse committed Jan 18, 2024
1 parent b7f57fe commit 82ba719
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 7 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/e2e-backend-switching-reuseable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
35 changes: 35 additions & 0 deletions scripts/gardener/aws/get_random_region.sh
Original file line number Diff line number Diff line change
@@ -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]}
15 changes: 13 additions & 2 deletions scripts/gardener/aws/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
20 changes: 19 additions & 1 deletion scripts/utils/utils.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <minimum> <maximum>
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 <minimum> <maximum>"
exit 1
fi

local min=$1
local max=$2
echo $(awk -v seed=$RANDOM "BEGIN{srand(seed); print int(rand()*($max-$min+1))+$min}")
}

0 comments on commit 82ba719

Please sign in to comment.