| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | # |
| 15 | |
| 16 | set +eux |
| 17 | |
| Pedro Escaleira | 6272e40 | 2024-03-05 17:56:23 +0000 | [diff] [blame] | 18 | K8S_VERSION=1.28 |
| 19 | K8S_PACKAGE_VERSION="$K8S_VERSION".2-1.1 |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 20 | |
| 21 | # installs kubernetes packages |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 22 | function install_kube() { |
| 23 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| garciadeblas | c1ae239 | 2021-12-14 18:02:30 +0100 | [diff] [blame] | 24 | # Kubernetes releases can be found here: https://kubernetes.io/releases/ |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 25 | # To check other available versions, run the following command |
| 26 | # curl -s https://packages.cloud.google.com/apt/dists/kubernetes-xenial/main/binary-amd64/Packages | grep Version | awk '{print $2}' |
| garciadeblas | 80b2e17 | 2023-06-01 18:38:13 +0200 | [diff] [blame] | 27 | sudo apt-get -y update && sudo apt-get install -y apt-transport-https ca-certificates curl |
| Pedro Escaleira | 44403b7 | 2024-03-04 17:07:11 +0000 | [diff] [blame] | 28 | curl -fsSL https://pkgs.k8s.io/core:/stable:/v"$K8S_VERSION"/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg |
| 29 | echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v'$K8S_VERSION'/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list |
| garciadeblas | 80b2e17 | 2023-06-01 18:38:13 +0200 | [diff] [blame] | 30 | sudo apt-get -y update |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 31 | echo "Installing Kubernetes Packages ..." |
| Pedro Escaleira | 44403b7 | 2024-03-04 17:07:11 +0000 | [diff] [blame] | 32 | sudo apt-get install -y kubelet=${K8S_PACKAGE_VERSION} kubeadm=${K8S_PACKAGE_VERSION} kubectl=${K8S_PACKAGE_VERSION} |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 33 | sudo apt-mark hold kubelet kubeadm kubectl |
| 34 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 35 | } |
| 36 | |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 37 | # check and track kube packages installation |
| 38 | function check_and_track_kube_install() { |
| 39 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| 40 | kubelet_version=$(dpkg -s kubelet|grep Version|awk '{print $2}') |
| 41 | [ -n "${kubelet_version}" ] || FATAL_TRACK k8scluster "Kubelet was not installed." |
| 42 | kubeadm_version=$(dpkg -s kubeadm|grep Version|awk '{print $2}') |
| 43 | [ -n "${kubeadm_version}" ] || FATAL_TRACK k8scluster "Kubeadm was not installed." |
| 44 | kubectl_version=$(dpkg -s kubectl|grep Version|awk '{print $2}') |
| 45 | [ -n "${kubectl_version}" ] || FATAL_TRACK k8scluster "Kubectl was not installed." |
| garciadeblas | b17abf7 | 2023-06-06 18:56:32 +0200 | [diff] [blame] | 46 | track k8scluster install_k8s_ok none none none kubelet ${kubelet_version} none none kubeadm ${kubeadm_version} none none kubectl ${kubectl_version} none none |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 47 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 48 | } |
| 49 | |
| 50 | # initializes kubernetes control plane |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 51 | function init_kubeadm() { |
| 52 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| garciadeblas | e797414 | 2024-10-03 10:49:26 +0200 | [diff] [blame] | 53 | sudo modprobe br_netfilter |
| 54 | echo "br_netfilter" | sudo tee /etc/modules-load.d/k8s.conf |
| 55 | sudo sysctl -w net.bridge.bridge-nf-call-iptables=1 |
| 56 | echo "net.bridge.bridge-nf-call-iptables=1" | sudo tee /etc/sysctl.d/k8s.conf |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 57 | sudo swapoff -a |
| 58 | sudo sed -i.bak '/.*none.*swap/s/^\(.*\)$/#\1/g' /etc/fstab |
| garciadeblas | 2e1c9f8 | 2023-06-01 14:20:03 +0200 | [diff] [blame] | 59 | sudo kubeadm init --config $1 --dry-run || FATAL_TRACK k8scluster "kubeadm init dry-run failed" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 60 | sudo kubeadm init --config $1 |
| 61 | sleep 5 |
| 62 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 63 | } |
| 64 | |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 65 | # Initializes kubeconfig file |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 66 | function kube_config_dir() { |
| 67 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| 68 | K8S_MANIFEST_DIR="/etc/kubernetes/manifests" |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 69 | [ ! -d $K8S_MANIFEST_DIR ] && FATAL_TRACK k8scluster "Kubernetes folder $K8S_MANIFEST_DIR was not found" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 70 | mkdir -p $HOME/.kube |
| 71 | sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config |
| 72 | sudo chown $(id -u):$(id -g) $HOME/.kube/config |
| 73 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 74 | } |
| 75 | |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 76 | # test kubernetes installation |
| 77 | function check_and_track_init_k8s() { |
| 78 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| garciadeblas | 80b2e17 | 2023-06-01 18:38:13 +0200 | [diff] [blame] | 79 | echo "Reading existing namespaces" |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 80 | kubectl get ns || FATAL_TRACK k8scluster "Failed getting namespaces" |
| 81 | track k8scluster init_k8s_ok |
| 82 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 83 | } |
| 84 | |
| 85 | # deploys flannel as daemonsets |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 86 | function deploy_cni_provider() { |
| 87 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| 88 | CNI_DIR="$(mktemp -d -q --tmpdir "flannel.XXXXXX")" |
| 89 | trap 'rm -rf "${CNI_DIR}"' EXIT |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 90 | KUBE_FLANNEL_FILE_URL="https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml" |
| 91 | wget --retry-on-host-error --retry-on-http-error 404,429,503 --tries=5 "${KUBE_FLANNEL_FILE_URL}" -P $CNI_DIR |
| 92 | [ ! -f $CNI_DIR/kube-flannel.yml ] && FATAL_TRACK k8scluster "Cannot Install Flannel because $CNI_DIR/kube-flannel.yml was not found. Maybe the file ${KUBE_FLANNEL_FILE_URL} is temporarily not accessible" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 93 | kubectl apply -f $CNI_DIR |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 94 | [ $? -ne 0 ] && FATAL_TRACK k8scluster "Cannot Install Flannel" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 95 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 96 | } |
| 97 | |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 98 | # taints K8s master node |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 99 | function taint_master_node() { |
| 100 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| garciadeblas | 80b2e17 | 2023-06-01 18:38:13 +0200 | [diff] [blame] | 101 | K8S_MASTER=$(kubectl get nodes | awk '$3~/control-plane/'| awk '{print $1; exit}') |
| 102 | kubectl taint node $K8S_MASTER node-role.kubernetes.io/control-plane:NoSchedule- |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 103 | sleep 5 |
| 104 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 105 | } |
| 106 | |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 107 | # check and track kube packages installation |
| 108 | function check_and_track_k8s_ready_before_helm() { |
| 109 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| 110 | kubectl get events || FATAL_TRACK k8scluster "Failed getting events" |
| 111 | track k8scluster k8s_ready_before_helm |
| 112 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 113 | } |
| 114 | |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 115 | #Install Helm v3 |
| garciadeblas | c1ae239 | 2021-12-14 18:02:30 +0100 | [diff] [blame] | 116 | #Helm releases can be found here: https://github.com/helm/helm/releases |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 117 | function install_helm() { |
| 118 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| garciadeblas | 171bbd4 | 2023-04-14 10:00:31 +0200 | [diff] [blame] | 119 | HELM_VERSION="v3.11.3" |
| garciadeblas | c1ae239 | 2021-12-14 18:02:30 +0100 | [diff] [blame] | 120 | if ! [[ "$(helm version --short 2>/dev/null)" =~ ^v3.* ]]; then |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 121 | # Helm is not installed. Install helm |
| garciadeblas | c1ae239 | 2021-12-14 18:02:30 +0100 | [diff] [blame] | 122 | echo "Helm3 is not installed, installing ..." |
| 123 | curl https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz --output helm-${HELM_VERSION}.tar.gz |
| 124 | tar -zxvf helm-${HELM_VERSION}.tar.gz |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 125 | sudo mv linux-amd64/helm /usr/local/bin/helm |
| 126 | rm -r linux-amd64 |
| garciadeblas | c1ae239 | 2021-12-14 18:02:30 +0100 | [diff] [blame] | 127 | rm helm-${HELM_VERSION}.tar.gz |
| 128 | else |
| 129 | echo "Helm3 is already installed. Skipping installation..." |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 130 | fi |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 131 | helm version || FATAL_TRACK k8scluster "Could not obtain helm version. Maybe helm client was not installed" |
| 132 | helm repo add stable https://charts.helm.sh/stable || FATAL_TRACK k8scluster "Helm repo stable could not be added" |
| 133 | helm repo update || FATAL_TRACK k8scluster "Helm repo stable could not be updated" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 134 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 135 | } |
| 136 | |
| 137 | function install_k8s_storageclass() { |
| 138 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| garciadeblas | 80b2e17 | 2023-06-01 18:38:13 +0200 | [diff] [blame] | 139 | # Openebs versions can be found here: https://github.com/openebs/openebs/releases |
| 140 | OPENEBS_VERSION="3.7.0" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 141 | echo "Installing OpenEBS" |
| 142 | helm repo add openebs https://openebs.github.io/charts |
| 143 | helm repo update |
| 144 | helm install --create-namespace --namespace openebs openebs openebs/openebs --version ${OPENEBS_VERSION} |
| 145 | helm ls -n openebs |
| 146 | local storageclass_timeout=400 |
| 147 | local counter=0 |
| 148 | local storageclass_ready="" |
| 149 | echo "Waiting for storageclass" |
| 150 | while (( counter < storageclass_timeout )) |
| 151 | do |
| 152 | kubectl get storageclass openebs-hostpath &> /dev/null |
| 153 | |
| 154 | if [ $? -eq 0 ] ; then |
| 155 | echo "Storageclass available" |
| 156 | storageclass_ready="y" |
| 157 | break |
| 158 | else |
| 159 | counter=$((counter + 15)) |
| 160 | sleep 15 |
| 161 | fi |
| 162 | done |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 163 | [ -n "$storageclass_ready" ] || FATAL_TRACK k8scluster "Storageclass not ready after $storageclass_timeout seconds. Cannot install openebs" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 164 | kubectl patch storageclass openebs-hostpath -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}' |
| 165 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 166 | } |
| 167 | |
| 168 | #installs metallb from helm |
| 169 | function install_helm_metallb() { |
| 170 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| 171 | echo "Installing MetalLB" |
| garciadeblas | 80b2e17 | 2023-06-01 18:38:13 +0200 | [diff] [blame] | 172 | METALLB_VERSION="0.13.10" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 173 | helm repo add metallb https://metallb.github.io/metallb |
| 174 | helm repo update |
| garciadeblas | 80b2e17 | 2023-06-01 18:38:13 +0200 | [diff] [blame] | 175 | helm install --create-namespace --namespace metallb-system metallb metallb/metallb --version ${METALLB_VERSION} |
| 176 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 177 | } |
| 178 | |
| 179 | function configure_ipaddresspool_metallb() { |
| 180 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| 181 | echo "Creating IP address pool manifest: ${OSM_CLUSTER_WORK_DIR}/metallb-ipaddrpool.yaml" |
| 182 | METALLB_IP_RANGE="$DEFAULT_IP/32" |
| 183 | echo "apiVersion: metallb.io/v1beta1 |
| 184 | kind: IPAddressPool |
| 185 | metadata: |
| 186 | name: first-pool |
| 187 | namespace: metallb-system |
| 188 | spec: |
| 189 | addresses: |
| 190 | - ${METALLB_IP_RANGE}" | sudo tee -a ${OSM_CLUSTER_WORK_DIR}/metallb-ipaddrpool.yaml |
| 191 | echo "Applying IP address pool manifest: kubectl apply -f ${OSM_CLUSTER_WORK_DIR}/metallb-ipaddrpool.yaml" |
| 192 | kubectl apply -f ${OSM_CLUSTER_WORK_DIR}/metallb-ipaddrpool.yaml || FATAL_TRACK k8scluster "Cannot create IP address Pool in MetalLB" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 193 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 194 | } |
| 195 | |
| Gabriel Cuba | 0d4965f | 2022-11-06 19:39:02 -0500 | [diff] [blame] | 196 | #installs cert-manager |
| 197 | function install_helm_certmanager() { |
| 198 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| 199 | echo "Installing cert-manager" |
| 200 | CERTMANAGER_VERSION="v1.9.1" |
| 201 | helm repo add jetstack https://charts.jetstack.io |
| 202 | helm repo update |
| 203 | helm install cert-manager --create-namespace --namespace cert-manager jetstack/cert-manager \ |
| 204 | --version ${CERTMANAGER_VERSION} --set installCRDs=true --set prometheus.enabled=false \ |
| 205 | --set clusterResourceNamespace=osm \ |
| 206 | --set extraArgs="{--enable-certificate-owner-ref=true}" |
| 207 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 208 | } |
| 209 | |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 210 | #checks openebs and metallb readiness |
| 211 | function check_for_readiness() { |
| 212 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| 213 | # Default input values |
| 214 | sampling_period=2 # seconds |
| 215 | time_for_readiness=20 # seconds ready |
| 216 | time_for_failure=200 # seconds broken |
| 217 | OPENEBS_NAMESPACE=openebs |
| 218 | METALLB_NAMESPACE=metallb-system |
| 219 | # STACK_NAME=osm # By default, "osm" |
| 220 | |
| 221 | # Equivalent number of samples |
| 222 | oks_threshold=$((time_for_readiness/${sampling_period})) # No. ok samples to declare the system ready |
| 223 | failures_threshold=$((time_for_failure/${sampling_period})) # No. nok samples to declare the system broken |
| 224 | failures_in_a_row=0 |
| 225 | oks_in_a_row=0 |
| 226 | |
| 227 | #################################################################################### |
| 228 | # Loop to check system readiness |
| 229 | #################################################################################### |
| 230 | while [[ (${failures_in_a_row} -lt ${failures_threshold}) && (${oks_in_a_row} -lt ${oks_threshold}) ]] |
| 231 | do |
| 232 | # State of OpenEBS |
| 233 | OPENEBS_STATE=$(kubectl get pod -n ${OPENEBS_NAMESPACE} --no-headers 2>&1) |
| 234 | OPENEBS_READY=$(echo "${OPENEBS_STATE}" | awk '$2=="1/1" || $2=="2/2" {printf ("%s\t%s\t\n", $1, $2)}') |
| 235 | OPENEBS_NOT_READY=$(echo "${OPENEBS_STATE}" | awk '$2!="1/1" && $2!="2/2" {printf ("%s\t%s\t\n", $1, $2)}') |
| 236 | COUNT_OPENEBS_READY=$(echo "${OPENEBS_READY}"| grep -v -e '^$' | wc -l) |
| 237 | COUNT_OPENEBS_NOT_READY=$(echo "${OPENEBS_NOT_READY}" | grep -v -e '^$' | wc -l) |
| 238 | |
| 239 | # State of MetalLB |
| 240 | METALLB_STATE=$(kubectl get pod -n ${METALLB_NAMESPACE} --no-headers 2>&1) |
| garciadeblas | 80b2e17 | 2023-06-01 18:38:13 +0200 | [diff] [blame] | 241 | METALLB_READY=$(echo "${METALLB_STATE}" | awk '$2=="1/1" || $2=="4/4" {printf ("%s\t%s\t\n", $1, $2)}') |
| 242 | METALLB_NOT_READY=$(echo "${METALLB_STATE}" | awk '$2!="1/1" && $2!="4/4" {printf ("%s\t%s\t\n", $1, $2)}') |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 243 | COUNT_METALLB_READY=$(echo "${METALLB_READY}" | grep -v -e '^$' | wc -l) |
| 244 | COUNT_METALLB_NOT_READY=$(echo "${METALLB_NOT_READY}" | grep -v -e '^$' | wc -l) |
| 245 | |
| Gabriel Cuba | 0d4965f | 2022-11-06 19:39:02 -0500 | [diff] [blame] | 246 | # State of CertManager |
| 247 | CERTMANAGER_STATE=$(kubectl get pod -n ${CERTMANAGER_NAMESPACE} --no-headers 2>&1) |
| 248 | CERTMANAGER_READY=$(echo "${CERTMANAGER_STATE}" | awk '$2=="1/1" || $2=="2/2" {printf ("%s\t%s\t\n", $1, $2)}') |
| 249 | CERTMANAGER_NOT_READY=$(echo "${CERTMANAGER_STATE}" | awk '$2!="1/1" && $2!="2/2" {printf ("%s\t%s\t\n", $1, $2)}') |
| 250 | COUNT_CERTMANAGER_READY=$(echo "${CERTMANAGER_READY}" | grep -v -e '^$' | wc -l) |
| 251 | COUNT_CERTMANAGER_NOT_READY=$(echo "${CERTMANAGER_NOT_READY}" | grep -v -e '^$' | wc -l) |
| 252 | |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 253 | # OK sample |
| 254 | if [[ $((${COUNT_OPENEBS_NOT_READY}+${COUNT_METALLB_NOT_READY})) -eq 0 ]] |
| 255 | then |
| 256 | ((++oks_in_a_row)) |
| 257 | failures_in_a_row=0 |
| 258 | echo -ne ===\> Successful checks: "${oks_in_a_row}"/${oks_threshold}\\r |
| 259 | # NOK sample |
| 260 | else |
| 261 | ((++failures_in_a_row)) |
| 262 | oks_in_a_row=0 |
| 263 | echo |
| 264 | echo Bootstraping... "${failures_in_a_row}" checks of ${failures_threshold} |
| 265 | |
| 266 | # Reports failed pods in OpenEBS |
| 267 | if [[ "${COUNT_OPENEBS_NOT_READY}" -ne 0 ]] |
| 268 | then |
| 269 | echo "OpenEBS: Waiting for ${COUNT_OPENEBS_NOT_READY} of $((${COUNT_OPENEBS_NOT_READY}+${COUNT_OPENEBS_READY})) pods to be ready:" |
| 270 | echo "${OPENEBS_NOT_READY}" |
| 271 | echo |
| 272 | fi |
| 273 | |
| Gabriel Cuba | 0d4965f | 2022-11-06 19:39:02 -0500 | [diff] [blame] | 274 | # Reports failed pods in MetalLB |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 275 | if [[ "${COUNT_METALLB_NOT_READY}" -ne 0 ]] |
| 276 | then |
| 277 | echo "MetalLB: Waiting for ${COUNT_METALLB_NOT_READY} of $((${COUNT_METALLB_NOT_READY}+${COUNT_METALLB_READY})) pods to be ready:" |
| 278 | echo "${METALLB_NOT_READY}" |
| 279 | echo |
| 280 | fi |
| Gabriel Cuba | 0d4965f | 2022-11-06 19:39:02 -0500 | [diff] [blame] | 281 | |
| 282 | # Reports failed pods in CertManager |
| 283 | if [[ "${COUNT_CERTMANAGER_NOT_READY}" -ne 0 ]] |
| 284 | then |
| 285 | echo "CertManager: Waiting for ${COUNT_CERTMANAGER_NOT_READY} of $((${COUNT_CERTMANAGER_NOT_READY}+${COUNT_CERTMANAGER_READY})) pods to be ready:" |
| 286 | echo "${CERTMANAGER_NOT_READY}" |
| 287 | echo |
| 288 | fi |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 289 | fi |
| 290 | |
| 291 | #------------ NEXT SAMPLE |
| 292 | sleep ${sampling_period} |
| 293 | done |
| 294 | |
| 295 | #################################################################################### |
| 296 | # OUTCOME |
| 297 | #################################################################################### |
| 298 | if [[ (${failures_in_a_row} -ge ${failures_threshold}) ]] |
| 299 | then |
| 300 | echo |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 301 | FATAL_TRACK k8scluster "K8S CLUSTER IS BROKEN" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 302 | else |
| 303 | echo |
| 304 | echo "K8S CLUSTER IS READY" |
| 305 | fi |
| 306 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 307 | } |
| 308 | |
| 309 | #removes osm deployments and services |
| 310 | function remove_k8s_namespace() { |
| 311 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| garciadeblas | 80b2e17 | 2023-06-01 18:38:13 +0200 | [diff] [blame] | 312 | echo "Deleting existing namespace $1: kubectl delete ns $1" |
| 313 | kubectl delete ns $1 2>/dev/null |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 314 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| 315 | } |
| 316 | |
| 317 | # main |
| 318 | while getopts ":D:d:i:-: " o; do |
| 319 | case "${o}" in |
| 320 | i) |
| 321 | DEFAULT_IP="${OPTARG}" |
| 322 | ;; |
| 323 | d) |
| garciadeblas | 2e1c9f8 | 2023-06-01 14:20:03 +0200 | [diff] [blame] | 324 | OSM_CLUSTER_WORK_DIR="${OPTARG}" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 325 | ;; |
| 326 | D) |
| 327 | OSM_DEVOPS="${OPTARG}" |
| 328 | ;; |
| 329 | -) |
| 330 | [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="y" && continue |
| 331 | echo -e "Invalid option: '--$OPTARG'\n" >&2 |
| 332 | exit 1 |
| 333 | ;; |
| 334 | :) |
| 335 | echo "Option -$OPTARG requires an argument" >&2 |
| 336 | exit 1 |
| 337 | ;; |
| 338 | \?) |
| 339 | echo -e "Invalid option: '-$OPTARG'\n" >&2 |
| 340 | exit 1 |
| 341 | ;; |
| 342 | *) |
| 343 | exit 1 |
| 344 | ;; |
| 345 | esac |
| 346 | done |
| 347 | |
| 348 | source $OSM_DEVOPS/common/logging |
| 349 | source $OSM_DEVOPS/common/track |
| 350 | |
| 351 | echo "DEBUG_INSTALL=$DEBUG_INSTALL" |
| 352 | echo "DEFAULT_IP=$DEFAULT_IP" |
| 353 | echo "OSM_DEVOPS=$OSM_DEVOPS" |
| garciadeblas | 2e1c9f8 | 2023-06-01 14:20:03 +0200 | [diff] [blame] | 354 | echo "OSM_CLUSTER_WORK_DIR=$OSM_CLUSTER_WORK_DIR" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 355 | echo "INSTALL_K8S_MONITOR=$INSTALL_K8S_MONITOR" |
| 356 | echo "HOME=$HOME" |
| 357 | |
| 358 | |
| 359 | install_kube |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 360 | check_and_track_kube_install |
| 361 | |
| garciadeblas | 2e1c9f8 | 2023-06-01 14:20:03 +0200 | [diff] [blame] | 362 | init_kubeadm $OSM_CLUSTER_WORK_DIR/kubeadm-config.yaml |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 363 | kube_config_dir |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 364 | check_and_track_init_k8s |
| 365 | |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 366 | if [ -n "$INSTALL_K8S_MONITOR" ]; then |
| 367 | # uninstall OSM MONITORING |
| 368 | uninstall_k8s_monitoring |
| garciadeblas | 4d89c37 | 2021-11-25 11:57:18 +0100 | [diff] [blame] | 369 | track k8scluster uninstall_k8s_monitoring_ok |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 370 | fi |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 371 | |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 372 | deploy_cni_provider |
| 373 | taint_master_node |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 374 | check_and_track_k8s_ready_before_helm |
| 375 | |
| garciadeblas | 80b2e17 | 2023-06-01 18:38:13 +0200 | [diff] [blame] | 376 | remove_k8s_namespace osm |
| 377 | |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 378 | install_helm |
| garciadeblas | 4d89c37 | 2021-11-25 11:57:18 +0100 | [diff] [blame] | 379 | track k8scluster install_helm_ok |
| garciadeblas | 8fed108 | 2022-08-29 11:25:02 +0200 | [diff] [blame] | 380 | |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 381 | install_k8s_storageclass |
| garciadeblas | 4d89c37 | 2021-11-25 11:57:18 +0100 | [diff] [blame] | 382 | track k8scluster k8s_storageclass_ok |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 383 | install_helm_metallb |
| garciadeblas | 4d89c37 | 2021-11-25 11:57:18 +0100 | [diff] [blame] | 384 | track k8scluster k8s_metallb_ok |
| Gabriel Cuba | 0d4965f | 2022-11-06 19:39:02 -0500 | [diff] [blame] | 385 | install_helm_certmanager |
| 386 | track k8scluster k8s_certmanager_ok |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 387 | check_for_readiness |
| garciadeblas | 4d89c37 | 2021-11-25 11:57:18 +0100 | [diff] [blame] | 388 | track k8scluster k8s_ready_ok |
| garciadeblas | 80b2e17 | 2023-06-01 18:38:13 +0200 | [diff] [blame] | 389 | configure_ipaddresspool_metallb |