Skip to content

Commit

Permalink
tests/e2e: test host.k3d.internal DNS entry
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Oct 5, 2020
1 parent a510639 commit c47f7b7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
44 changes: 44 additions & 0 deletions tests/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,47 @@ check_cluster_token_exist() {
[ -n "$EXE" ] || abort "EXE is not defined"
$EXE cluster get "$1" --token | grep "TOKEN" >/dev/null 2>&1
}

wait_for_pod_running_by_label() {
podname=$(kubectl get pod -l "$1" $([[ -n "$2" ]] && echo "--namespace $2") -o jsonpath='{.items[0].metadata.name}')
wait_for_pod_running_by_name "$podname" "$2"
}

wait_for_pod_running_by_name() {
while : ; do
podstatus=$(kubectl get pod "$1" $([[ -n "$2" ]] && echo "--namespace $2") -o go-template='{{.status.phase}}')
case "$podstatus" in
"ErrImagePull" )
echo "Pod $1 is NOT running: ErrImagePull"
return 1
;;
"ContainerCreating" )
continue
;;
"Pending" )
continue
;;
"Running" )
echo "Pod $1 is Running"
return 0
;;
* )
echo "Pod $1 is NOT running: Unknown status '$podstatus'"
kubectl describe pod "$1" || kubectl get pods $([[ -n "$2" ]] && echo "--namespace $2")
return 1
esac
done
}

wait_for_pod_exec() {
# $1 = pod name
# $2 = command
# $3 = max. retries (default: 10)
max_retries=$([[ -n "$3" ]] && echo "$3" || echo "10")
for (( i=0; i<=max_retries; i++ )); do
echo "Try #$i"
kubectl exec "$1" -- $2 && return 0
done
echo "Command '$2' in pod '$1' did NOT return successfully in $max_retries tries"
return 1
}
20 changes: 14 additions & 6 deletions tests/test_full_lifecycle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,24 @@ check_multi_node "$clustername" 3 || failed "failed to verify number of nodes"

# 4. load an image into the cluster
info "Importing an image into the cluster..."
docker pull nginx:latest > /dev/null
docker tag nginx:latest nginx:local > /dev/null
$EXE image import nginx:local -c $clustername || failed "could not import image in $clustername"
docker pull alpine:latest > /dev/null
docker tag alpine:latest alpine:local > /dev/null
$EXE image import alpine:local -c $clustername || failed "could not import image in $clustername"

# 5. use that image
# 5. use imported image
info "Spawning a pod using the imported image..."
kubectl run --image nginx:local testimage
kubectl run --image alpine:local testimage --command -- tail -f /dev/null
info "Waiting for a bit for the pod to start..."
sleep 5
kubectl get pod testimage | grep 'Running' || failed "Pod using the imported image is not running after 5 seconds"

wait_for_pod_running_by_name "testimage"
wait_for_pod_running_by_label "k8s-app=kube-dns" "kube-system"

sleep 5

# 6. test host.k3d.internal
info "Checking DNS Lookup for host.k3d.internal"
wait_for_pod_exec "testimage" "nslookup host.k3d.internal" 6

# Cleanup

Expand Down

0 comments on commit c47f7b7

Please sign in to comment.