-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: wait for pod in e2e tests correctly
- Loading branch information
1 parent
23d93ff
commit d2273dc
Showing
2 changed files
with
56 additions
and
20 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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
|
||
NAMESPACE="" | ||
LABEL_SELECTOR="" | ||
POD_NAME="" | ||
CONTEXT="" | ||
|
||
# Parse command-line arguments | ||
while [[ $# -gt 0 ]]; do | ||
case "$1" in | ||
-n | --namespace) | ||
NAMESPACE="$2" | ||
shift 2 | ||
;; | ||
-l | --label-selector) | ||
LABEL_SELECTOR="$2" | ||
shift 2 | ||
;; | ||
-c | --context) | ||
CONTEXT="$2" | ||
shift 2 | ||
;; | ||
*) | ||
echo "Invalid argument: $1" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# Validate required arguments | ||
if [[ -z "$NAMESPACE" ]]; then | ||
echo "Namespace is required. Use the '-n' or '--namespace' flag." | ||
exit 1 | ||
fi | ||
|
||
if [[ -z "$LABEL_SELECTOR" ]]; then | ||
echo "Label selector is required. Use the '-l' or '--label-selector' flag." | ||
exit 1 | ||
fi | ||
|
||
# Loop until a pod with the given label selector is created | ||
while [[ -z "$POD_NAME" ]]; do | ||
POD_NAME=$(kubectl get pod --context="$CONTEXT" -n "$NAMESPACE" -l "$LABEL_SELECTOR" --output=jsonpath='{.items[0].metadata.name}' 2>/dev/null) | ||
if [[ -z "$POD_NAME" ]]; then | ||
echo "Pod with label selector '$LABEL_SELECTOR' not found in context '$CONTEXT'. Waiting..." | ||
sleep 5 | ||
fi | ||
done | ||
|
||
# Wait for the pod to be ready | ||
kubectl wait --context="$CONTEXT" --for=condition=Ready -n $NAMESPACE pod -l $LABEL_SELECTOR --timeout=5m |