-function install_k8s_storageclass() {
- [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
- echo "Installing open-iscsi"
- sudo apt-get update
- sudo apt-get install open-iscsi
- sudo systemctl enable --now iscsid
- OPENEBS_VERSION="3.1.0"
- echo "Installing OpenEBS"
- helm repo add openebs https://openebs.github.io/charts
- helm repo update
- helm install --create-namespace --namespace openebs openebs openebs/openebs --version ${OPENEBS_VERSION}
- 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_TRACK k8scluster "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"}}}'
- [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
-}
-
-#installs metallb from helm
-function install_helm_metallb() {
- [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
- echo "Installing MetalLB"
- METALLB_VERSION="0.11.0"
- METALLB_IP_RANGE="$DEFAULT_IP/32"
- echo "configInline:
- address-pools:
- - name: default
- protocol: layer2
- addresses:
- - $METALLB_IP_RANGE" | sudo tee -a ${OSM_DOCKER_WORK_DIR}/metallb-config.yaml
- helm repo add metallb https://metallb.github.io/metallb
- helm repo update
- helm install --create-namespace --namespace metallb-system metallb metallb/metallb --version ${METALLB_VERSION} -f ${OSM_DOCKER_WORK_DIR}/metallb-config.yaml
- [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
-}
-
-#checks openebs and metallb readiness
-function check_for_readiness() {
- [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
- # Default input values
- sampling_period=2 # seconds
- time_for_readiness=20 # seconds ready
- time_for_failure=200 # seconds broken
- OPENEBS_NAMESPACE=openebs
- METALLB_NAMESPACE=metallb-system
- # STACK_NAME=osm # By default, "osm"
-
- # Equivalent number of samples
- oks_threshold=$((time_for_readiness/${sampling_period})) # No. ok samples to declare the system ready
- failures_threshold=$((time_for_failure/${sampling_period})) # No. nok samples to declare the system broken
- failures_in_a_row=0
- oks_in_a_row=0
-
- ####################################################################################
- # Loop to check system readiness
- ####################################################################################
- while [[ (${failures_in_a_row} -lt ${failures_threshold}) && (${oks_in_a_row} -lt ${oks_threshold}) ]]
- do
- # State of OpenEBS
- OPENEBS_STATE=$(kubectl get pod -n ${OPENEBS_NAMESPACE} --no-headers 2>&1)
- OPENEBS_READY=$(echo "${OPENEBS_STATE}" | awk '$2=="1/1" || $2=="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
- OPENEBS_NOT_READY=$(echo "${OPENEBS_STATE}" | awk '$2!="1/1" && $2!="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
- COUNT_OPENEBS_READY=$(echo "${OPENEBS_READY}"| grep -v -e '^$' | wc -l)
- COUNT_OPENEBS_NOT_READY=$(echo "${OPENEBS_NOT_READY}" | grep -v -e '^$' | wc -l)
-
- # State of MetalLB
- METALLB_STATE=$(kubectl get pod -n ${METALLB_NAMESPACE} --no-headers 2>&1)
- METALLB_READY=$(echo "${METALLB_STATE}" | awk '$2=="1/1" || $2=="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
- METALLB_NOT_READY=$(echo "${METALLB_STATE}" | awk '$2!="1/1" && $2!="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
- COUNT_METALLB_READY=$(echo "${METALLB_READY}" | grep -v -e '^$' | wc -l)
- COUNT_METALLB_NOT_READY=$(echo "${METALLB_NOT_READY}" | grep -v -e '^$' | wc -l)
-
- # OK sample
- if [[ $((${COUNT_OPENEBS_NOT_READY}+${COUNT_METALLB_NOT_READY})) -eq 0 ]]
- then
- ((++oks_in_a_row))
- failures_in_a_row=0
- echo -ne ===\> Successful checks: "${oks_in_a_row}"/${oks_threshold}\\r
- # NOK sample
- else
- ((++failures_in_a_row))
- oks_in_a_row=0
- echo
- echo Bootstraping... "${failures_in_a_row}" checks of ${failures_threshold}
-
- # Reports failed pods in OpenEBS
- if [[ "${COUNT_OPENEBS_NOT_READY}" -ne 0 ]]
- then
- echo "OpenEBS: Waiting for ${COUNT_OPENEBS_NOT_READY} of $((${COUNT_OPENEBS_NOT_READY}+${COUNT_OPENEBS_READY})) pods to be ready:"
- echo "${OPENEBS_NOT_READY}"
- echo
- fi
-
- # Reports failed statefulsets
- if [[ "${COUNT_METALLB_NOT_READY}" -ne 0 ]]
- then
- echo "MetalLB: Waiting for ${COUNT_METALLB_NOT_READY} of $((${COUNT_METALLB_NOT_READY}+${COUNT_METALLB_READY})) pods to be ready:"
- echo "${METALLB_NOT_READY}"
- echo
- fi
- fi
-
- #------------ NEXT SAMPLE
- sleep ${sampling_period}
- done
-
- ####################################################################################
- # OUTCOME
- ####################################################################################
- if [[ (${failures_in_a_row} -ge ${failures_threshold}) ]]
- then
- echo
- FATAL_TRACK k8scluster "K8S CLUSTER IS BROKEN"
- else
- echo
- echo "K8S CLUSTER IS READY"
- fi
- [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
-}
-
-#removes osm deployments and services