tests/e2e: test host.k3d.internal DNS entry
This commit is contained in:
parent
a51063966f
commit
c47f7b731d
@ -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
|
||||
}
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user