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