Skip to content

Commit

Permalink
add --cluster= parameter in order to run tests in any cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
manolo committed Jan 29, 2025
1 parent 5b1b021 commit 8ad5ff5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 42 deletions.
3 changes: 3 additions & 0 deletions scripts/pit/its/cc-identity-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const {log, args, createPage, closePage, takeScreenshot, waitForServerReady} = r

log(`Adding Role, Group and User ...\n`);
await page.getByRole('link', { name: 'Roles' }).click();
await page.waitForTimeout(2000);
await page.getByRole('button', { name: 'Create' }).click();
await takeScreenshot(page, __filename, 'role-form');
await page.getByLabel('Name').fill(role);
Expand All @@ -59,6 +60,7 @@ const {log, args, createPage, closePage, takeScreenshot, waitForServerReady} = r
await takeScreenshot(page, __filename, 'role-created');

await page.getByRole('link', { name: 'Groups' }).click();
await page.waitForTimeout(2000);
await page.getByRole('button', { name: 'Create' }).click();
await takeScreenshot(page, __filename, 'group-form');
await page.getByLabel('Name').fill(group);
Expand All @@ -68,6 +70,7 @@ const {log, args, createPage, closePage, takeScreenshot, waitForServerReady} = r
await takeScreenshot(page, __filename, 'group-created');

await page.getByRole('link', { name: 'Users' }).click();
await page.waitForTimeout(2000);
await page.getByRole('button', { name: 'Create' }).click();
await takeScreenshot(page, __filename, 'user-form');
await page.getByLabel('First Name').fill(role);
Expand Down
5 changes: 3 additions & 2 deletions scripts/pit/its/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ async function createPage(headless, ignoreHTTPSErrors) {
const browser = await chromium.launch({
headless: headless,
chromiumSandbox: false,
slowMo: 500,
slowMo: headless ? -1: 500,
args: ['--window-position=0,0']
});
const context = await browser.newContext({ignoreHTTPSErrors: ignoreHTTPSErrors, viewport: { width: 1920, height: 1080 } });
const context = await browser.newContext({ignoreHTTPSErrors: ignoreHTTPSErrors, viewport: { width: 1792, height: 970 } });
const page = await context.newPage();
page.on('console', msg => out("> CONSOLE:", (msg.text() + ' - ' + msg.location().url).replace(/\s+/g, ' '), '\n'));
page.on('pageerror', e => warn("> JSERROR:", ('' + e).replace(/\s+/g, ' '), '\n'));
Expand Down
4 changes: 3 additions & 1 deletion scripts/pit/lib/lib-args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Use: $0 with the next options:
--skip-clean Do not clean maven cache
--skip-helm Do not re-install control-center with helm and continue running tests
--skip-pw Do not run playwright tests
--cluster=name Run tests in an existing k8s cluster
--keep-cc Keep control-center running after tests
--pnpm Use pnpm instead of npm to speed up frontend compilation (default npm)
--vite Use vite inetad of webpack to speed up frontend compilation (default webpack)
Expand All @@ -37,7 +38,7 @@ Use: $0 with the next options:
everything after this argument is the function name and arguments passed to the function.
you should take care with arguments that contain spaces, they should be quoted twice.
--help Show this message
--starters=list List of demos or presets separated by comma to run (default: all) valid options:`echo ,$DEFAULT_STARTERS | sed -e 's/,/\n · /g'`
--starters=list List of demos or presets separated by comma to run (default: all) valid options:`echo ,$DEFAULT_STARTERS | tr ' ' , | sed -e 's/,/\n · /g'`
EOF
exit 1
}
Expand Down Expand Up @@ -74,6 +75,7 @@ checkArgs() {
--skip-dev) NODEV=true;;
--skip-prod) NOPROD=true;;
--skip-pw) SKIPPW=true;;
--cluster=*) CLUSTER="$arg";;
--skip-helm) SKIPHELM=true;;
--keep-cc) KEEPCC=true;;
--pnpm) PNPM="-Dpnpm.enable=true";;
Expand Down
48 changes: 33 additions & 15 deletions scripts/pit/lib/lib-ccenter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,17 @@ checkTls() {
done
}

reloadIngress() {
[ -n "$TEST" ] && return 0
pod=`kubectl -n $CC_NS get pods | grep control-center-ingress-nginx-controller | awk '{print $1}'` || return 1
[ -n "$pod" ] && runCmd "$TEST" "Reloading nginx in $pod" "kubectl exec $pod -n "$CC_NS" -- nginx -s reload" || return 1
}

