From e4f48f5cebef7c07fddd41eb0d7063633138ecaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Mac=C3=ADk?= Date: Mon, 27 Nov 2023 16:44:07 +0100 Subject: [PATCH] bump rhdh version and fix keycloak token handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pavel MacĂ­k --- Makefile | 2 +- ci-scripts/collect-results.sh | 2 +- ci-scripts/rhdh-setup/create_resource.sh | 21 +++++++++------------ ci-scripts/rhdh-setup/deploy.sh | 6 +++++- ci-scripts/setup.sh | 18 ++++++++++-------- ci-scripts/test.sh | 2 +- 6 files changed, 27 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 7d4dec0..b61f109 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ export SPAWN_RATE ?= 20 # RHDH image to deploy export RHDH_IMAGE_REGISTRY ?= quay.io export RHDH_IMAGE_REPO ?= rhdh/rhdh-hub-rhel9 -export RHDH_IMAGE_TAG ?= 1.0-190 +export RHDH_IMAGE_TAG ?= 1.0-191 # RHDH Helm chart to deploy export RHDH_NAMESPACE ?= rhdh-performance diff --git a/ci-scripts/collect-results.sh b/ci-scripts/collect-results.sh index c028fef..63a110d 100755 --- a/ci-scripts/collect-results.sh +++ b/ci-scripts/collect-results.sh @@ -4,7 +4,7 @@ set -o nounset set -o errexit set -o pipefail -echo "\n === Collecting test results and metrics ===\n" +echo -e "\n === Collecting test results and metrics ===\n" ARTIFACT_DIR=${ARTIFACT_DIR:-artifacts} monitoring_collection_data=$ARTIFACT_DIR/benchmark.json diff --git a/ci-scripts/rhdh-setup/create_resource.sh b/ci-scripts/rhdh-setup/create_resource.sh index 5a39979..0cbe6fc 100755 --- a/ci-scripts/rhdh-setup/create_resource.sh +++ b/ci-scripts/rhdh-setup/create_resource.sh @@ -20,7 +20,7 @@ function backstage_url() { cat $f } -export -f keycloak_url backstage_url +export keycloak_url backstage_url function create_per_grp() { varname=$2 @@ -81,7 +81,7 @@ function create_cmp() { } function create_group() { - token=$(cat $TMP_DIR/token) + token=$(get_token) curl -s -k --location --request POST "$(keycloak_url)/auth/admin/realms/backstage/groups" \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer '$token \ @@ -90,8 +90,6 @@ function create_group() { function create_groups() { echo "Creating Groups in Keycloak" - export -f get_token - nohup bash -c 'get_token' & refresh_pid=$! sleep 5 export -f create_group @@ -100,7 +98,7 @@ function create_groups() { } function create_user() { - token=$(cat $TMP_DIR/token) + token=$(get_token) grp=$(echo "${0}%${GROUP_COUNT}" | bc) [[ $grp -eq 0 ]] && grp=${GROUP_COUNT} curl -s -k --location --request POST "$(keycloak_url)/auth/admin/realms/backstage/users" \ @@ -111,9 +109,7 @@ function create_user() { function create_users() { echo "Creating Users in Keycloak" - export -f get_token export GROUP_COUNT - nohup bash -c 'get_token' & refresh_pid=$! sleep 5 export -f create_user @@ -122,9 +118,10 @@ function create_users() { } function get_token() { - keycloak_pass=$(oc -n ${RHDH_NAMESPACE} get secret credential-example-sso -o template --template='{{.data.ADMIN_PASSWORD}}' | base64 -d) - while true; do - curl -s -k "$(keycloak_url)/auth/realms/master/protocol/openid-connect/token" -d "username=admin" -d "password=${keycloak_pass}" -d 'grant_type=password' -d 'client_id=admin-cli' | jq -r .access_token >$TMP_DIR/token - sleep 30 - done + token_file=$TMP_DIR/token.json + if [ ! -f $token_file ] || [ $(date +%s) -gt $(jq -rc '.expires_in_timestamp' $token_file) ]; then + keycloak_pass=$(oc -n ${RHDH_NAMESPACE} get secret credential-example-sso -o template --template='{{.data.ADMIN_PASSWORD}}' | base64 -d) + curl -s -k $(keycloak_url)/auth/realms/master/protocol/openid-connect/token -d username=admin -d password=${keycloak_pass} -d 'grant_type=password' -d 'client_id=admin-cli' | jq -r ".expires_in_timestamp = $(date -d '30 seconds' +%s)" >$token_file + fi + jq -rc '.access_token' $token_file } diff --git a/ci-scripts/rhdh-setup/deploy.sh b/ci-scripts/rhdh-setup/deploy.sh index 87d7359..6f86385 100755 --- a/ci-scripts/rhdh-setup/deploy.sh +++ b/ci-scripts/rhdh-setup/deploy.sh @@ -20,7 +20,7 @@ export RHDH_KEYCLOAK_REPLICAS=${RHDH_KEYCLOAK_REPLICAS:-1} export RHDH_IMAGE_REGISTRY=${RHDH_IMAGE_REGISTRY:-quay.io} export RHDH_IMAGE_REPO=${RHDH_IMAGE_REPO:-rhdh/rhdh-hub-rhel9} -export RHDH_IMAGE_TAG=${RHDH_IMAGE_TAG:-1.0-190} +export RHDH_IMAGE_TAG=${RHDH_IMAGE_TAG:-1.0-191} export RHDH_HELM_REPO=${RHDH_HELM_REPO:-https://gist.githubusercontent.com/rhdh-bot/63cef5cb6285889527bd6a67c0e1c2a9/raw} export RHDH_HELM_CHART=${RHDH_HELM_CHART:-developer-hub} @@ -32,6 +32,10 @@ export API_COUNT="${API_COUNT:-1}" export COMPONENT_COUNT="${COMPONENT_COUNT:-1}" delete() { + if ! $cli get ns $RHDH_NAMESPACE >/dev/null; then + echo "$RHDH_NAMESPACE namespace does not exit... Skipping. " + return + fi for cr in keycloakusers keycloakclients keycloakrealms keycloaks; do for res in $($clin get $cr.keycloak.org -o name); do $clin patch $res -p '{"metadata":{"finalizers":[]}}' --type=merge diff --git a/ci-scripts/setup.sh b/ci-scripts/setup.sh index 9c792aa..8c7e5d0 100755 --- a/ci-scripts/setup.sh +++ b/ci-scripts/setup.sh @@ -4,7 +4,7 @@ set -o nounset set -o errexit set -o pipefail -echo "\n === Installing and setting up RHDH ===\n" +echo -e "\n === Installing and setting up RHDH ===\n" export GITHUB_TOKEN GITHUB_USER GITHUB_REPO QUAY_TOKEN KUBECONFIG @@ -13,14 +13,16 @@ GITHUB_USER=$(cat /usr/local/ci-secrets/backstage-performance/github.user) GITHUB_REPO=$(cat /usr/local/ci-secrets/backstage-performance/github.repo) QUAY_TOKEN=$(cat /usr/local/ci-secrets/backstage-performance/quay.token) -export RHDH_DEPLOYMENT_REPLICAS=5 -export RHDH_DB_REPLICAS=5 -export RHDH_KEYCLOAK_REPLICAS=5 +export RHDH_DEPLOYMENT_REPLICAS=2 +export RHDH_DB_REPLICAS=2 +export RHDH_KEYCLOAK_REPLICAS=2 -export API_COUNT=10000 -export COMPONENT_COUNT=10000 -export BACKSTAGE_USER_COUNT=10000 -export GROUP_COUNT=1000 +export API_COUNT=1000 +export COMPONENT_COUNT=1000 +export BACKSTAGE_USER_COUNT=1000 +export GROUP_COUNT=100 + +make undeploy-rhdh echo "$(date --utc -Ins) Running deployment script" make ci-deploy diff --git a/ci-scripts/test.sh b/ci-scripts/test.sh index b211b93..876ff2e 100755 --- a/ci-scripts/test.sh +++ b/ci-scripts/test.sh @@ -4,7 +4,7 @@ set -o nounset set -o errexit set -o pipefail -echo "\n === Executing RHDH load test ===\n" +echo -e "\n === Executing RHDH load test ===\n" export SCENARIO