-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update rhdh-setup and add search-catalog scenario
Signed-off-by: Pavel Macík <[email protected]>
- Loading branch information
Showing
9 changed files
with
182 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
.venv | ||
.vscode | ||
.rhdh-setup.git* | ||
benchmark-scenario | ||
benchmark-before | ||
benchmark-after | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.tmp | ||
nohup.out | ||
app-config.yaml | ||
config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,128 @@ | ||
#/bin/bash | ||
#!/bin/bash | ||
|
||
create_per_grp() { | ||
export TMP_DIR=$(readlink -m .tmp) | ||
mkdir -p $TMP_DIR | ||
|
||
function keycloak_url() { | ||
f=$TMP_DIR/keycloak.url | ||
if [ ! -f $f ]; then | ||
echo -n "https://$(oc get routes keycloak -n ${RHDH_NAMESPACE} -o jsonpath='{.spec.host}')" >$f | ||
fi | ||
cat $f | ||
} | ||
|
||
function backstage_url() { | ||
f=$TMP_DIR/backstage.url | ||
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 | ||
cat $f | ||
} | ||
|
||
export -f keycloak_url backstage_url | ||
|
||
function 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=$(echo "(${obj_count}/${GROUP_COUNT})" | bc) | ||
local 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 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}) | ||
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}')" | ||
function clone_and_upload() { | ||
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"` | ||
base_name=$(basename $GITHUB_REPO) | ||
git_dir=$TMP_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` | ||
tmp_branch=$(mktemp -u XXXXXXXXXX) | ||
git checkout -b $tmp_branch | ||
mv ../${1} . | ||
git add ${1} | ||
mv -vf ${1} . | ||
filename=$(basename ${1}) | ||
git add $filename | ||
git commit -a -m "commit objects" | ||
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}"'"}' | ||
} | ||
|
||
create_api() { | ||
export grp_indx=$1 | ||
function create_api() { | ||
export grp_indx=$1 | ||
export api_indx=$2 | ||
cat template/component/api.template | envsubst '${grp_indx} ${api_indx}'>> api.yaml | ||
cat template/component/api.template | envsubst '${grp_indx} ${api_indx}' >>$TMP_DIR/api.yaml | ||
} | ||
|
||
create_cmp() { | ||
export grp_indx=$1 | ||
function create_cmp() { | ||
export grp_indx=$1 | ||
export cmp_indx=$2 | ||
cat template/component/component.template | envsubst '${grp_indx} ${cmp_indx}'>> component.yaml | ||
cat template/component/component.template | envsubst '${grp_indx} ${cmp_indx}' >>$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}"'"}' | ||
function create_group() { | ||
token=$(cat $TMP_DIR/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() { | ||
function 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' & | ||
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}"'"]}' | ||
function create_user() { | ||
token=$(cat $TMP_DIR/token) | ||
grp=$(echo "${0}%${GROUP_COUNT}" | bc) | ||
[[ $grp -eq 0 ]] && grp=${GROUP_COUNT} | ||
keycloak_url="https://$(oc get routes keycloak -n ${RHDH_NAMESPACE} -o jsonpath='{.spec.host}')" | ||
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() { | ||
function 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' & | ||
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 | ||
} | ||
|
||
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 | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.