Skip to content

Commit

Permalink
fix: wait for pod in e2e tests correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKramm committed Jul 26, 2024
1 parent 23d93ff commit d2273dc
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 20 deletions.
25 changes: 5 additions & 20 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,7 @@ jobs:
--connect=false \
--distro=${{ matrix.distribution }}
_out=$(kubectl wait --for=condition=ready pod -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} --timeout=300s 2>&1)
if [[ "${_out}" =~ "no matching resources" ]]
then
sleep 20
kubectl wait --for=condition=ready pod -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} --timeout=300s
fi
./hack/wait-for-pod.sh -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }}
- name: upgrade with the dev cli
run: |
Expand All @@ -240,14 +235,7 @@ jobs:
--local-chart-dir ./chart \
-f ./test/commonValues.yaml
sleep 20
_out=$(kubectl wait --for=condition=ready pod -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} --timeout=300s 2>&1)
if [[ "${_out}" =~ "no matching resources" ]]
then
sleep 20
kubectl wait --for=condition=ready pod -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} --timeout=300s
fi
./hack/wait-for-pod.sh -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }}
e2e-tests:
name: Execute test suites
Expand Down Expand Up @@ -384,12 +372,9 @@ jobs:
if: steps.create-vcluster.outcome == 'success'
run: |
set -x
_out=$(kubectl wait --for=condition=ready pod -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} --timeout=300s 2>&1)
if [[ "${_out}" =~ "no matching resources" ]]
then
sleep 20
kubectl wait --for=condition=ready pod -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }} --timeout=300s
fi
./hack/wait-for-pod.sh -l app=${{ env.VCLUSTER_SUFFIX }} -n ${{ env.VCLUSTER_NAMESPACE }}
continue-on-error: true

- name: Collect deployment information in case vcluster fails to start
Expand Down
51 changes: 51 additions & 0 deletions hack/wait-for-pod.sh
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

0 comments on commit d2273dc

Please sign in to comment.