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
91 #checks openebs and metallb readiness
92 function check_for_readiness
() {
93 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of
function
94 # Default input values
95 sampling_period
=2 # seconds
96 time_for_readiness
=20 # seconds ready
97 time_for_failure
=200 # seconds broken
98 OPENEBS_NAMESPACE
=openebs
99 METALLB_NAMESPACE
=metallb-system
100 CERTMANAGER_NAMESPACE
=cert-manager
101 # STACK_NAME=osm # By default, "osm"
103 # Equivalent number of samples
104 oks_threshold
=$
((time_for_readiness
/${sampling_period})) # No. ok samples to declare the system ready
105 failures_threshold
=$
((time_for_failure
/${sampling_period})) # No. nok samples to declare the system broken
109 ####################################################################################
110 # Loop to check system readiness
111 ####################################################################################
112 while [[ (${failures_in_a_row} -lt ${failures_threshold}) && (${oks_in_a_row} -lt ${oks_threshold}) ]]
115 OPENEBS_STATE
=$
(kubectl get pod
-n ${OPENEBS_NAMESPACE} --no-headers 2>&1)
116 OPENEBS_READY
=$
(echo "${OPENEBS_STATE}" |
awk '$2=="1/1" || $2=="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
117 OPENEBS_NOT_READY
=$
(echo "${OPENEBS_STATE}" |
awk '$2!="1/1" && $2!="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
118 COUNT_OPENEBS_READY
=$
(echo "${OPENEBS_READY}"|
grep -v -e '^$' |
wc -l)
119 COUNT_OPENEBS_NOT_READY
=$
(echo "${OPENEBS_NOT_READY}" |
grep -v -e '^$' |
wc -l)
122 METALLB_STATE
=$
(kubectl get pod
-n ${METALLB_NAMESPACE} --no-headers 2>&1)
123 METALLB_READY
=$
(echo "${METALLB_STATE}" |
awk '$2=="1/1" || $2=="4/4" {printf ("%s\t%s\t\n", $1, $2)}')
124 METALLB_NOT_READY
=$
(echo "${METALLB_STATE}" |
awk '$2!="1/1" && $2!="4/4" {printf ("%s\t%s\t\n", $1, $2)}')
125 COUNT_METALLB_READY
=$
(echo "${METALLB_READY}" |
grep -v -e '^$' |
wc -l)
126 COUNT_METALLB_NOT_READY
=$
(echo "${METALLB_NOT_READY}" |
grep -v -e '^$' |
wc -l)
128 # State of CertManager
129 CERTMANAGER_STATE
=$
(kubectl get pod
-n ${CERTMANAGER_NAMESPACE} --no-headers 2>&1)
130 CERTMANAGER_READY
=$
(echo "${CERTMANAGER_STATE}" |
awk '$2=="1/1" || $2=="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
131 CERTMANAGER_NOT_READY
=$
(echo "${CERTMANAGER_STATE}" |
awk '$2!="1/1" && $2!="2/2" {printf ("%s\t%s\t\n", $1, $2)}')
132 COUNT_CERTMANAGER_READY
=$
(echo "${CERTMANAGER_READY}" |
grep -v -e '^$' |
wc -l)
133 COUNT_CERTMANAGER_NOT_READY
=$
(echo "${CERTMANAGER_NOT_READY}" |
grep -v -e '^$' |
wc -l)
136 if [[ $
((${COUNT_OPENEBS_NOT_READY}+${COUNT_METALLB_NOT_READY})) -eq 0 ]]
140 echo -ne ===\
> Successful checks
: "${oks_in_a_row}"/${oks_threshold}\\r
143 ((++failures_in_a_row
))
146 echo Bootstraping...
"${failures_in_a_row}" checks of
${failures_threshold}
148 # Reports failed pods in OpenEBS
149 if [[ "${COUNT_OPENEBS_NOT_READY}" -ne 0 ]]
151 echo "OpenEBS: Waiting for ${COUNT_OPENEBS_NOT_READY} of $((${COUNT_OPENEBS_NOT_READY}+${COUNT_OPENEBS_READY})) pods to be ready:"
152 echo "${OPENEBS_NOT_READY}"
156 # Reports failed pods in MetalLB
157 if [[ "${COUNT_METALLB_NOT_READY}" -ne 0 ]]
159 echo "MetalLB: Waiting for ${COUNT_METALLB_NOT_READY} of $((${COUNT_METALLB_NOT_READY}+${COUNT_METALLB_READY})) pods to be ready:"
160 echo "${METALLB_NOT_READY}"
164 # Reports failed pods in CertManager
165 if [[ "${COUNT_CERTMANAGER_NOT_READY}" -ne 0 ]]
167 echo "CertManager: Waiting for ${COUNT_CERTMANAGER_NOT_READY} of $((${COUNT_CERTMANAGER_NOT_READY}+${COUNT_CERTMANAGER_READY})) pods to be ready:"
168 echo "${CERTMANAGER_NOT_READY}"
173 #------------ NEXT SAMPLE
174 sleep ${sampling_period}
177 ####################################################################################
179 ####################################################################################
180 if [[ (${failures_in_a_row} -ge ${failures_threshold}) ]]
183 FATAL_TRACK k8scluster
"K8S CLUSTER IS BROKEN"
186 echo "K8S CLUSTER IS READY"
188 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of
function
192 while getopts ":D:d:i:-: " o
; do
195 DEFAULT_IP
="${OPTARG}"
198 OSM_CLUSTER_WORK_DIR
="${OPTARG}"
201 OSM_DEVOPS
="${OPTARG}"
204 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL
="y" && continue
205 echo -e "Invalid option: '--$OPTARG'\n" >&2
209 echo "Option -$OPTARG requires an argument" >&2
213 echo -e "Invalid option: '-$OPTARG'\n" >&2
222 source $OSM_DEVOPS/common
/logging
223 source $OSM_DEVOPS/common
/track
225 echo "DEBUG_INSTALL=$DEBUG_INSTALL"
226 echo "DEFAULT_IP=$DEFAULT_IP"
227 echo "OSM_DEVOPS=$OSM_DEVOPS"
228 echo "OSM_CLUSTER_WORK_DIR=$OSM_CLUSTER_WORK_DIR"
230 install_k8s_storageclass
231 track k8scluster k8s_storageclass_ok
233 track k8scluster k8s_metallb_ok
234 install_helm_certmanager
235 track k8scluster k8s_certmanager_ok
237 track k8scluster k8s_ready_ok
238 configure_ipaddresspool_metallb