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/vm/deployment"}
18 gpg --import ${FLUX_SOPS_PRIVATE_KEY}
19 flux_create_site ${SITE_REPO} ${SITE_BRANCH} ${SITE_PATH} ${FLUX_SOPS_KEY_NAME}
23 kubectl -n flux-system delete kustomization $(flux_site_kustomization_name ${SITE_REPO} ${SITE_BRANCH} ${SITE_PATH})
26 function is_cluster_ready {
27 [[ $(kubectl -n ${SITE_NAMESPACE} get cluster icn -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}') == "True" ]]
30 function is_control_plane_ready {
31 # Checking the Cluster resource status is not sufficient, it
32 # reports the control plane as ready before the nodes forming the
33 # control plane are ready
34 local -r replicas=$(kubectl -n ${SITE_NAMESPACE} get kubeadmcontrolplane icn -o jsonpath='{.spec.replicas}')
35 [[ $(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} ]]
38 function insert_control_plane_network_identity_into_ssh_config {
39 # This enables logging into the control plane machines from this
40 # machine without specifying the identify file on the command line
42 if [[ ! $(which ipcalc) ]]; then
43 apt-get install -y ipcalc
46 # Create ssh config if it doesn't exist
47 mkdir -p ${HOME}/.ssh && chmod 700 ${HOME}/.ssh
48 touch ${HOME}/.ssh/config
49 chmod 600 ${HOME}/.ssh/config
50 # Add the entry for the control plane network, host value in ssh
51 # config is a wildcard
52 endpoint=$(helm -n ${SITE_NAMESPACE} get values -a cluster-icn | awk '/controlPlaneEndpoint:/ {print $2}')
53 prefix=$(helm -n ${SITE_NAMESPACE} get values -a cluster-icn | awk '/controlPlanePrefix:/ {print $2}')
54 host=$(ipcalc ${endpoint}/${prefix} | awk '/Network:/ {sub(/\.0.*/,".*"); print $2}')
55 if [[ $(grep -c "Host ${host}" ${HOME}/.ssh/config) != 0 ]]; then
56 sed -i -e '/Host '"${host}"'/,+3 d' ${HOME}/.ssh/config
58 cat <<EOF >>${HOME}/.ssh/config
60 IdentityFile ${SCRIPTDIR}/id_rsa
61 StrictHostKeyChecking no
62 UserKnownHostsFile /dev/null
64 # Add the identity to authorized keys on this host to enable ssh
65 # logins via its control plane address
66 authorized_key=$(cat ${SCRIPTDIR}/id_rsa.pub)
67 sed -i -e '\!'"${authorized_key}"'!d' ${HOME}/.ssh/authorized_keys
68 cat ${SCRIPTDIR}/id_rsa.pub >> ~/.ssh/authorized_keys
71 function wait_for_all_ready {
74 wait_for is_cluster_ready
75 clusterctl -n ${SITE_NAMESPACE} get kubeconfig icn >${BUILDDIR}/icn-admin.conf
76 chmod 600 ${BUILDDIR}/icn-admin.conf
77 wait_for is_control_plane_ready
78 insert_control_plane_network_identity_into_ssh_config
81 function is_cluster_deleted {
82 ! kubectl -n ${SITE_NAMESPACE} get cluster icn
85 function wait_for_all_deleted {
88 wait_for is_cluster_deleted
94 "wait") wait_for_all_ready ;;
95 "wait-clean") wait_for_all_deleted ;;
97 Usage: $(basename $0) COMMAND
100 clean - Remove the site
101 deploy - Deploy the site
102 wait - Wait for the site to be ready