Feature 11041: Enable K3s as Kubernetes distro for OSM installation
[osm/devops.git] / installers / full_install_osm.sh
index 92ec4fa..679e834 100755 (executable)
@@ -25,7 +25,7 @@ function usage(){
     echo -e "     -u <repo base>: use specified repository url for osm packages"
     echo -e "     -k <repo key>:  use specified repository public key url"
     echo -e "     -a <apt proxy url>: use this apt proxy url when downloading apt packages (air-gapped installation)"
-    echo -e "     -c <kubernetes engine>: use a specific kubernetes engine (options: kubeadm, k3s, microk8s), default is kubeadm"
+    echo -e "     -c <kubernetes engine>: use a specific kubernetes engine (options: kubeadm, k3s), default is kubeadm"
     echo -e "     -s <namespace>  namespace when installed using k8s, default is osm"
     echo -e "     -H <VCA host>   use specific juju host controller IP"
     echo -e "     -S <VCA secret> use VCA/juju secret key"
@@ -33,8 +33,8 @@ function usage(){
     echo -e "     -A <VCA apiproxy> use VCA/juju API proxy"
     echo -e "     --pla:          install the PLA module for placement support"
     echo -e "     --old-sa:       install old Service Assurance framework (MON, POL); do not install Airflow and Pushgateway"
-    echo -e "     --ng-sa:        install new Service Assurance framework (Airflow, AlertManager and Pushgateway)  (enabled by default)"
-    echo -e "     -o <ADDON>:     ONLY (un)installs one of the addons (k8s_monitor, ng-sa)"
+    echo -e "     --ng-sa:        install new Service Assurance framework (Airflow, AlertManager and Pushgateway) (enabled by default)"
+    echo -e "     -o <COMPONENT>: ONLY installs the specified component (k8s_monitor, ng-sa, k8scluster, docker, deploy-osm)"
     echo -e "     -O <openrc file path/cloud name>: Install OSM to an OpenStack infrastructure. <openrc file/cloud name> is required. If a <cloud name> is used, the clouds.yaml file should be under ~/.config/openstack/ or /etc/openstack/"
     echo -e "     -N <openstack public network name/ID>: Public network name required to setup OSM to OpenStack"
     echo -e "     -f <path to SSH public key>: Public SSH key to use to deploy OSM to OpenStack"
@@ -420,14 +420,25 @@ function install_k8s_cluster() {
         KUBEADM_INSTALL_OPTS="-d ${OSM_WORK_DIR} -D ${OSM_DEVOPS} ${DEBUG_INSTALL}"
         $OSM_DEVOPS/installers/install_kubeadm_cluster.sh ${KUBEADM_INSTALL_OPTS} || \
         FATAL_TRACK k8scluster "install_kubeadm_cluster.sh failed"
-        K8SCLUSTER_ADDONS_INSTALL_OPTS="-i ${OSM_DEFAULT_IP} -d ${OSM_WORK_DIR} -D ${OSM_DEVOPS} ${DEBUG_INSTALL}"
+        K8SCLUSTER_ADDONS_INSTALL_OPTS="-i ${OSM_DEFAULT_IP} -d ${OSM_WORK_DIR} -D ${OSM_DEVOPS} ${DEBUG_INSTALL} --all"
         $OSM_DEVOPS/installers/install_cluster_addons.sh ${K8SCLUSTER_ADDONS_INSTALL_OPTS} || \
-        FATAL_TRACK k8scluster "install_cluster_addons.sh failed"
+        FATAL_TRACK k8scluster "install_cluster_addons.sh failed for kubeadm cluster"
+    elif [ "${K8S_CLUSTER_ENGINE}" == "k3s" ]; then
+        K3S_INSTALL_OPTS="-D ${OSM_DEVOPS} ${DEBUG_INSTALL}"
+        # The K3s installation script will automatically take the HTTP_PROXY, HTTPS_PROXY and NO_PROXY,
+        # as well as the CONTAINERD_HTTP_PROXY, CONTAINERD_HTTPS_PROXY and CONTAINERD_NO_PROXY variables
+        # from the shell, if they are present, and write them to the environment file of k3s systemd service,
+        $OSM_DEVOPS/installers/install_k3s_cluster.sh ${K3S_INSTALL_OPTS} || \
+        FATAL_TRACK k8scluster "install_k3s_cluster.sh failed"
+        K8SCLUSTER_ADDONS_INSTALL_OPTS="-i ${OSM_DEFAULT_IP} -d ${OSM_WORK_DIR} -D ${OSM_DEVOPS} ${DEBUG_INSTALL} --certmgr --nginx"
+        $OSM_DEVOPS/installers/install_cluster_addons.sh ${K8SCLUSTER_ADDONS_INSTALL_OPTS} || \
+        FATAL_TRACK k8scluster "install_cluster_addons.sh failed for k3s cluster"
     fi
     [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
 }
 
 function deploy_osm() {
+    [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
     deploy_mongodb
     track deploy_osm deploy_mongodb_ok
     deploy_osm_helm_chart
@@ -437,6 +448,7 @@ function deploy_osm() {
         install_osm_ngsa_service
         track deploy_osm install_osm_ngsa_ok
     fi
+    [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
 }
 
 function install_osm() {
@@ -625,6 +637,10 @@ function dump_vars(){
     echo "INSTALL_NGSA=$INSTALL_NGSA"
     echo "INSTALL_DOCKER=$INSTALL_DOCKER"
     echo "INSTALL_ONLY=$INSTALL_ONLY"
+    echo "INSTALL_ONLY_DEPLOY_OSM=$INSTALL_ONLY_DEPLOY_OSM"
+    echo "INSTALL_ONLY_DOCKER_CE=$INSTALL_ONLY_DOCKER_CE"
+    echo "INSTALL_ONLY_K8S_CLUSTER=$INSTALL_ONLY_K8S_CLUSTER"
+    echo "INSTALL_ONLY_NGSA=$INSTALL_ONLY_NGSA"
     echo "INSTALL_PLA=$INSTALL_PLA"
     echo "INSTALL_TO_OPENSTACK=$INSTALL_TO_OPENSTACK"
     echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
@@ -679,7 +695,7 @@ INSTALL_LXD=""
 SHOWOPTS=""
 ASSUME_YES=""
 APT_PROXY_URL=""
-K8S_CLUSTER_ENGINE="kubeadm"
+K8S_CLUSTER_ENGINE="k3s"
 DEBUG_INSTALL=""
 RELEASE="testing-daily"
 REPOSITORY="testing"
@@ -698,6 +714,10 @@ OPENSTACK_USERDATA_FILE=""
 OPENSTACK_VM_NAME="server-osm"
 OPENSTACK_PYTHON_VENV="$HOME/.virtual-envs/osm"
 INSTALL_ONLY=""
+INSTALL_ONLY_DEPLOY_OSM=""
+INSTALL_ONLY_DOCKER_CE=""
+INSTALL_ONLY_K8S_CLUSTER=""
+INSTALL_ONLY_NGSA=""
 INSTALL_DOCKER=""
 INSTALL_JUJU=""
 INSTALL_NOHOSTCLIENT=""
@@ -746,7 +766,6 @@ while getopts ":a:c:r:n:k:u:R:D:o:O:N:H:S:s:t:U:P:A:l:L:K:d:p:T:f:F:-: hy" o; do
             K8S_CLUSTER_ENGINE=${OPTARG}
             [ "${K8S_CLUSTER_ENGINE}" == "kubeadm" ] && continue
             [ "${K8S_CLUSTER_ENGINE}" == "k3s" ] && continue
-            [ "${K8S_CLUSTER_ENGINE}" == "microk8s" ] && continue
             echo -e "Invalid argument for -c : ' ${K8S_CLUSTER_ENGINE}'\n" >&2
             usage && exit 1
             ;;
@@ -772,7 +791,10 @@ while getopts ":a:c:r:n:k:u:R:D:o:O:N:H:S:s:t:U:P:A:l:L:K:d:p:T:f:F:-: hy" o; do
         o)
             INSTALL_ONLY="y"
             [ "${OPTARG}" == "k8s_monitor" ] && INSTALL_K8S_MONITOR="y" && continue
-            [ "${OPTARG}" == "ng-sa" ] && INSTALL_NGSA="y" && continue
+            [ "${OPTARG}" == "ng-sa" ] && INSTALL_ONLY_NGSA="y" && continue
+            [ "${OPTARG}" == "docker" ] && INSTALL_ONLY_DOCKER_CE="y" && continue
+            [ "${OPTARG}" == "k8scluster" ] && INSTALL_ONLY_K8S_CLUSTER="y" && continue
+            [ "${OPTARG}" == "deploy-osm" ] && INSTALL_ONLY_DEPLOY_OSM="y" && continue
             ;;
         O)
             INSTALL_TO_OPENSTACK="y"
@@ -940,8 +962,11 @@ else
     # Community_installer
     # Special cases go first
     if [ -n "$INSTALL_ONLY" ]; then
+        [ -n "$INSTALL_ONLY_DOCKER_CE" ] && install_docker_ce
+        [ -n "$INSTALL_ONLY_K8S_CLUSTER" ] && install_k8s_cluster
         [ -n "$INSTALL_K8S_MONITOR" ] && install_k8s_monitoring
-        [ -n "$INSTALL_NGSA" ] && install_osm_ngsa_service
+        [ -n "$INSTALL_ONLY_DEPLOY_OSM" ] && deploy_osm
+        [ -n "$INSTALL_ONLY_NGSA" ] && install_osm_ngsa_service
         echo -e "\nDONE" && exit 0
     fi
     # This is where installation starts