Skip to content

Commit

Permalink
rename vars and check port 443
Browse files Browse the repository at this point in the history
  • Loading branch information
manolo committed Jan 30, 2025
1 parent af42337 commit f3d882a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
1 change: 1 addition & 0 deletions scripts/pit/its/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ async function createPage(headless, ignoreHTTPSErrors) {
const browser = await chromium.launch({
headless: headless,
chromiumSandbox: false,
slowMo: 500,
args: ['--window-position=0,0']
});
const context = await browser.newContext({ignoreHTTPSErrors: ignoreHTTPSErrors, viewport: { width: 1792, height: 970 } });
Expand Down
26 changes: 14 additions & 12 deletions scripts/pit/lib/lib-ccenter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ CC_TLS_K=cc-control-login-tls
## Ingress names
CC_ING_A=control-center
CC_ING_K=control-center-keycloak-ingress
## K8s cluster and namespace
CC_CLUSTER=cc-cluster
# Namespace used for CC
CC_NS=control-center

## UI tests to run after the control-center is installed
Expand Down Expand Up @@ -86,6 +85,7 @@ getTLs() {
}

checkTls() {
[ -n "$TEST" ] && return 0
log "Checking TLS certificates for all ingresses hosted in the cluster"
[ -n "$TEST" -o -n "$SKIPHELM" ] && return 0
for i in `kubectl get ingresses -n $CC_NS | grep nginx | awk '{print $1}'`; do
Expand All @@ -97,6 +97,7 @@ 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
[ -z "$TEST" ] && sleep 3
}

## Configure secrets for the control-center and the keycloak servers
Expand Down Expand Up @@ -155,12 +156,11 @@ runPwTests() {
if [ "$f" = cc-install-apps.js ]; then
reloadIngress && checkTls || return 1
fi
sleep 3
done
}

setClusterContext() {
[ "$1" = "$CC_CLUSTER" ] && current=kind-$1 || current=$1
[ "$1" = "$KIND_CLUSTER" ] && current=kind-$1 || current=$1
ns=$2
H=`kubectl config get-contexts | tr '*' ' ' | awk '{print $1}' | egrep "^$current$"`
[ -z "$H" ] && log "Cluster $current not found in kubectl contexts" && return 1
Expand All @@ -173,13 +173,13 @@ setClusterContext() {

## Main method for running control center
runControlCenter() {
CLUSTER=${CLUSTER:-$CC_CLUSTER}
CLUSTER=${CLUSTER:-$KIND_CLUSTER}

checkCommands docker kubectl helm unzip || return 1
checkDockerRunning || return 1

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

## Set the context to the cluster
setClusterContext "$CLUSTER" "$CC_NS" || return 1
Expand All @@ -199,15 +199,17 @@ runControlCenter() {
installTls && checkTls || return 1

## Forward the ingress (it needs root access since it uses port 443)
# checkBusyPort "443"
checkPort 443 || forwardIngress $CC_NS || return 1
# checkPort "443"
[ "$CLUSTER" != "$KIND_CLUSTER" ] || 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
[ "$CLUSTER" != "$CC_CLUSTER" ] || deleteKindCluster $CC_CLUSTER || return 1
fi
stopForwardIngress || return 1

## Delete the KinD cluster if it was created in this test
[ -n "$TEST" -o -n "$KEEPCC" -o "$CLUSTER" != "$KIND_CLUSTER" ] || deleteKindCluster "$CLUSTER" || return 1
[ -n "$TEST" -o -n "$KEEPCC" -o "$CLUSTER" = "$KIND_CLUSTER" ] || uninstallCC || return 1

return 0
}

Expand Down
7 changes: 6 additions & 1 deletion scripts/pit/lib/lib-k8s-kind.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
. `dirname $0`/lib/lib-utils.sh

## Kind cluster to use if not provided
KIND_CLUSTER=cc-cluster

## Check that the command has SUID bit set
# $1: command
hasSUID() {
Expand Down Expand Up @@ -37,6 +40,7 @@ setSuid() {
# $3: port in guest
# $4: target port in host
startPortForward() {
checkPort "$4" && err "Port $4 is already in use" && return 1
H=`getPids "kubectl port-forward $2"`
[ -n "$H" ] && log "Already running k8s port-forward $1 $2 $3 -> $4 with pid $H" && return 0
[ -z "$TEST" ] && log "Starting k8s port-forward $1 $2 $3 -> $4"
Expand All @@ -45,7 +49,8 @@ startPortForward() {
rm -f "$bgf"
runInBackgroundToFile "$K port-forward $2 $4:$3 -n $1" "$bgf"
sleep 2
egrep 'Forwarding from' "$bgf"
tail "$bgf"
egrep -q 'Forwarding from' "$bgf"
}

##
Expand Down

0 comments on commit f3d882a

Please sign in to comment.