c3dee97cbf798d3754d8a939e383e76a7d067412
[icn.git] / deploy / site / pod11 / pod11.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 source $SCRIPTDIR/../common.sh
9
10 BUILDDIR=${SCRIPTDIR/deploy/build}
11 mkdir -p ${BUILDDIR}
12
13 FLUX_SOPS_KEY_NAME=${FLUX_SOPS_KEY_NAME:-"icn-site-vm"} # TODO Replace ICN test key with real key
14
15 function build_source {
16     sops_encrypt_site ${SCRIPTDIR}/site.yaml ${FLUX_SOPS_KEY_NAME}
17 }
18
19 function deploy {
20     flux_create_site https://gerrit.akraino.org/r/icn master deploy/site/pod11 ${FLUX_SOPS_KEY_NAME}
21 }
22
23 function clean {
24     kubectl -n flux-system delete kustomization icn-master-site-pod11
25 }
26
27 function is_cluster_ready {
28     [[ $(kubectl -n metal3 get cluster icn -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}') == "True" ]]
29 }
30
31 function is_control_plane_ready {
32     # Checking the Cluster resource status is not sufficient, it
33     # reports the control plane as ready before the nodes forming the
34     # control plane are ready
35     local -r replicas=$(kubectl -n metal3 get kubeadmcontrolplane icn -o jsonpath='{.spec.replicas}')
36     [[ $(kubectl --kubeconfig=${BUILDDIR}/icn-admin.conf get nodes -l node-role.kubernetes.io/control-plane -o jsonpath='{range .items[*]}{.status.conditions[?(@.type=="Ready")].status}{"\n"}{end}' | grep -c True) == ${replicas} ]]
37 }
38
39 function wait_for_all_ready {
40     WAIT_FOR_INTERVAL=60s
41     WAIT_FOR_TRIES=30
42     wait_for is_cluster_ready
43     clusterctl -n metal3 get kubeconfig icn >${BUILDDIR}/icn-admin.conf
44     chmod 600 ${BUILDDIR}/icn-admin.conf
45     wait_for is_control_plane_ready
46 }
47
48 case $1 in
49     "build-source") build_source ;;
50     "clean") clean ;;
51     "deploy") deploy ;;
52     "wait") wait_for_all_ready ;;
53     *) cat <<EOF
54 Usage: $(basename $0) COMMAND
55
56 Commands:
57   build-source  - Rebuild the in-tree site files
58   clean         - Remove the site
59   deploy        - Deploy the site
60   wait          - Wait for the site to be ready
61 EOF
62        ;;
63 esac