+function generate_osmclient_script () {
+ echo "docker run -ti --network net${OSM_STACK_NAME} ${DOCKER_REGISTRY_URL}${DOCKER_USER}/osmclient:${OSM_DOCKER_TAG}" | $WORKDIR_SUDO tee $OSM_DOCKER_WORK_DIR/osm
+ $WORKDIR_SUDO chmod +x "$OSM_DOCKER_WORK_DIR/osm"
+ echo "osmclient sidecar container can be found at: $OSM_DOCKER_WORK_DIR/osm"
+}
+
+#installs kubernetes packages
+function install_kube() {
+ sudo apt-get update && sudo apt-get install -y apt-transport-https
+ curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
+ sudo add-apt-repository "deb https://apt.kubernetes.io/ kubernetes-xenial main"
+ sudo apt-get update
+ echo "Installing Kubernetes Packages ..."
+ sudo apt-get install -y kubelet=1.15.0-00 kubeadm=1.15.0-00 kubectl=1.15.0-00
+ sudo apt-mark hold kubelet kubeadm kubectl
+}
+
+#initializes kubernetes control plane
+function init_kubeadm() {
+ sudo swapoff -a
+ sudo sed -i.bak '/.*none.*swap/s/^\(.*\)$/#\1/g' /etc/fstab
+ sudo kubeadm init --config $1
+ sleep 5
+}
+
+function kube_config_dir() {
+ [ ! -d $K8S_MANIFEST_DIR ] && FATAL "Cannot Install Kubernetes"
+ mkdir -p $HOME/.kube
+ sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config
+ sudo chown $(id -u):$(id -g) $HOME/.kube/config
+}
+
+function install_k8s_storageclass() {
+ echo "Installing OpenEBS"
+ kubectl create ns openebs
+ helm repo add openebs https://openebs.github.io/charts
+ helm repo update
+ helm install --namespace openebs openebs openebs/openebs --version 1.12.0
+ helm ls -n openebs
+ local storageclass_timeout=400
+ local counter=0
+ local storageclass_ready=""
+ echo "Waiting for storageclass"
+ while (( counter < storageclass_timeout ))
+ do
+ kubectl get storageclass openebs-hostpath &> /dev/null
+
+ if [ $? -eq 0 ] ; then
+ echo "Storageclass available"
+ storageclass_ready="y"
+ break
+ else
+ counter=$((counter + 15))
+ sleep 15
+ fi
+ done
+ [ -n "$storageclass_ready" ] || FATAL "Storageclass not ready after $storageclass_timeout seconds. Cannot install openebs"
+ kubectl patch storageclass openebs-hostpath -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
+}
+
+function install_k8s_metallb() {
+ METALLB_IP_RANGE=$DEFAULT_IP-$DEFAULT_IP
+ cat ${OSM_DEVOPS}/installers/k8s/metallb/metallb.yaml | kubectl apply -f -
+ echo "apiVersion: v1
+kind: ConfigMap
+metadata:
+ namespace: metallb-system
+ name: config
+data:
+ config: |
+ address-pools:
+ - name: default
+ protocol: layer2
+ addresses:
+ - $METALLB_IP_RANGE" | kubectl apply -f -
+}
+#deploys flannel as daemonsets
+function deploy_cni_provider() {
+ CNI_DIR="$(mktemp -d -q --tmpdir "flannel.XXXXXX")"
+ trap 'rm -rf "${CNI_DIR}"' EXIT
+ wget -q https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml -P $CNI_DIR
+ kubectl apply -f $CNI_DIR
+ [ $? -ne 0 ] && FATAL "Cannot Install Flannel"
+}
+
+#creates secrets from env files which will be used by containers
+function kube_secrets(){
+ kubectl create ns $OSM_STACK_NAME
+ kubectl create secret generic lcm-secret -n $OSM_STACK_NAME --from-env-file=$OSM_DOCKER_WORK_DIR/lcm.env
+ kubectl create secret generic mon-secret -n $OSM_STACK_NAME --from-env-file=$OSM_DOCKER_WORK_DIR/mon.env
+ kubectl create secret generic nbi-secret -n $OSM_STACK_NAME --from-env-file=$OSM_DOCKER_WORK_DIR/nbi.env
+ kubectl create secret generic ro-db-secret -n $OSM_STACK_NAME --from-env-file=$OSM_DOCKER_WORK_DIR/ro-db.env
+ kubectl create secret generic ro-secret -n $OSM_STACK_NAME --from-env-file=$OSM_DOCKER_WORK_DIR/ro.env
+ kubectl create secret generic keystone-secret -n $OSM_STACK_NAME --from-env-file=$OSM_DOCKER_WORK_DIR/keystone.env
+ kubectl create secret generic pol-secret -n $OSM_STACK_NAME --from-env-file=$OSM_DOCKER_WORK_DIR/pol.env
+}
+
+#taints K8s master node
+function taint_master_node() {
+ K8S_MASTER=$(kubectl get nodes | awk '$3~/master/'| awk '{print $1}')
+ kubectl taint node $K8S_MASTER node-role.kubernetes.io/master:NoSchedule-
+ sleep 5
+}
+
+#deploys osm pods and services
+function deploy_osm_services() {
+ kubectl apply -n $OSM_STACK_NAME -f $OSM_K8S_WORK_DIR
+}
+
+#deploy charmed services
+function deploy_charmed_services() {
+ juju add-model $OSM_STACK_NAME $OSM_VCA_K8S_CLOUDNAME
+ juju deploy ch:mongodb-k8s -m $OSM_STACK_NAME
+}
+
+function deploy_osm_pla_service() {
+ # corresponding to namespace_vol
+ $WORKDIR_SUDO sed -i "s#path: /var/lib/osm#path: $OSM_NAMESPACE_VOL#g" $OSM_DOCKER_WORK_DIR/osm_pla/pla.yaml
+ # corresponding to deploy_osm_services
+ kubectl apply -n $OSM_STACK_NAME -f $OSM_DOCKER_WORK_DIR/osm_pla
+}
+
+#Install Helm v3
+function install_helm() {
+ helm > /dev/null 2>&1
+ if [ $? != 0 ] ; then
+ # Helm is not installed. Install helm
+ echo "Helm is not installed, installing ..."
+ curl https://get.helm.sh/helm-v3.6.3-linux-amd64.tar.gz --output helm-v3.6.3.tar.gz
+ tar -zxvf helm-v3.6.3.tar.gz
+ sudo mv linux-amd64/helm /usr/local/bin/helm
+ rm -r linux-amd64
+ rm helm-v3.6.3.tar.gz
+ helm repo add stable https://charts.helm.sh/stable
+ helm repo update
+ fi
+}
+
+function parse_yaml() {
+ TAG=$1
+ shift
+ services=$@
+ for module in $services; do
+ if [ "$module" == "pla" ]; then
+ if [ -n "$INSTALL_PLA" ]; then
+ echo "Updating K8s manifest file from opensourcemano\/${module}:.* to ${DOCKER_REGISTRY_URL}${DOCKER_USER}\/${module}:${TAG}"
+ $WORKDIR_SUDO sed -i "s#opensourcemano/pla:.*#${DOCKER_REGISTRY_URL}${DOCKER_USER}/pla:${TAG}#g" ${OSM_DOCKER_WORK_DIR}/osm_pla/pla.yaml
+ fi
+ else
+ echo "Updating K8s manifest file from opensourcemano\/${module}:.* to ${DOCKER_REGISTRY_URL}${DOCKER_USER}\/${module}:${TAG}"
+ $WORKDIR_SUDO sed -i "s#opensourcemano/${module}:.*#${DOCKER_REGISTRY_URL}${DOCKER_USER}/${module}:${TAG}#g" ${OSM_K8S_WORK_DIR}/${module}.yaml
+ fi
+ done
+}
+
+function update_manifest_files() {
+ osm_services="nbi lcm ro pol mon ng-ui keystone pla"
+ list_of_services=""
+ for module in $osm_services; do
+ module_upper="${module^^}"
+ if ! echo $TO_REBUILD | grep -q $module_upper ; then
+ list_of_services="$list_of_services $module"
+ fi
+ done
+ if [ ! "$OSM_DOCKER_TAG" == "10" ]; then
+ parse_yaml $OSM_DOCKER_TAG $list_of_services
+ fi
+ if [ -n "$MODULE_DOCKER_TAG" ]; then
+ parse_yaml $MODULE_DOCKER_TAG $list_of_services_to_rebuild
+ fi
+}
+
+function namespace_vol() {
+ osm_services="nbi lcm ro pol mon kafka mysql prometheus"
+ for osm in $osm_services; do
+ $WORKDIR_SUDO sed -i "s#path: /var/lib/osm#path: $OSM_NAMESPACE_VOL#g" $OSM_K8S_WORK_DIR/$osm.yaml
+ done
+}
+
+function init_docker_swarm() {