4 SCRIPTDIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
5 LIBDIR="$(dirname $(dirname $(dirname ${SCRIPTDIR})))/env/lib"
7 source $LIBDIR/common.sh
8 source $SCRIPTDIR/../common.sh
10 BUILDDIR=${SCRIPTDIR/deploy/build}
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"}
17 FLUX_SOPS_KEY_NAME=${FLUX_SOPS_KEY_NAME:-"icn-site-vm"} # TODO Replace ICN test key with real key
19 function build_source {
20 sops_encrypt ${SCRIPTDIR}/site.yaml ${FLUX_SOPS_KEY_NAME}
24 flux_create_site ${SITE_REPO} ${SITE_BRANCH} ${SITE_PATH} ${FLUX_SOPS_KEY_NAME}
28 kubectl -n flux-system delete kustomization $(flux_site_kustomization_name ${SITE_REPO} ${SITE_BRANCH} ${SITE_PATH})
31 function is_cluster_ready {
32 [[ $(kubectl -n ${SITE_NAMESPACE} get cluster icn -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}') == "True" ]]
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 ${SITE_NAMESPACE} 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} ]]
43 function wait_for_all_ready {
46 wait_for is_cluster_ready
47 clusterctl -n ${SITE_NAMESPACE} get kubeconfig icn >${BUILDDIR}/icn-admin.conf
48 chmod 600 ${BUILDDIR}/icn-admin.conf
49 wait_for is_control_plane_ready
52 function is_cluster_deleted {
53 ! kubectl -n ${SITE_NAMESPACE} get cluster icn
56 function wait_for_all_deleted {
59 wait_for is_cluster_deleted
63 "build-source") build_source ;;
66 "wait") wait_for_all_ready ;;
67 "wait-clean") wait_for_all_deleted ;;
69 Usage: $(basename $0) COMMAND
72 build-source - Rebuild the in-tree site files
73 clean - Remove the site
74 deploy - Deploy the site
75 wait - Wait for the site to be ready