Skip to content

Commit

Permalink
wait for Tenant to have a status field
Browse files Browse the repository at this point in the history
Optimize the test and make it more reliable

Signed-off-by: pjuarezd <[email protected]>
  • Loading branch information
pjuarezd committed Jul 5, 2024
1 parent 15ab044 commit bc9ae13
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
43 changes: 43 additions & 0 deletions shared-functions/shared-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,46 @@ function wait_for_resource_field_selector() {
--field-selector $fieldselector \
--timeout="$timeout"
}

# usage: wait_resource_status <namespace> <resourcetype> <resourcename> [<timeout>]
function wait_resource_status() {
# This function will wait until the resource has a status field
# wait_resource_status ns-1 Tenant my-tenant
# wait_resource_status ns-1 Tenant my-tenant 1200

local namespace=$1
local resourcetype=$2
local resourcename=$3

# Timeout in seconds
if [ $# -ge 4 ]; then
TIMEOUT=$4
else
TIMEOUT=600
fi

START_TIME=$(date +%s)
# Interval in seconds between checks
INTERVAL=10

echo -e "${BLUE}Waiting for $resourcetype status to be created (${TIMEOUT}s timeout)${NC}"
while true; do
if kubectl get "$resourcetype" -n "$namespace" "$resourcename" -ojson | jq -e '.status' >/dev/null 2>&1; then
echo -e "${CHECK}$resourcetype/$resourcename status found."
break
else
echo "$resourcetype/$resourcename status not found, waiting for $INTERVAL seconds."
sleep $INTERVAL
fi

# Check timeout
CURRENT_TIME=$(date +%s)
# shellcheck disable=SC2004
ELAPSED_TIME=$(($CURRENT_TIME - $START_TIME))

if [ "$ELAPSED_TIME" -ge "$TIMEOUT" ]; then
echo "Timeout waiting for $resourcetype/$resourcename to be created."
exit 1
fi
done
}
2 changes: 2 additions & 0 deletions testing/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@ function check_tenant_status() {
echo "No third argument provided, using default key"
fi

wait_resource_status $1 Tenant $2 600

wait_for_resource $1 $value $key

echo "Waiting for tenant to be Initialized"
Expand Down

0 comments on commit bc9ae13

Please sign in to comment.