From: beierlm Date: Thu, 16 Jul 2020 20:57:09 +0000 (-0400) Subject: Make Charmed Installer Idempotent X-Git-Tag: v8.0.0rc3~1 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=9425dd2d4a3a0ac8c0bb6dd8d71b0c4b71045f62;p=osm%2Fdevops.git Make Charmed Installer Idempotent By default, the charmed installer will create a controller called 'controller', unless an external VCA is specified using the --vca option. Upon uninstall, it is not known or safe to remove this Juju controller as there might be other applications using it. This change shows that message on uninstall, giving the user the opportunity to remove it with a command. Also, as part of the installation, this change checks for the controller and if it exists, presents the user with options for how to resolve the situation. Fixes bug 1126 Change-Id: Id13cd822ed7eef60250544108b74bbba7998d9b7 Signed-off-by: beierlm --- diff --git a/installers/charmed_install.sh b/installers/charmed_install.sh index 6d89a340..e8eda63d 100755 --- a/installers/charmed_install.sh +++ b/installers/charmed_install.sh @@ -42,7 +42,23 @@ function install_snaps(){ function bootstrap_k8s_lxd(){ [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER - [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="controller" + [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca" + + if [ -v BOOTSTRAP_NEEDED ]; then + CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l) + if [ $CONTROLLER_PRESENT -ge 1 ]; then + cat << EOF +Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}". +You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it +using this command: + + juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME} + +Please retry the installation once this conflict has been resolved. +EOF + exit 1 + fi + fi if [ -v KUBECFG ]; then cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS @@ -50,8 +66,16 @@ function bootstrap_k8s_lxd(){ else sg microk8s -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb" sg microk8s -c "microk8s.enable storage dns" + TIME_TO_WAIT=30 + start_time="$(date -u +%s)" while true do + now="$(date -u +%s)" + if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then + echo "Microk8s storage failed to enable" + sg microk8s -c "microk8s.status" + exit 1 + fi sg microk8s -c "microk8s.status" | grep 'storage: enabled' if [ $? -eq 0 ]; then break @@ -119,7 +143,7 @@ EOF juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS sg lxd -c "lxd waitready" - juju add-model test lxd-cloud || true + #juju add-model test lxd-cloud || true juju controller-config features=[k8s-operators] } @@ -283,3 +307,19 @@ install_osmclient if [ -v MICROSTACK ]; then install_microstack fi + +echo "Your installation is now complete, follow these steps for configuring the osmclient:" +echo +echo "1. Get the NBI IP with the following command:" +echo +echo NBI_IP='`juju status --format json | jq -rc '"'"'.applications."nbi-k8s".address'"'"'`' +echo +echo "2. Create the OSM_HOSTNAME environment variable with the NBI IP" +echo +echo "export OSM_HOSTNAME=\$NBI_IP" +echo +echo "3. Add the previous command to your .bashrc for other Shell sessions" +echo +echo "echo \"export OSM_HOSTNAME=\$NBI_IP\" >> ~/.bashrc" +echo +echo "DONE" diff --git a/installers/charmed_uninstall.sh b/installers/charmed_uninstall.sh index ef2b293c..09305d2a 100755 --- a/installers/charmed_uninstall.sh +++ b/installers/charmed_uninstall.sh @@ -14,7 +14,18 @@ # -juju destroy-model osm --destroy-storage -y -juju destroy-model test --destroy-storage -y +juju destroy-model osm --destroy-storage -y --force --no-wait sudo snap unalias osm sudo snap remove osmclient +CONTROLLER_NAME="osm-vca" +CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l) +if [[ $CONTROLLER_PRESENT -ge 1 ]]; then + cat << EOF +The VCA with the name "${CONTROLLER_NAME}" has been left in place to ensure that no other +applications are using it. If you are sure you wish to remove this controller, +please execute the following command: + + juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME} + +EOF +fi diff --git a/installers/full_install_osm.sh b/installers/full_install_osm.sh index 1a800e4c..a76aa571 100755 --- a/installers/full_install_osm.sh +++ b/installers/full_install_osm.sh @@ -1246,7 +1246,7 @@ EOF [ -z "$INSTALL_NOHOSTCLIENT" ] && install_osmclient track osmclient - + echo -e "Checking OSM health state..." if [ -n "$KUBERNETES" ]; then $OSM_DEVOPS/installers/osm_health.sh -s ${OSM_STACK_NAME} -k || \ @@ -1641,22 +1641,6 @@ if [ -n "$CHARMED" ]; then ${OSM_DEVOPS}/installers/charmed_uninstall.sh -R $RELEASE -r $REPOSITORY -u $REPOSITORY_BASE -D /usr/share/osm-devops -t $DOCKER_TAG "$@" else ${OSM_DEVOPS}/installers/charmed_install.sh -R $RELEASE -r $REPOSITORY -u $REPOSITORY_BASE -D /usr/share/osm-devops -t $DOCKER_TAG "$@" - - echo "Your installation is now complete, follow these steps for configuring the osmclient:" - echo - echo "1. Get the NBI IP with the following command:" - echo - echo NBI_IP='`juju status --format json | jq -rc '"'"'.applications."nbi-k8s".address'"'"'`' - echo - echo "2. Create the OSM_HOSTNAME environment variable with the NBI IP" - echo - echo "export OSM_HOSTNAME=\$NBI_IP" - echo - echo "3. Add the previous command to your .bashrc for other Shell sessions" - echo - echo "echo \"export OSM_HOSTNAME=\$NBI_IP\" >> ~/.bashrc" - echo - echo "DONE" fi exit 0