Separate helm client installation from install_kubeadm_cluster 90/14290/1
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 1 Apr 2024 13:01:27 +0000 (15:01 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Mon, 1 Apr 2024 13:09:46 +0000 (15:09 +0200)
Change-Id: I3179800acf111516dfc0750d98d6fd4edf3c47a9
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
installers/full_install_osm.sh
installers/install_helm_client.sh [new file with mode: 0755]
installers/install_kubeadm_cluster.sh

index fb8270f..b25cdaa 100755 (executable)
@@ -493,19 +493,26 @@ function install_osm() {
     track prereq prereqok_ok
 
     if [ -n "$INSTALL_DOCKER" ] || [ "${K8S_CLUSTER_ENGINE}" == "kubeadm" ]; then
+        if [ "${K8S_CLUSTER_ENGINE}" == "kubeadm" ]; then
+            echo "Kubeadm requires docker, so docker will be installed."
+        fi
         DOCKER_CE_OPTS="-D ${OSM_DEVOPS} ${DEBUG_INSTALL}"
         [ -n "${DOCKER_PROXY_URL}" ] && DOCKER_CE_OPTS="${DOCKER_CE_OPTS} -p ${DOCKER_PROXY_URL}"
         [ -n "${OSM_BEHIND_PROXY}" ] && DOCKER_CE_OPTS="${DOCKER_CE_OPTS} -P"
         $OSM_DEVOPS/installers/install_docker_ce.sh ${DOCKER_CE_OPTS} || FATAL_TRACK docker_ce "install_docker_ce.sh failed"
     fi
-
     track docker_ce docker_ce_ok
 
+    $OSM_DEVOPS/installers/install_helm_client.sh -D ${OSM_DEVOPS} ${DEBUG_INSTALL} || \
+    FATAL_TRACK k8scluster "install_helm_client.sh failed"
+    track helm_client install_helm_client_ok
+
     if [ "${K8S_CLUSTER_ENGINE}" == "kubeadm" ]; then
-        $OSM_DEVOPS/installers/install_kubeadm_cluster.sh -i ${OSM_DEFAULT_IP} -d ${OSM_WORK_DIR} -D ${OSM_DEVOPS} ${DEBUG_INSTALL} || \
+        KUBEADM_INSTALL_OPTS="-i ${OSM_DEFAULT_IP} -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"
-        track k8scluster k8scluster_ok
     fi
+    track k8scluster k8scluster_ok
 
     if [ -n "${INSTALL_JUJU}" ]; then
         JUJU_OPTS="-D ${OSM_DEVOPS} -s ${OSM_NAMESPACE} -i ${OSM_DEFAULT_IP} ${DEBUG_INSTALL} ${INSTALL_CACHELXDIMAGES}"
diff --git a/installers/install_helm_client.sh b/installers/install_helm_client.sh
new file mode 100755 (executable)
index 0000000..d66a017
--- /dev/null
@@ -0,0 +1,73 @@
+#!/bin/bash
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+
+set +eux
+
+HELM_VERSION="v3.11.3"
+
+#Install Helm v3
+#Helm releases can be found here: https://github.com/helm/helm/releases
+function install_helm_client() {
+    [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+    if ! [[ "$(helm version --short 2>/dev/null)" =~ ^v3.* ]]; then
+        # Helm is not installed. Install helm
+        echo "Helm3 is not installed, installing ..."
+        curl https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz --output helm-${HELM_VERSION}.tar.gz
+        tar -zxvf helm-${HELM_VERSION}.tar.gz
+        sudo mv linux-amd64/helm /usr/local/bin/helm
+        rm -r linux-amd64
+        rm helm-${HELM_VERSION}.tar.gz
+    else
+        echo "Helm3 is already installed. Skipping installation..."
+    fi
+    helm version || FATAL_TRACK k8scluster "Could not obtain helm version. Maybe helm client was not installed"
+    helm repo add stable https://charts.helm.sh/stable || FATAL_TRACK k8scluster "Helm repo stable could not be added"
+    helm repo update || FATAL_TRACK k8scluster "Helm repo stable could not be updated"
+    [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+# main
+while getopts ":D:-: " o; do
+    case "${o}" in
+        D)
+            OSM_DEVOPS="${OPTARG}"
+            ;;
+        -)
+            [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="y" && continue
+            echo -e "Invalid option: '--$OPTARG'\n" >&2
+            exit 1
+            ;;
+        :)
+            echo "Option -$OPTARG requires an argument" >&2
+            exit 1
+            ;;
+        \?)
+            echo -e "Invalid option: '-$OPTARG'\n" >&2
+            exit 1
+            ;;
+        *)
+            exit 1
+            ;;
+    esac
+done
+
+source $OSM_DEVOPS/common/logging
+source $OSM_DEVOPS/common/track
+
+echo "DEBUG_INSTALL=$DEBUG_INSTALL"
+echo "DEFAULT_IP=$DEFAULT_IP"
+echo "OSM_DEVOPS=$OSM_DEVOPS"
+
+install_helm_client
index c616c36..feb1e59 100755 (executable)
@@ -370,7 +370,8 @@ check_and_track_k8s_ready_before_helm
 
 remove_k8s_namespace osm
 
-install_helm
+# install_helm has been moved to install_helm_client.sh, run from full_install_osm.sh,
+# but tracking is still here because the installation analytics still expects it
 track k8scluster install_helm_ok
 
 install_k8s_storageclass