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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 function install_k8s_storageclass
() {
19 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of
function
20 # Openebs versions can be found here: https://github.com/openebs/openebs/releases
21 OPENEBS_VERSION
="3.7.0"
22 echo "Installing OpenEBS"
23 helm repo add openebs https
://openebs.github.io
/charts
25 helm
install --create-namespace --namespace openebs openebs openebs
/openebs
--version ${OPENEBS_VERSION}
27 local storageclass_timeout
=400
29 local storageclass_ready
=""
30 echo "Waiting for storageclass"
31 while (( counter
< storageclass_timeout
))
33 kubectl get storageclass openebs-hostpath
&> /dev
/null
35 if [ $?
-eq 0 ] ; then
36 echo "Storageclass available"
37 storageclass_ready
="y"
40 counter
=$
((counter
+ 15))
44 [ -n "$storageclass_ready" ] || FATAL_TRACK k8scluster
"Storageclass not ready after $storageclass_timeout seconds. Cannot install openebs"
45 kubectl
patch storageclass openebs-hostpath
-p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
46 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of
function
49 #installs metallb from helm
50 function install_helm_metallb
() {
51 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of
function
52 echo "Installing MetalLB"
53 METALLB_VERSION
="0.13.10"
54 helm repo add metallb https
://metallb.github.io
/metallb
56 helm
install --create-namespace --namespace metallb-system metallb metallb
/metallb
--version ${METALLB_VERSION}
57 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of
function
60 function configure_ipaddresspool_metallb
() {
61 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of
function
62 echo "Creating IP address pool manifest: ${OSM_CLUSTER_WORK_DIR}/metallb-ipaddrpool.yaml"
63 METALLB_IP_RANGE
="$DEFAULT_IP/32"
64 echo "apiVersion: metallb.io/v1beta1
68 namespace: metallb-system
71 - ${METALLB_IP_RANGE}" | sudo
tee -a ${OSM_CLUSTER_WORK_DIR}/metallb-ipaddrpool.yaml
72 echo "Applying IP address pool manifest: kubectl apply -f ${OSM_CLUSTER_WORK_DIR}/metallb-ipaddrpool.yaml"
73 kubectl apply
-f ${OSM_CLUSTER_WORK_DIR}/metallb-ipaddrpool.yaml || FATAL_TRACK k8scluster
"Cannot create IP address Pool in MetalLB"
74 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of
function
77 #installs cert-manager
78 function install_helm_certmanager
() {
79 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of
function
80 echo "Installing cert-manager"
81 CERTMANAGER_VERSION
="v1.9.1"
82 helm repo add jetstack https
://charts.jetstack.io
84 helm
install cert-manager
--create-namespace --namespace cert-manager jetstack
/cert-manager \
85 --version ${CERTMANAGER_VERSION} --set installCRDs
=true
--set prometheus.enabled
=false \
86 --set clusterResourceNamespace
=osm \
87 --set extraArgs
="{--enable-certificate-owner-ref=true}"
88 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of
function
92 function install_helm_nginx
() {
93 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of
function
94 echo "Installing nginx"
95 NGINX_VERSION
="4.10.0"
96 ANNOTATIONS
='--set controller.service.annotations."service\.beta\.kubernetes\.io/azure-load-balancer-health-probe-request-path"=/healthz'
97 ANNOTATIONS
=${ANNOTATIONS:-""}
98 helm upgrade
--install ingress-nginx ingress-nginx \
99 --repo https
://kubernetes.github.io
/ingress-nginx
--version ${NGINX_VERSION} \
100 --namespace ingress-nginx
--create-namespace ${ANNOTATIONS}
102 kubectl
wait --namespace ingress-nginx \
103 --for=condition
=ready pod \
104 --selector=app.kubernetes.io
/component
=controller \
106 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of
function
109 #checks openebs, metallb and cert-manager readiness
110 function check_for_readiness
() {
111 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of
function
112 # Default input values
113 sampling_period
=2 # seconds
114 time_for_readiness
=20 # seconds ready
115 time_for_failure
=200 # seconds broken
116 OPENEBS_NAMESPACE
=openebs
117 METALLB_NAMESPACE
=metallb-system
118 CERTMANAGER_NAMESPACE
=cert-manager
119 # STACK_NAME=osm # By default, "osm"
121 # Equivalent number of samples
122 oks_threshold
=$
((time_for_readiness
/${sampling_period})) # No. ok samples to declare the system ready
123 failures_threshold
=$
((time_for_failure
/${sampling_period})) # No. nok samples to declare the system broken
127 ####################################################################################
128 # Loop to check system readiness
129 ####################################################################################
130 while [[ (${failures_in_a_row} -lt ${failures_threshold}) && (${oks_in_a_row} -lt ${oks_threshold}) ]]
133 OPENEBS_STATE
=$
(kubectl get pod
-n ${OPENEBS_NAMESPACE} --no-headers 2>&1)
134 OPENEBS_READY
=$
(echo "${OPENEBS_STATE}" |
awk '$2=="1/1" || $2=="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
135 OPENEBS_NOT_READY
=$
(echo "${OPENEBS_STATE}" |
awk '$2!="1/1" && $2!="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
136 COUNT_OPENEBS_READY
=$
(echo "${OPENEBS_READY}"|
grep -v -e '^$' |
wc -l)
137 COUNT_OPENEBS_NOT_READY
=$
(echo "${OPENEBS_NOT_READY}" |
grep -v -e '^$' |
wc -l)
140 METALLB_STATE
=$
(kubectl get pod
-n ${METALLB_NAMESPACE} --no-headers 2>&1)
141 METALLB_READY
=$
(echo "${METALLB_STATE}" |
awk '$2=="1/1" || $2=="4/4" {printf ("%s\t%s\t\n", $1, $2)}')
142 METALLB_NOT_READY
=$
(echo "${METALLB_STATE}" |
awk '$2!="1/1" && $2!="4/4" {printf ("%s\t%s\t\n", $1, $2)}')
143 COUNT_METALLB_READY
=$
(echo "${METALLB_READY}" |
grep -v -e '^$' |
wc -l)
144 COUNT_METALLB_NOT_READY
=$
(echo "${METALLB_NOT_READY}" |
grep -v -e '^$' |
wc -l)
146 # State of CertManager
147 CERTMANAGER_STATE
=$
(kubectl get pod
-n ${CERTMANAGER_NAMESPACE} --no-headers 2>&1)
148 CERTMANAGER_READY
=$
(echo "${CERTMANAGER_STATE}" |
awk '$2=="1/1" || $2=="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
149 CERTMANAGER_NOT_READY
=$
(echo "${CERTMANAGER_STATE}" |
awk '$2!="1/1" && $2!="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
150 COUNT_CERTMANAGER_READY
=$
(echo "${CERTMANAGER_READY}" |
grep -v -e '^$' |
wc -l)
151 COUNT_CERTMANAGER_NOT_READY
=$
(echo "${CERTMANAGER_NOT_READY}" |
grep -v -e '^$' |
wc -l)
154 if [[ $
((${COUNT_OPENEBS_NOT_READY}+${COUNT_METALLB_NOT_READY})) -eq 0 ]]
158 echo -ne ===\
> Successful checks
: "${oks_in_a_row}"/${oks_threshold}\\r
161 ((++failures_in_a_row
))
164 echo Bootstraping...
"${failures_in_a_row}" checks of
${failures_threshold}
166 # Reports failed pods in OpenEBS
167 if [[ "${COUNT_OPENEBS_NOT_READY}" -ne 0 ]]
169 echo "OpenEBS: Waiting for ${COUNT_OPENEBS_NOT_READY} of $((${COUNT_OPENEBS_NOT_READY}+${COUNT_OPENEBS_READY})) pods to be ready:"
170 echo "${OPENEBS_NOT_READY}"
174 # Reports failed pods in MetalLB
175 if [[ "${COUNT_METALLB_NOT_READY}" -ne 0 ]]
177 echo "MetalLB: Waiting for ${COUNT_METALLB_NOT_READY} of $((${COUNT_METALLB_NOT_READY}+${COUNT_METALLB_READY})) pods to be ready:"
178 echo "${METALLB_NOT_READY}"
182 # Reports failed pods in CertManager
183 if [[ "${COUNT_CERTMANAGER_NOT_READY}" -ne 0 ]]
185 echo "CertManager: Waiting for ${COUNT_CERTMANAGER_NOT_READY} of $((${COUNT_CERTMANAGER_NOT_READY}+${COUNT_CERTMANAGER_READY})) pods to be ready:"
186 echo "${CERTMANAGER_NOT_READY}"
191 #------------ NEXT SAMPLE
192 sleep ${sampling_period}
195 ####################################################################################
197 ####################################################################################
198 if [[ (${failures_in_a_row} -ge ${failures_threshold}) ]]
201 FATAL_TRACK k8scluster
"K8S CLUSTER IS BROKEN"
204 echo "K8S CLUSTER IS READY"
206 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of
function
210 while getopts ":D:d:i:-: " o
; do
213 DEFAULT_IP
="${OPTARG}"
216 OSM_CLUSTER_WORK_DIR
="${OPTARG}"
219 OSM_DEVOPS
="${OPTARG}"
222 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL
="y" && continue
223 echo -e "Invalid option: '--$OPTARG'\n" >&2
227 echo "Option -$OPTARG requires an argument" >&2
231 echo -e "Invalid option: '-$OPTARG'\n" >&2
240 source $OSM_DEVOPS/common
/logging
241 source $OSM_DEVOPS/common
/track
243 echo "DEBUG_INSTALL=$DEBUG_INSTALL"
244 echo "DEFAULT_IP=$DEFAULT_IP"
245 echo "OSM_DEVOPS=$OSM_DEVOPS"
246 echo "OSM_CLUSTER_WORK_DIR=$OSM_CLUSTER_WORK_DIR"
248 install_k8s_storageclass
249 track k8scluster k8s_storageclass_ok
251 track k8scluster k8s_metallb_ok
252 install_helm_certmanager
253 track k8scluster k8s_certmanager_ok
255 track k8scluster k8s_nginx_ok
257 track k8scluster k8s_ready_ok
258 configure_ipaddresspool_metallb