From c3c11d3293d99aa8a8b28c6b42ec4701a8a408b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Mac=C3=ADk?= Date: Wed, 22 Nov 2023 15:10:42 +0100 Subject: [PATCH] test(RHIDP-460): update rhdh-setup and add search-catalog scenario MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pavel MacĂ­k --- .github/workflows/pr-checks.yaml | 3 - .gitignore | 4 +- Makefile | 47 +++-- add-dockercfg-docker.io.sh | 8 - ci-scripts/collect-results.sh | 37 +++- ci-scripts/rhdh-setup/.gitignore | 1 + ci-scripts/rhdh-setup/README.md | 11 +- ci-scripts/rhdh-setup/create_resource.sh | 163 ++++++++++------ ci-scripts/rhdh-setup/deploy.sh | 174 +++++++++++------- .../template/backstage/app-config.yaml | 3 +- .../chart-values.image-override.yaml | 156 ++++++++++++++++ .../template/backstage/chart-values.yaml | 12 +- ci-scripts/setup.sh | 55 +++++- ci-scripts/test.sh | 47 ++++- scenarios/search-catalog.py | 58 ++++++ 15 files changed, 589 insertions(+), 190 deletions(-) delete mode 100755 add-dockercfg-docker.io.sh create mode 100644 ci-scripts/rhdh-setup/template/backstage/chart-values.image-override.yaml create mode 100644 scenarios/search-catalog.py diff --git a/.github/workflows/pr-checks.yaml b/.github/workflows/pr-checks.yaml index 1e97625..e780468 100644 --- a/.github/workflows/pr-checks.yaml +++ b/.github/workflows/pr-checks.yaml @@ -24,6 +24,3 @@ jobs: - name: Run linters run: make lint - - - name: Run ShellCheck - uses: ludeeus/action-shellcheck@master diff --git a/.gitignore b/.gitignore index 73d31d7..58408d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ +**/.tmp/* .venv .vscode -.rhdh-setup.git* benchmark-scenario benchmark-before benchmark-after load-test.log -shellcheck \ No newline at end of file +shellcheck diff --git a/Makefile b/Makefile index b0e8f37..f36300e 100644 --- a/Makefile +++ b/Makefile @@ -16,15 +16,16 @@ export DURATION ?= 1m # Used to set --spawn-rate option of locust CLI (Rate to spawn users at (users per second)). See https://docs.locust.io/en/stable/configuration.html#command-line-options for details 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-162 +# RHDH image to deploy. Uncomment and set to override RHDH image to deploy and test. +export RHDH_IMAGE_REGISTRY ?= +export RHDH_IMAGE_REPO ?= +export RHDH_IMAGE_TAG ?= # RHDH Helm chart to deploy export RHDH_NAMESPACE ?= rhdh-performance -export RHDH_HELM_REPO ?= https://gist.githubusercontent.com/nickboldt/a8483eb244f9c4286798e85accaa70af/raw/ +export RHDH_HELM_REPO ?= https://gist.githubusercontent.com/rhdh-bot/63cef5cb6285889527bd6a67c0e1c2a9/raw export RHDH_HELM_CHART ?= developer-hub +export RHDH_HELM_CHART_VERSION ?= export RHDH_HELM_RELEASE_NAME ?= rhdh # RHDH horizontal scaling @@ -35,6 +36,9 @@ export RHDH_KEYCLOAK_REPLICAS ?= 1 # python's venv base dir relative to the root of the repository PYTHON_VENV=.venv +# Local directory to store temporary files +export TMP_DIR=$(shell readlink -m .tmp) + # Name of the namespace to install locust operator as well as to run Pods of master and workers. LOCUST_NAMESPACE=locust-operator @@ -64,12 +68,17 @@ namespace: ## Deploy RHDH .PHONY: deploy-rhdh deploy-rhdh: - ./ci-scripts/setup.sh + cd ./ci-scripts/rhdh-setup/; ./deploy.sh -i + +## Create users, groups and objects such as components and APIs in RHDH +.PHONY: populate-rhdh +populate-rhdh: + cd ./ci-scripts/rhdh-setup/; ./deploy.sh -c ## Undeploy RHDH .PHONY: undeploy-rhdh undeploy-rhdh: - ./ci-scripts/rhdh-setup/deploy.sh -d + cd ./ci-scripts/rhdh-setup/; ./deploy.sh -d ## === Locust Operator === @@ -93,18 +102,12 @@ undeploy-locust: clean @kubectl delete namespace $(LOCUST_NAMESPACE) --wait @helm repo remove $(LOCUST_OPERATOR_REPO) -## Add docker.io token to default-dockercfg-* Secret to avoid pull rate limits from docker.io -## Run `make add-dockerio DOCKERIO_TOKEN=...` -.PHONY: add-dockerio -add-dockerio: namespace - @TOKEN=$(DOCKERIO_TOKEN) NAMESPACE=$(LOCUST_NAMESPACE) ./add-dockercfg-docker.io.sh - ## === Testing === ## Remove test related resources from cluster -## Run `make clean SCENARIO=...` to clean a specific scenario -.PHONY: clean -clean: +## Run `make clean-test SCENARIO=...` to clean a specific scenario from cluster +.PHONY: clean-test +clean-test: kubectl delete --namespace $(LOCUST_NAMESPACE) cm locust.$(SCENARIO) --ignore-not-found --wait kubectl delete --namespace $(LOCUST_NAMESPACE) locusttests.locust.io $(SCENARIO).test --ignore-not-found --wait || true @@ -132,12 +135,17 @@ shellcheck: ## Run all linters .PHONY: lint lint: shellcheck + shellcheck $$(find -name '*.sh') ## === CI === ## Run the load test in CI end to end .PHONY: ci-run -ci-run: setup-venv deploy-locust add-dockerio test +ci-run: setup-venv deploy-locust test + +## Deploy and populate RHDH in CI end to end +.PHONY: ci-deploy +ci-deploy: clean namespace deploy-rhdh ## === Maintanence === @@ -149,6 +157,11 @@ update-locust-images: skopeo copy --src-no-creds docker://docker.io/containersol/locust_exporter:latest docker://quay.io/backstage-performance/locust_exporter:latest skopeo copy --src-no-creds docker://docker.io/lotest/locust-k8s-operator:latest docker://quay.io/backstage-performance/locust-k8s-operator:latest +## Clean local resources +.PHONY: clean +clean: + rm -rvf *.log benchmark-* shellcheck ci-scripts/rhdh-setup/.tmp $(TMP_DIR) + ## === Help === ## Print help message for all Makefile targets diff --git a/add-dockercfg-docker.io.sh b/add-dockercfg-docker.io.sh deleted file mode 100755 index 6260d76..0000000 --- a/add-dockercfg-docker.io.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -ns="${NAMESPACE:-locust-operator}" - -for s in builder default deployer locust-operator-locust-k8s-operator; do - secret=$(kubectl get --namespace "$ns" secret -o json | jq -rc '.items[] | select(.metadata.name | startswith("'"${s}"'-dockercfg")).metadata.name') - kubectl patch --namespace "$ns" secret $secret --type=merge -p '{"data": {".dockercfg" :"'$(kubectl get --namespace "$ns" secret $secret -o json | jq -r '.data | map_values(@base64d).".dockercfg"' | jq -rc '."https://index.docker.io/v1/".auth = "'${TOKEN}'"' | base64 -w0)'"}}' -done diff --git a/ci-scripts/collect-results.sh b/ci-scripts/collect-results.sh index 7fe62d3..67971fc 100755 --- a/ci-scripts/collect-results.sh +++ b/ci-scripts/collect-results.sh @@ -4,19 +4,41 @@ set -o nounset set -o errexit set -o pipefail +echo -e "\n === Collecting test results and metrics ===\n" + ARTIFACT_DIR=${ARTIFACT_DIR:-artifacts} +mkdir -p "${ARTIFACT_DIR}" + monitoring_collection_data=$ARTIFACT_DIR/benchmark.json monitoring_collection_log=$ARTIFACT_DIR/monitoring-collection.log monitoring_collection_dir=$ARTIFACT_DIR/monitoring-collection-raw-data-dir mkdir -p "$monitoring_collection_dir" -cp -vf load-test.log $ARTIFACT_DIR/load-test.log +try_gather_file() { + if [ -f "$1" ]; then + cp -vf "$1" "${2:-$ARTIFACT_DIR}" + else + echo "WARNING: Tried to gather $1 but the file was not found!" + fi +} + +try_gather_dir() { + if [ -d "$1" ]; then + cp -rvf "$1" "${2:-$ARTIFACT_DIR}" + else + echo "WARNING: Tried to gather $1 but the directory was not found!" + fi +} + +try_gather_dir .tmp +try_gather_file load-test.log PYTHON_VENV_DIR=.venv echo "$(date --utc -Ins) Setting up tool to collect monitoring data" python3 -m venv $PYTHON_VENV_DIR set +u +# shellcheck disable=SC1090,SC1091 source $PYTHON_VENV_DIR/bin/activate set -u python3 -m pip install --quiet -U pip @@ -27,20 +49,21 @@ set -u echo "$(date --utc -Ins) Collecting monitoring data" set +u +# shellcheck disable=SC1090,SC1091 source $PYTHON_VENV_DIR/bin/activate set -u mstart=$(date --utc --date "$(cat benchmark-before)" --iso-8601=seconds) mend=$(date --utc --date "$(cat benchmark-after)" --iso-8601=seconds) mhost=$(kubectl -n openshift-monitoring get route -l app.kubernetes.io/name=thanos-query -o json | jq --raw-output '.items[0].spec.host') -mversion=$(sed -n 's/^__version__ = "\(.*\)"/\1/p' scenarios/$(cat benchmark-scenario).py) +mversion=$(sed -n 's/^__version__ = "\(.*\)"/\1/p' "scenarios/$(cat benchmark-scenario).py") status_data.py \ --status-data-file "$monitoring_collection_data" \ --set \ - results.started="$(cat benchmark-before)" \ - results.ended="$(cat benchmark-after)" \ - name="RHDH load test $(cat benchmark-scenario)" \ - metadata.scenario.name="$(cat benchmark-scenario)" \ - metadata.scenario.version="$mversion" \ + results.started="$(cat benchmark-before)" \ + results.ended="$(cat benchmark-after)" \ + name="RHDH load test $(cat benchmark-scenario)" \ + metadata.scenario.name="$(cat benchmark-scenario)" \ + metadata.scenario.version="$mversion" \ -d &>"$monitoring_collection_log" status_data.py \ --status-data-file "$monitoring_collection_data" \ diff --git a/ci-scripts/rhdh-setup/.gitignore b/ci-scripts/rhdh-setup/.gitignore index abd9126..d6b5d45 100644 --- a/ci-scripts/rhdh-setup/.gitignore +++ b/ci-scripts/rhdh-setup/.gitignore @@ -1,2 +1,3 @@ +nohup.out app-config.yaml config.yaml diff --git a/ci-scripts/rhdh-setup/README.md b/ci-scripts/rhdh-setup/README.md index e6ce985..5bdd530 100644 --- a/ci-scripts/rhdh-setup/README.md +++ b/ci-scripts/rhdh-setup/README.md @@ -1,7 +1,14 @@ # rhdh-setup -Run `./deploy.sh` to setup backstage with keycloak. -The script expects `QUAY_TOKEN` and `GITHUB_TOKEN` to be set. +Run `./deploy.sh -i` to install backstage with keycloak. + +The script expects follwoing environmental variables to be set: +* `QUAY_TOKEN` +* `GITHUB_TOKEN` +* `GITHUB_USER` +* `GITHUB_REPO` Run with `-r` to delete backstage and redeploy again `./deploy.sh -r`. This is used to syc up users and groups from keycloak. Run with `-d` to delete backstage only. + +Run with `-c` to create objects (Users, Groups, Components and APIs). diff --git a/ci-scripts/rhdh-setup/create_resource.sh b/ci-scripts/rhdh-setup/create_resource.sh index e24159a..fd1183a 100755 --- a/ci-scripts/rhdh-setup/create_resource.sh +++ b/ci-scripts/rhdh-setup/create_resource.sh @@ -1,109 +1,156 @@ -#/bin/bash +#!/bin/bash + +export TMP_DIR WORKDIR + +TMP_DIR=${TMP_DIR:-$(readlink -m .tmp)} +mkdir -p "$TMP_DIR" +WORKDIR=$(readlink -m .) + +kc_lockfile="$TMP_DIR/kc.lockfile" + +keycloak_url() { + f="$TMP_DIR/keycloak.url" + exec 4>"$kc_lockfile" + flock 4 || { + echo "Failed to acquire lock" + exit 1 + } + + if [ ! -f "$f" ]; then + echo -n "https://$(oc get routes keycloak -n "${RHDH_NAMESPACE}" -o jsonpath='{.spec.host}')" >"$f" + fi + cat "$f" + set +x +} + +bs_lockfile="$TMP_DIR/bs.lockfile" + +backstage_url() { + f="$TMP_DIR/backstage.url" + exec 5>"$bs_lockfile" + flock 5 || { + echo "Failed to acquire lock" + exit 1 + } + if [ ! -f "$f" ]; then + echo -n "https://$(oc get routes "${RHDH_HELM_RELEASE_NAME}-developer-hub" -n "${RHDH_NAMESPACE}" -o jsonpath='{.spec.host}')" >"$f" + fi + flock -u 5 + cat "$f" +} create_per_grp() { varname=$2 obj_count=${!varname} - if [[ -z ${!varname} ]] ; then - echo "$varname is not set: Skipping $1 "; + if [[ -z ${!varname} ]]; then + echo "$varname is not set: Skipping $1 " exit 1 fi - local iter_count=`echo "(${obj_count}/${GROUP_COUNT})"|bc` - local mod=`echo "(${obj_count}%${GROUP_COUNT})"|bc` + local iter_count mod + iter_count=$(echo "(${obj_count}/${GROUP_COUNT})" | bc) + mod=$(echo "(${obj_count}%${GROUP_COUNT})" | bc) - if [[ ! ${mod} -eq 0 ]] ; then - iter_count=`echo "${iter_count}+1"|bc` + if [[ ! ${mod} -eq 0 ]]; then + iter_count=$(echo "${iter_count}+1" | bc) fi indx=0 - for i in `seq 1 $((${iter_count}))`; do - for j in `seq 1 $((${GROUP_COUNT}))`; do - indx=$((1+indx)) - [[ ${obj_count} -lt $indx ]] && break - local out=$(${1} ${j} ${indx}) + for _ in $(seq 1 "${iter_count}"); do + for g in $(seq 1 "${GROUP_COUNT}"); do + indx=$((1 + indx)) + [[ ${obj_count} -lt $indx ]] && break + $1 "$g" "$indx" done done } clone_and_upload() { - export backstage_url="https://$(oc get routes ${RHDH_HELM_RELEASE_NAME}-developer-hub -n ${RHDH_NAMESPACE} -o jsonpath='{.spec.host}')" git_str="${GITHUB_USER}:${GITHUB_TOKEN}@github.com" - base_name=`basename $GITHUB_REPO` - git_dir=${base_name%%.*} - git_repo=`echo $GITHUB_REPO|sed -e "s/github.com/${git_str}/g"` - [[ -d ${git_dir} ]] && rm -rf ${git_dir} - git clone $git_repo - cd $git_dir - tmp_branch=`mktemp -u XXXXXXXXXX` - git checkout -b $tmp_branch - mv ../${1} . - git add ${1} + base_name=$(basename "$GITHUB_REPO") + git_dir=$TMP_DIR/${base_name} + git_repo=${GITHUB_REPO//github.com/${git_str}} + [[ -d "${git_dir}" ]] && rm -rf "${git_dir}" + git clone "$git_repo" "$git_dir" + cd "$git_dir" || return + git config user.name "rhdh-performance-bot" + git config user.email rhdh-performance-bot@redhat.com + tmp_branch=$(mktemp -u XXXXXXXXXX) + git checkout -b "$tmp_branch" + mv -vf "$1" . + filename=$(basename "$1") + git add "$filename" git commit -a -m "commit objects" - git push -f --set-upstream origin $tmp_branch + git push -f --set-upstream origin "$tmp_branch" cd .. sleep 5 - upload_url=${GITHUB_REPO%.*}/blob/${tmp_branch}/${1} - curl -k ${backstage_url}'/api/catalog/locations' -X POST -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' --data-raw '{"type":"url","target":"'"${upload_url}"'"}' + upload_url="${GITHUB_REPO%.*}/blob/${tmp_branch}/${filename}" + curl -k "$(backstage_url)/api/catalog/locations" -X POST -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' --data-raw '{"type":"url","target":"'"${upload_url}"'"}' } +# shellcheck disable=SC2016 create_api() { - export grp_indx=$1 + export grp_indx=$1 export api_indx=$2 - cat template/component/api.template | envsubst '${grp_indx} ${api_indx}'>> api.yaml + envsubst '${grp_indx} ${api_indx}' <"$WORKDIR/template/component/api.template" >>"$TMP_DIR/api.yaml" } +# shellcheck disable=SC2016 create_cmp() { - export grp_indx=$1 + export grp_indx=$1 export cmp_indx=$2 - cat template/component/component.template | envsubst '${grp_indx} ${cmp_indx}'>> component.yaml + envsubst '${grp_indx} ${cmp_indx}' <"$WORKDIR/template/component/component.template" >>"$TMP_DIR/component.yaml" } create_group() { - token=`cat /tmp/token` - curl -s -k --location --request POST ${keycloak_url}'/auth/admin/realms/backstage/groups' \ - -H 'Content-Type: application/json' \ - -H 'Authorization: Bearer '$token \ - --data-raw '{"name": "group'"${0}"'"}' + 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" \ + --data-raw '{"name": "group'"${0}"'"}' } create_groups() { echo "Creating Groups in Keycloak" - export keycloak_url="https://$(oc get routes keycloak -n ${RHDH_NAMESPACE} -o jsonpath='{.spec.host}')" - export keycloak_pass=$(oc -n ${RHDH_NAMESPACE} get secret credential-example-sso -o template --template='{{.data.ADMIN_PASSWORD}}'|base64 -d) - export -f get_token - nohup bash -c 'get_token' & refresh_pid=$! sleep 5 - export -f create_group - seq 1 ${GROUP_COUNT}| xargs -n1 -P10 bash -c 'create_group' + seq 1 "${GROUP_COUNT}" | xargs -n1 -P10 bash -c 'create_group' kill $refresh_pid } create_user() { - token=`cat /tmp/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' \ - -H 'Content-Type: application/json' \ - -H 'Authorization: Bearer '$token \ - --data-raw '{"firstName":"test'"${0}"'","lastName":"tester", "email":"test'"${0}"'@test.com", "enabled":"true", "username":"test'"${0}"'","groups":["/group'"${grp}"'"]}' + 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" \ + -H 'Content-Type: application/json' \ + -H 'Authorization: Bearer '"$token" \ + --data-raw '{"firstName":"test'"${0}"'","lastName":"tester", "email":"test'"${0}"'@test.com", "enabled":"true", "username":"test'"${0}"'","groups":["/group'"${grp}"'"]}' } create_users() { echo "Creating Users in Keycloak" - export keycloak_url="https://$(oc get routes keycloak -n ${RHDH_NAMESPACE} -o jsonpath='{.spec.host}')" - export keycloak_pass=$(oc -n ${RHDH_NAMESPACE} get secret credential-example-sso -o template --template='{{.data.ADMIN_PASSWORD}}'|base64 -d) - export -f get_token export GROUP_COUNT - nohup bash -c 'get_token' & refresh_pid=$! sleep 5 - export -f create_user - seq 1 ${BACKSTAGE_USER_COUNT}| xargs -n1 -P10 bash -c 'create_user' + seq 1 "${BACKSTAGE_USER_COUNT}" | xargs -n1 -P10 bash -c 'create_user' kill $refresh_pid } +token_lockfile="$TMP_DIR/token.lockfile" + get_token() { - while true; do - echo -n $(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/token - sleep 30 - done + token_file=$TMP_DIR/token.json + exec 3>"$token_lockfile" + flock 3 || { + echo "Failed to acquire lock" + exit 1 + } + 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 + flock -u 3 + jq -rc '.access_token' "$token_file" } + +export -f keycloak_url backstage_url backstage_url get_token create_group create_user +export kc_lockfile bs_lockfile token_lockfile diff --git a/ci-scripts/rhdh-setup/deploy.sh b/ci-scripts/rhdh-setup/deploy.sh index b1bda6f..81fa2c9 100755 --- a/ci-scripts/rhdh-setup/deploy.sh +++ b/ci-scripts/rhdh-setup/deploy.sh @@ -1,12 +1,13 @@ #!/bin/bash set -uo pipefail +# shellcheck disable=SC1091 source ./create_resource.sh -[ -z ${QUAY_TOKEN} ] -[ -z ${GITHUB_TOKEN} ] -[ -z ${GITHUB_USER} ] -[ -z ${GITHUB_REPO} ] +[ -z "${QUAY_TOKEN}" ] +[ -z "${GITHUB_TOKEN}" ] +[ -z "${GITHUB_USER}" ] +[ -z "${GITHUB_REPO}" ] export RHDH_NAMESPACE=${RHDH_NAMESPACE:-rhdh-performance} export RHDH_HELM_RELEASE_NAME=${RHDH_HELM_RELEASE_NAME:-rhdh} @@ -14,16 +15,19 @@ export RHDH_HELM_RELEASE_NAME=${RHDH_HELM_RELEASE_NAME:-rhdh} cli="oc" clin="$cli -n $RHDH_NAMESPACE" +repo_name="$RHDH_NAMESPACE-helm-repo" + export RHDH_DEPLOYMENT_REPLICAS=${RHDH_DEPLOYMENT_REPLICAS:-1} export RHDH_DB_REPLICAS=${RHDH_DB_REPLICAS:-1} 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-162} +export RHDH_IMAGE_REGISTRY=${RHDH_IMAGE_REGISTRY:-} +export RHDH_IMAGE_REPO=${RHDH_IMAGE_REPO:-} +export RHDH_IMAGE_TAG=${RHDH_IMAGE_TAG:-} -export RHDH_HELM_REPO=${RHDH_HELM_REPO:-https://gist.githubusercontent.com/nickboldt/a8483eb244f9c4286798e85accaa70af/raw} #v1.0-162 +export RHDH_HELM_REPO=${RHDH_HELM_REPO:-https://gist.githubusercontent.com/rhdh-bot/63cef5cb6285889527bd6a67c0e1c2a9/raw} export RHDH_HELM_CHART=${RHDH_HELM_CHART:-developer-hub} +export RHDH_HELM_CHART_VERSION=${RHDH_HELM_CHART_VERSION:-} export PRE_LOAD_DB="${PRE_LOAD_DB:-true}" export BACKSTAGE_USER_COUNT="${BACKSTAGE_USER_COUNT:-1}" @@ -31,59 +35,91 @@ export GROUP_COUNT="${GROUP_COUNT:-1}" export API_COUNT="${API_COUNT:-1}" export COMPONENT_COUNT="${COMPONENT_COUNT:-1}" +wait_to_start() { + resource=${1:-deployment} + name=${2:-name} + initial_timeout=${3:-300} + wait_timeout=${4:-300} + rn=$resource/$name + description=${5:-$rn} + timeout_timestamp=$(date -d "$initial_timeout seconds" "+%s") + while ! /bin/bash -c "$clin get $rn -o name"; do + if [ "$(date "+%s")" -gt "$timeout_timestamp" ]; then + echo "ERROR: Timeout waiting for $description to start" + exit 1 + else + echo "Waiting for $description to start..." + sleep 5s + fi + done + $clin rollout status "$rn" --timeout="${wait_timeout}s" +} + 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 - $clin delete $res --wait + for res in $($clin get "$cr.keycloak.org" -o name); do + $clin patch "$res" -p '{"metadata":{"finalizers":[]}}' --type=merge + $clin delete "$res" --wait done done - helm uninstall ${RHDH_HELM_RELEASE_NAME} --namespace ${RHDH_NAMESPACE} - $clin delete pvc data-${RHDH_HELM_RELEASE_NAME}-postgresql-0 --ignore-not-found - $cli delete ns ${RHDH_NAMESPACE} --wait + helm uninstall "${RHDH_HELM_RELEASE_NAME}" --namespace "${RHDH_NAMESPACE}" + $clin delete pvc "data-${RHDH_HELM_RELEASE_NAME}-postgresql-0" --ignore-not-found + $cli delete ns "${RHDH_NAMESPACE}" --wait + helm repo remove "${repo_name}" || true } keycloak_install() { - $cli create namespace ${RHDH_NAMESPACE} --dry-run=client -o yaml | $cli apply -f - - export KEYCLOAK_CLIENT_SECRET=$(mktemp -u XXXXXXXXXX) - cat template/keycloak/keycloak-op.yaml | envsubst | $clin apply -f - + $cli create namespace "${RHDH_NAMESPACE}" --dry-run=client -o yaml | $cli apply -f - + export KEYCLOAK_CLIENT_SECRET + KEYCLOAK_CLIENT_SECRET=$(mktemp -u XXXXXXXXXX) + envsubst