Make .ssh/config changes idempotent
[icn.git] / deploy / site / vm / vm.sh
index c533f27..8d65df7 100755 (executable)
@@ -84,7 +84,7 @@ function insert_control_plane_network_identity_into_ssh_config {
     prefix=$(helm -n ${SITE_NAMESPACE} get values -a cluster-icn | awk '/controlPlanePrefix:/ {print $2}')
     host=$(ipcalc ${endpoint}/${prefix} | awk '/Network:/ {sub(/\.0.*/,".*"); print $2}')
     if [[ $(grep -c "Host ${host}" ${HOME}/.ssh/config) != 0 ]]; then
-       sed -i -e '/Host '"${host}"'/,+1 d' ${HOME}/.ssh/config
+       sed -i -e '/Host '"${host}"'/,+3 d' ${HOME}/.ssh/config
     fi
     cat <<EOF >>${HOME}/.ssh/config
 Host ${host}
@@ -94,6 +94,8 @@ Host ${host}
 EOF
     # Add the identity to authorized keys on this host to enable ssh
     # logins via its control plane address
+    authorized_key=$(cat ${SCRIPTDIR}/id_rsa.pub)
+    sed -i -e '\!'"${authorized_key}"'!d' ${HOME}/.ssh/authorized_keys
     cat ${SCRIPTDIR}/id_rsa.pub >> ~/.ssh/authorized_keys
 }
 
@@ -107,11 +109,22 @@ function wait_for_all_ready {
     insert_control_plane_network_identity_into_ssh_config
 }
 
+function is_cluster_deleted {
+    ! kubectl -n ${SITE_NAMESPACE} get cluster icn
+}
+
+function wait_for_all_deleted {
+    WAIT_FOR_INTERVAL=60s
+    WAIT_FOR_TRIES=30
+    wait_for is_cluster_deleted
+}
+
 case $1 in
     "build-source") build_source ;;
     "clean") clean ;;
     "deploy") deploy ;;
     "wait") wait_for_all_ready ;;
+    "wait-clean") wait_for_all_deleted ;;
     *) cat <<EOF
 Usage: $(basename $0) COMMAND