+function generate_osmclient_script () {
+ echo "docker run -ti --network net${OSM_STACK_NAME} ${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
+}
+
+#initializes kubernetes control plane
+function init_kubeadm() {
+ sudo swapoff -a
+ 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() {
+ kubectl apply -f https://openebs.github.io/charts/openebs-operator-1.6.0.yaml
+ local storageclass_timeout=300
+ local counter=0
+ echo "Waiting for storageclass"
+ while (( counter < storageclass_timeout ))
+ do
+ kubectl get storageclass openebs-hostpath &> /dev/null
+
+ if [ $? -eq 0 ] ; then
+ echo "Storageclass available"
+ break
+ else
+ counter=$((counter + 15))
+ sleep 15
+ fi
+ done
+ 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 lwui-secret -n $OSM_STACK_NAME --from-env-file=$OSM_DOCKER_WORK_DIR/lwui.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
+ # deploy mongodb charm
+ namespace=$OSM_STACK_NAME
+ juju deploy cs:~charmed-osm/mongodb-k8s \
+ --config enable-sidecar=true \
+ --config replica-set=rs0 \
+ --config namespace=$namespace \
+ -m $namespace
+}
+
+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 and tiller
+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-v2.15.2-linux-amd64.tar.gz --output helm-v2.15.2.tar.gz
+ tar -zxvf helm-v2.15.2.tar.gz
+ sudo mv linux-amd64/helm /usr/local/bin/helm
+ rm -r linux-amd64
+ rm helm-v2.15.2.tar.gz
+ fi
+
+ # Checking if tiller has being configured
+ kubectl --namespace kube-system get serviceaccount tiller > /dev/null 2>&1
+ if [ $? == 1 ] ; then
+ # tiller account for kubernetes
+ kubectl --namespace kube-system create serviceaccount tiller
+ kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
+ # HELM initialization
+ helm init --service-account tiller
+
+ # Wait for Tiller to be up and running. If timeout expires, continue installing
+ tiller_timeout=120;
+ counter=0;
+ tiller_status=""
+ while (( counter < tiller_timeout ))
+ do
+ tiller_status=`kubectl -n kube-system get deployment.apps/tiller-deploy --no-headers | awk '{print $2'}`
+ ( [ ! -z "$tiller_status" ] && [ $tiller_status == "1/1" ] ) && echo "Tiller ready" && break
+ counter=$((counter + 5))
+ sleep 5
+ done
+ [ "$tiller_status" != "1/1" ] && echo "Tiller is NOT READY YET. Installation will continue"
+ fi
+}
+
+function parse_yaml() {
+ osm_services="nbi lcm ro pol mon light-ui ng-ui keystone"
+ TAG=$1
+ for osm in $osm_services; do
+ $WORKDIR_SUDO sed -i "s/opensourcemano\/$osm:.*/$DOCKER_USER\/$osm:$TAG/g" $OSM_K8S_WORK_DIR/$osm.yaml
+ done
+ $WORKDIR_SUDO sed -i "s/opensourcemano\/pla:.*/$DOCKER_USER\/\/pla:$OSM_DOCKER_TAG/g" $OSM_DOCKER_WORK_DIR/osm_pla/pla.yaml
+}
+
+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
+}
+