From: zamre Date: Mon, 16 Oct 2023 16:47:10 +0000 (+0000) Subject: Feature 11007: replace charmed mongodb with bitnami helm chart X-Git-Tag: release-v15.0-start~12 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2Fdevops.git;a=commitdiff_plain;h=4db5d53daaac39a25d870bbb404b339407b9ebb2 Feature 11007: replace charmed mongodb with bitnami helm chart This change replaces charmed MongoDB with Bitnami helm chart. The values passed to the helm chart use the same service name that existed previously, mongodb-k8s, so that no other changes are required in the rest of modules. It also modifies OSM health checks to successfully pass mongodb health check. Change-Id: I52b938598314ed75d2f248e9399dcae60934bd3e Signed-off-by: zamre --- diff --git a/installers/full_install_osm.sh b/installers/full_install_osm.sh index 15aee9c9..e053bd7d 100755 --- a/installers/full_install_osm.sh +++ b/installers/full_install_osm.sh @@ -308,7 +308,10 @@ function deploy_charmed_services() { #deploy mongodb function deploy_mongodb() { [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function - deploy_charmed_services + MONGO_OPTS="-d ${OSM_HELM_WORK_DIR} -D ${OSM_DEVOPS} -t ${OSM_DOCKER_TAG} -U ${DOCKER_USER} ${DEBUG_INSTALL}" + [ -n "${DOCKER_REGISTRY_URL}" ] && MONGO_OPTS="${MONGO_OPTS} -r ${DOCKER_REGISTRY_URL}" + $OSM_DEVOPS/installers/install_mongodb.sh ${MONGO_OPTS} || \ + FATAL_TRACK install_osm_mongodb_service "install_mongodb.sh failed" [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function } diff --git a/installers/helm/values/mongodb-values.yaml b/installers/helm/values/mongodb-values.yaml new file mode 100644 index 00000000..41ef151a --- /dev/null +++ b/installers/helm/values/mongodb-values.yaml @@ -0,0 +1,19 @@ +# +# 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. +# +--- +service: + nameOverride: "mongodb-k8s" +auth: + enabled: false +architecture: "replicaset" \ No newline at end of file diff --git a/installers/install_mongodb.sh b/installers/install_mongodb.sh new file mode 100755 index 00000000..d13fc1e2 --- /dev/null +++ b/installers/install_mongodb.sh @@ -0,0 +1,88 @@ +#!/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 chart 13.9.4 correspondes to Mongo DB 6.0.5 +MONGODB_HELM_VERSION=13.9.4 + + +# Install MongoDB helm chart +function install_mongodb() { + [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function + # copy mongodb-values.yaml to the destination folder + sudo mkdir -p ${OSM_HELM_WORK_DIR} + sudo cp ${OSM_DEVOPS}/installers/helm/values/mongodb-values.yaml ${OSM_HELM_WORK_DIR} + # update mongodb-values.yaml to use the right tag + + helm repo add bitnami https://charts.bitnami.com/bitnami + helm repo update + helm upgrade mongodb-k8s bitnami/mongodb -n osm --create-namespace --install -f ${OSM_HELM_WORK_DIR}/mongodb-values.yaml --version ${MONGODB_HELM_VERSION} --timeout 10m || FATAL_TRACK mongodb "Failed installing mongodb helm chart" + [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function +} + +# main + +DOCKER_REGISTRY_URL= +DOCKER_USER="opensourcemano" +OSM_DEVOPS="/usr/share/osm-devops" +OSM_DOCKER_TAG="testing-daily" +OSM_HELM_WORK_DIR="/etc/osm/helm" + +while getopts ":D:d:t:r:U:-: " o; do + case "${o}" in + D) + OSM_DEVOPS="${OPTARG}" + ;; + d) + OSM_HELM_WORK_DIR="${OPTARG}" + ;; + t) + OSM_DOCKER_TAG="${OPTARG}" + ;; + r) + DOCKER_REGISTRY_URL="${OPTARG}" + ;; + U) + DOCKER_USER="${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 "OSM_DEVOPS=$OSM_DEVOPS" +echo "OSM_DOCKER_TAG=$OSM_DOCKER_TAG" +echo "OSM_HELM_WORK_DIR=$OSM_HELM_WORK_DIR" + +install_mongodb diff --git a/installers/osm_health.sh b/installers/osm_health.sh index 077290be..16b74cf5 100755 --- a/installers/osm_health.sh +++ b/installers/osm_health.sh @@ -72,8 +72,8 @@ do # State of Statefulsets STS_STATE=$(kubectl get statefulset -n ${STACK_NAME} --no-headers 2>&1) - STS_READY=$(echo "${STS_STATE}" | awk '$2=="1/1" {printf ("%20s\t%s\t%s\n", $1, $2, $4)}') - STS_NOT_READY=$(echo "${STS_STATE}" | awk '$2!="1/1" {printf ("%20s\t%s\t%s\n", $1, $2, $4)}') + STS_READY=$(echo "${STS_STATE}" | awk '$2=="1/1" || $2=="2/2" {printf ("%20s\t%s\t%s\n", $1, $2, $4)}') + STS_NOT_READY=$(echo "${STS_STATE}" | awk '$2!="1/1" && $2!="2/2" {printf ("%20s\t%s\t%s\n", $1, $2, $4)}') COUNT_STS_READY=$(echo "${STS_READY}" | grep -v -e '^$' | wc -l) COUNT_STS_NOT_READY=$(echo "${STS_NOT_READY}" | grep -v -e '^$' | wc -l)