Merge "Increase provisioning timeout for HA VM testing"
[icn.git] / deploy / site / vm / vm.sh
1 #!/usr/bin/env bash
2 set -eux -o pipefail
3
4 SCRIPTDIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
5 LIBDIR="$(dirname $(dirname $(dirname ${SCRIPTDIR})))/env/lib"
6
7 source $LIBDIR/common.sh
8
9 BUILDDIR=${SCRIPTDIR/deploy/build}
10 mkdir -p ${BUILDDIR}
11
12 function build {
13     SSH_AUTHORIZED_KEY=$(cat ${HOME}/.ssh/id_rsa.pub)
14     # Use ! instead of usual / to avoid escaping / in
15     # SSH_AUTHORIZED_KEY
16     sed -e 's!sshAuthorizedKey: .*!sshAuthorizedKey: '"${SSH_AUTHORIZED_KEY}"'!' ${SCRIPTDIR}/cluster-e2etest-values.yaml >${BUILDDIR}/cluster-e2etest-values.yaml
17 }
18
19 function release_name {
20     local -r values_path=$1
21     name=$(basename ${values_path})
22     echo ${name%-values.yaml}
23 }
24
25 function deploy {
26     for values in ${BUILDDIR}/machine-*-values.yaml; do
27         helm -n metal3 install $(release_name ${values}) ${SCRIPTDIR}/../../machine --create-namespace -f ${values}
28     done
29     helm -n metal3 install cluster-e2etest ${SCRIPTDIR}/../../cluster --create-namespace -f ${BUILDDIR}/cluster-e2etest-values.yaml
30 }
31
32 function clean {
33     helm -n metal3 uninstall cluster-e2etest
34     for values in ${BUILDDIR}/machine-*-values.yaml; do
35         helm -n metal3 uninstall $(release_name ${values})
36     done
37 }
38
39 function is_cluster_ready {
40     [[ $(kubectl -n metal3 get cluster e2etest -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}') == "True" ]]
41 }
42
43 function is_control_plane_ready {
44     [[ $(kubectl --kubeconfig=${BUILDDIR}/e2etest-admin.conf get nodes -l node-role.kubernetes.io/control-plane -o jsonpath='{range .items[*]}{.status.conditions[?(@.type=="Ready")].status}{"\n"}{end}' | grep -c -v True) == 0 ]]
45 }
46
47 function wait_for_all_ready {
48     WAIT_FOR_INTERVAL=60s
49     WAIT_FOR_TRIES=30
50     wait_for is_cluster_ready
51     clusterctl -n metal3 get kubeconfig e2etest >${BUILDDIR}/e2etest-admin.conf
52     chmod 600 ${BUILDDIR}/e2etest-admin.conf
53     wait_for is_control_plane_ready
54 }
55
56 case $1 in
57     "build") build ;;
58     "clean") clean ;;
59     "deploy") deploy ;;
60     "wait") wait_for_all_ready ;;
61     *) cat <<EOF
62 Usage: $(basename $0) COMMAND
63
64 Commands:
65   build         - Build the site deployment values
66   clean         - Remove the site
67   deploy        - Deploy the site
68   wait          - Wait for the site to be ready
69 EOF
70        ;;
71 esac