Do not error when a deleted resource is not found
[icn.git] / cmd / bpa-operator / e2etest / bpa_remote_virtletvm_verifier.sh
1 #!/usr/bin/env bash
2 set -eu -o pipefail
3
4 printf "\n\nStart Remote Virtlet VM provisioning E2E test\n\n"
5
6 # remote compute provisioned and kube config available
7 source ~/ICN/latest/icn/env/lib/common.sh
8 CLUSTER_NAME=bpa-remote
9 KUBECONFIG=--kubeconfig=/opt/kud/multi-cluster/${CLUSTER_NAME}/artifacts/admin.conf
10 APISERVER=$(kubectl ${KUBECONFIG} config view --minify -o jsonpath='{.clusters[0].cluster.server}')
11 TOKEN=$(kubectl ${KUBECONFIG} get secret $(kubectl ${KUBECONFIG} get serviceaccount default -o jsonpath='{.secrets[0].name}') -o jsonpath='{.data.token}' | base64 --decode )
12 if ! call_api $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure;
13 then
14   printf "\nRemote Kubernetes Cluster Install did not complete successfully\n"
15 else
16   printf "\niRemote Kubernetes Cluster Install was successful\n"
17 fi
18
19 # create virtlet VM in remote compute
20 printf "Create remote Virtlet VM ...\n"
21 key=$(cat /opt/kud/multi-cluster/.ssh/id_rsa.pub)
22 cp ../deploy/virtlet-deployment-sample.yaml bpa_remote_virtletvm.yaml
23 sed -i "s|\$ssh_key|${key}|" bpa_remote_virtletvm.yaml
24 kubectl ${KUBECONFIG} create -f bpa_remote_virtletvm.yaml
25
26 status=""
27 while [[ $status != "Running" ]]
28 do
29         stats=$(kubectl ${KUBECONFIG} get pods |grep -i virtlet-deployment)
30         status=$(echo $stats | cut -d " " -f 3)
31         if [[ $status == "Err"* ]]; then
32                 echo "Error creating remote Virtlet VM, test incomplete"
33                 kubectl ${KUBECONFIG} delete -f bpa_remote_virtletvm.yaml
34                 exit 1
35         fi
36 done
37
38 echo "Remote Virtlet VM is ready for provisioning"
39
40 printf "\nkubectl ${KUBECONFIG} get pods $(kubectl ${KUBECONFIG} get pods |grep -i virtlet-deployment | awk '{print $1}') -o json\n"
41 podjson=$(kubectl ${KUBECONFIG} get pods $(kubectl ${KUBECONFIG} get pods |grep -i virtlet-deployment | awk '{print $1}') -o json)
42 printf "\n$podjson\n\n"
43
44 printf "Provision remote Virtlet VM ...\n"
45 kubectl  ${KUBECONFIG} apply -f bpa_remote_virtletvm_cr.yaml
46
47 #Check Status of remote kud job pod
48 status="Running"
49
50 while [[ $status == "Running" ]]
51 do
52         echo "KUD install job still running"
53         sleep 2m
54         stats=$(kubectl ${KUBECONFIG} get pods |grep -i kud-)
55         status=$(echo $stats | cut -d " " -f 3)
56 done
57
58 if [[ $status == "Completed" ]];
59 then
60    printf "KUD Install Job completed\n"
61    printf "Checking cluster status\n"
62 else
63    printf "KUD Install Job failed\n"
64 fi
65
66 #Print logs of Job Pod
67 jobPod=$(kubectl ${KUBECONFIG} get pods|grep kud-)
68 podName=$(echo $jobPod | cut -d " " -f 1)
69 printf "\nNow Printing Job pod logs\n"
70 kubectl ${KUBECONFIG} logs $podName
71
72 #printf "\n\nBeginning E2E Remote VM Test Teardown\n\n"
73
74 kubectl ${KUBECONFIG} delete -f bpa_remote_virtletvm_cr.yaml
75 kubectl ${KUBECONFIG} delete job kud-remotevvm
76 kubectl ${KUBECONFIG} delete --ignore-not-found=true configmap remotevvm-configmap
77 kubectl  ${KUBECONFIG} delete -f bpa_remote_virtletvm.yaml