## Configure secrets for the control-center and the keycloak servers
installTls() {
[ -n "$SKIPHELM" ] && return 0
[ -z "$CC_KEY" -o -z "$CC_CERT" ] && log "No CC_KEY and CC_CERT provided, skiping TLS installation" && return 0
[ -n "$CC_FULL" ] && CC_CERT=$CC_FULL
[ -n "$CC_FULL" ] && CC_CERT="$CC_FULL"
[ -z "$TEST" ] && log "Installing TLS $CC_TLS for $CC_CONTROL and $CC_AUT" || cmd "## Creating TLS file '$CC_DOMAIN.pem' from envs"
f1=cc-tls.crt
f2=cc-tls.key
Expand Down Expand Up @@ -124,8 +130,7 @@ installTls() {

[ -n "$TEST" ] && return 0

pod=`kubectl -n $CC_NS get pods | grep control-center-ingress-nginx-controller | awk '{print $1}'` || return 1
[ -n "$pod" ] && runCmd "$TEST" "Reloading nginx in $pod" "kubectl exec $pod -n "$CC_NS" -- nginx -s reload" || return 1
reloadIngress || return 1
}

## Show temporary user-email and password in the terminal
Expand All @@ -144,38 +149,51 @@ runPwTests() {
[ -z "$CC_CERT" -o -z "$CC_KEY" ] && NO_TLS=--notls || NO_TLS=""
for f in $CC_TESTS; do
runPlaywrightTests "$PIT_SCR_FOLDER/its/$f" "" "prod" "control-center" --url=https://$CC_CONTROL --login=$CC_EMAIL $NO_TLS || return 1
[ "$f" = cc-install-apps.js ] && checkTls
[ "$f" = cc-install-apps.js ] && reloadIngress && checkTls
sleep 3
done
}

## Main method for running control center
runControlCenter() {
checkCommands kind helm docker kubectl || return 1
checkBusyPort "443" || return 1
CLUSTER=${CLUSTER:-$CC_CLUSTER}

checkCommands docker kubectl helm || return 1
checkDockerRunning || return 1
## Clean up from a previous run
[ -z "$SKIPHELM" ] && uninstallCC $CC_CLUSTER $CC_NS
# deleteCluster $CC_CLUSTER
## Start a new cluster
createCluster $CC_CLUSTER $CC_NS || return 1
# startCloudProvider || return 1

## Start a new kind cluster if needed
[ "$CLUSTER" != "$CC_CLUSTER" ] || createKindCluster $CC_CLUSTER $CC_NS || return 1

## Set the context to the cluster
kubectl config set-context $CLUSTER || return 1
kubectl config set-context --current --namespace=$CC_NS || return 1
kubectl get ns >/dev/null 2>&1 || return 1

## Clean up CC from a previous run unless SKIPHELM is set
[ -z "$SKIPHELM" ] && uninstallCC $CLUSTER $CC_NS

## Install Control Center
installCC || return 1
## Control center takes a long time to start
waitForCC 900 || return 1

## Show temporary user-email and password in the terminal
showTemporaryPassword

## Install TLS certificates for the control-center and keycloak
installTls && checkTls || return 1

## Forward the ingress (it needs root access since it uses port 443)
forwardIngress $CC_NS || return 1
## Run Playwright tests
# checkBusyPort "443"
checkPort 443 || forwardIngress $CC_NS || return 1

## Run Playwright tests for the control-center
runPwTests || return 1
if [ -z "$TEST" -a -z "$KEEPCC" ]; then
stopForwardIngress || return 1
deleteCluster $CC_CLUSTER || return 1
[ "$CLUSTER" != "$CC_CLUSTER" ] || deleteKindCluster $CC_CLUSTER || return 1
fi
return 0
}


Expand Down
27 changes: 3 additions & 24 deletions scripts/pit/lib/lib-k8s-kind.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
. `dirname $0`/lib/lib-utils.sh

startCloudProvider() {
[ -z "$TEST" ] && docker container inspect kind-cloud-provider >/dev/null 2>&1 && log "Docker Kind Cloud Provider already running" && return
runCmd "$TEST" "Starting Docker KinD Cloud Provider" \
"docker run --quiet --name kind-cloud-provider --rm -d \
-v /var/run/docker.sock:/var/run/docker.sock \
rophy/cloud-provider-kind:0.4.0-20241026-r1"

# --network kind -p 443:443
}

stopCloudProvider() {
docker ps | grep kind-cloud-provider || return 0
runCmd "$TEST" "Stoping Docker KinD Cloud Provider" \
"docker kill kind-cloud-provider" || return 1
docker ps | grep envoyproxy/envoy | awk '{print $1}' | xargs docker kill 2>/dev/null
}

## Check that the command has SUID bit set
# $1: command
hasSUID() {
Expand Down Expand Up @@ -84,7 +67,8 @@ stopForwardIngress() {
##
# $1: cluster name
# $2: namespace
createCluster() {
createKindCluster() {
checkCommands kind || return 1
kind get clusters | grep -q "^$1$" && return 0
runCmd "$TEST" "Creating KinD cluster: $1" \
"kind create cluster --name $1" || return 1
Expand All @@ -94,15 +78,10 @@ createCluster() {

##
# $1: cluster name
deleteCluster() {
deleteKindCluster() {
kind get clusters | grep -q "^$1$" || return 0
runCmd "$TEST" "Deleting Cluster $1" \
"kind delete cluster --name $1" || return 1
}







0 comments on commit 8ad5ff5

Please sign in to comment.