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