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