-
Notifications
You must be signed in to change notification settings - Fork 49
/
helloworld_aks_demo.sh
executable file
·77 lines (63 loc) · 2.08 KB
/
helloworld_aks_demo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
set -e
RESOURCE_GROUP=
CLUSTER_NAME=
HELLOWORLD_JOB=myst-helloworld
HELLOWORLD_YAML="myst-helloworld.yaml"
HELLOWORLD_JOB=myst-helloworld
HELLOWORLD_LABEL_KEY=app
HELLOWORLD_LABEL_VALUE=myst-helloworld
function main() {
echo -e "\nValidate Helloworld"
initialize_kubeconfig
validate_myst-helloworld
echo "Done"
}
function validate_myst-helloworld() {
delete_all
# Apply job
kubectl apply -f $HELLOWORLD_YAML
sleep 2
kubectl get pods
# display job logs
JOB_POD=$(kubectl get pods -l $HELLOWORLD_LABEL_KEY=$HELLOWORLD_LABEL_VALUE -o 'jsonpath={..metadata.name}')
kubectl logs $JOB_POD
# wait for job completion
kubectl wait --for=condition=Complete job/$HELLOWORLD_JOB --timeout=600s
# display job logs
JOB_POD=$(kubectl get pods -l $HELLOWORLD_LABEL_KEY=$HELLOWORLD_LABEL_VALUE -o 'jsonpath={..metadata.name}')
kubectl logs $JOB_POD
# delete_all
}
function delete_all()(
echo -e "\nClean up all deployments"
delete_resource job $HELLOWORLD_JOB
wait_for_all_terminating_pods_to_complete
)
# Set kubectl to refer to the current clusters kubeconfig
function initialize_kubeconfig() {
echo -e "\nDisplay cluster nodes created"
az aks get-credentials --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME
kubectl get nodes
}
# This function waits for all terminating pods to be completely terminated
function wait_for_all_terminating_pods_to_complete() {
while : ; do
terminating=$(kubectl get pods | awk '/Terminating/' | wc -l)
[ $terminating -gt 0 ] || break
sleep 10
echo "Waiting...there are some terminating pods."
done
}
# $1=RESOURCE_TYPE $2=RESOURCE_NAME $3=NAMESPACE
function delete_resource() {
RESOURCE_TYPE=${1:-"default"}
RESOURCE_NAME=${2:-"default"}
NAMESPACE=${3:-"default"}
EXISTS=$(kubectl get $RESOURCE_TYPE $RESOURCE_NAME -n $NAMESPACE | awk {'print $1'} | tail -1)
if [[ $EXISTS != "" ]]; then
echo "deleting $RESOURCE_NAME"
kubectl delete $RESOURCE_TYPE $RESOURCE_NAME -n $NAMESPACE
fi
}
main "$@"; exit