From 9bae86f02d596295c9a552b65f177d13a1de4013 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Fri, 31 May 2024 17:15:18 +0200 Subject: [PATCH] Refactor code in full_install_osm.sh to group code in functions Change-Id: I5a9aadba811af4f2d2b2f331faf6dd8dbf6d2b43 Signed-off-by: garciadeblas --- installers/full_install_osm.sh | 88 ++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 31 deletions(-) diff --git a/installers/full_install_osm.sh b/installers/full_install_osm.sh index a2677504..92ec4fa9 100755 --- a/installers/full_install_osm.sh +++ b/installers/full_install_osm.sh @@ -199,7 +199,7 @@ function docker_login() { } #deploys osm pods and services -function deploy_osm_services() { +function deploy_osm_helm_chart() { [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function # Generate helm values to be passed with -f osm-values.yaml sudo mkdir -p ${OSM_HELM_WORK_DIR} @@ -382,6 +382,7 @@ Do you want to proceed with the installation (Y/n)? " y && echo "Cancelled!" && } function find_devops_folder() { + [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function if [ -z "$OSM_DEVOPS" ]; then if [ -n "$TEST_INSTALLER" ]; then echo -e "\nUsing local devops repo for OSM installation" @@ -393,6 +394,49 @@ function find_devops_folder() { git clone https://osm.etsi.org/gerrit/osm/devops.git $OSM_DEVOPS fi fi + [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function +} + +function install_lxd() { + [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function + LXD_INSTALL_OPTS="-D ${OSM_DEVOPS} -i ${OSM_DEFAULT_IF} ${DEBUG_INSTALL}" + [ -n "${OSM_BEHIND_PROXY}" ] && LXD_INSTALL_OPTS="${LXD_INSTALL_OPTS} -P" + $OSM_DEVOPS/installers/install_lxd.sh ${LXD_INSTALL_OPTS} || FATAL_TRACK lxd "install_lxd.sh failed" + [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function +} + +function install_docker_ce() { + [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function + 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" + [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function +} + +function install_k8s_cluster() { + [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function + if [ "${K8S_CLUSTER_ENGINE}" == "kubeadm" ]; then + 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}" + $OSM_DEVOPS/installers/install_cluster_addons.sh ${K8SCLUSTER_ADDONS_INSTALL_OPTS} || \ + FATAL_TRACK k8scluster "install_cluster_addons.sh failed" + fi + [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function +} + +function deploy_osm() { + deploy_mongodb + track deploy_osm deploy_mongodb_ok + deploy_osm_helm_chart + track deploy_osm deploy_osm_services_k8s_ok + if [ -n "$INSTALL_NGSA" ]; then + # optional NGSA install + install_osm_ngsa_service + track deploy_osm install_osm_ngsa_ok + fi } function install_osm() { @@ -430,11 +474,7 @@ function install_osm() { [ -n "$APT_PROXY_URL" ] && configure_apt_proxy $APT_PROXY_URL # if lxd is requested, we will install it - if [ -n "$INSTALL_LXD" ]; then - LXD_INSTALL_OPTS="-D ${OSM_DEVOPS} -i ${OSM_DEFAULT_IF} ${DEBUG_INSTALL}" - [ -n "${OSM_BEHIND_PROXY}" ] && LXD_INSTALL_OPTS="${LXD_INSTALL_OPTS} -P" - $OSM_DEVOPS/installers/install_lxd.sh ${LXD_INSTALL_OPTS} || FATAL_TRACK lxd "install_lxd.sh failed" - fi + [ -n "$INSTALL_LXD" ] && install_lxd track prereq prereqok_ok @@ -442,10 +482,7 @@ function install_osm() { 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" + install_docker_ce fi track docker_ce docker_ce_ok @@ -453,14 +490,7 @@ function install_osm() { FATAL_TRACK k8scluster "install_helm_client.sh failed" track helm_client install_helm_client_ok - if [ "${K8S_CLUSTER_ENGINE}" == "kubeadm" ]; then - 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}" - $OSM_DEVOPS/installers/install_cluster_addons.sh ${K8SCLUSTER_ADDONS_INSTALL_OPTS} || \ - FATAL_TRACK k8scluster "install_cluster_addons.sh failed" - fi + install_k8s_cluster track k8scluster k8scluster_ok if [ -n "${INSTALL_JUJU}" ]; then @@ -475,23 +505,17 @@ function install_osm() { fi track juju juju_ok - # Deploy OSM services + # This track is maintained for backwards compatibility track docker_images docker_images_ok - deploy_mongodb - track deploy_osm deploy_mongodb_ok - deploy_osm_services - track deploy_osm deploy_osm_services_k8s_ok + # Deploy OSM (mongodb, OSM helm chart, NGSA) + deploy_osm + if [ -n "$INSTALL_K8S_MONITOR" ]; then # install OSM MONITORING install_k8s_monitoring track deploy_osm install_k8s_monitoring_ok fi - if [ -n "$INSTALL_NGSA" ]; then - # optional NGSA install - install_osm_ngsa_service - track deploy_osm install_osm_ngsa_ok - fi [ -z "$INSTALL_NOHOSTCLIENT" ] && install_osmclient track osmclient osmclient_ok @@ -915,9 +939,11 @@ elif [ -n "$INSTALL_TO_OPENSTACK" ]; then else # Community_installer # Special cases go first - [ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_K8S_MONITOR" ] && install_k8s_monitoring - [ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_NGSA" ] && install_osm_ngsa_service - [ -n "$INSTALL_ONLY" ] && echo -e "\nDONE" && exit 0 + if [ -n "$INSTALL_ONLY" ]; then + [ -n "$INSTALL_K8S_MONITOR" ] && install_k8s_monitoring + [ -n "$INSTALL_NGSA" ] && install_osm_ngsa_service + echo -e "\nDONE" && exit 0 + fi # This is where installation starts install_osm echo -e "\nDONE" -- 2.25.1