blob: d879a03909ce0c502f3e497502da2c0e2425c884 [file] [log] [blame]
Zhe Huang38dc8572019-12-08 00:01:26 -05001#!/bin/bash
2################################################################################
3# Copyright (c) 2019 AT&T Intellectual Property. #
4# Copyright (c) 2019 Nokia. #
Chandrasekaran Ramachandranb515b962021-06-11 16:07:09 +05305# Copyright (c) 2021 HCL Technologies Limited. #
Zhe Huang38dc8572019-12-08 00:01:26 -05006# #
7# Licensed under the Apache License, Version 2.0 (the "License"); #
8# you may not use this file except in compliance with the License. #
9# You may obtain a copy of the License at #
10# #
11# http://www.apache.org/licenses/LICENSE-2.0 #
12# #
13# Unless required by applicable law or agreed to in writing, software #
14# distributed under the License is distributed on an "AS IS" BASIS, #
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
16# See the License for the specific language governing permissions and #
17# limitations under the License. #
18################################################################################
knowpdf882a9b2020-04-03 16:44:09 -040019
20function wait_for_pods() {
21 echo -n "waiting for $1 pods to run"
22
23 STILL_WAITING=true
24 while $STILL_WAITING; do
25 STILL_WAITING=false
26 PODS=$(kubectl get pods -n $2 2>/dev/null | grep $1 | awk '{print $1}')
27 if [ -z $PODS ]; then
28 STILL_WAITING=true
29 sleep 1
30 echo -n "."
31 fi
32 for POD in ${PODS}; do
33 if [[ $(kubectl get pod ${POD} -n $2 -o go-template --template "{{.status.phase}}") != "Running" ]]; then
34 STILL_WAITING=true
35 sleep 1
36 echo -n "."
37 break
38 fi
39 done
40 done
41
42 echo
43}
44
45function wait_for_cats() {
46 echo -n "waiting for $1 daemonset to complete"
47
48 STILL_WAITING=true
49 while $STILL_WAITING; do
50 STILL_WAITING=false
51 PODS=$(kubectl get pods -n $2 | grep $1 | awk '{print $1}')
52 for POD in ${PODS}; do
53 if [[ $(kubectl logs ${POD} -n $2 --tail 1) != "done" ]]; then
54 STILL_WAITING=true
55 sleep 1
56 echo -n "."
57 break
58 fi
59 done
60 done
61
62 echo
63}
64
Zhe Huang1d417dc2020-04-22 13:04:47 -040065KERNEL_OPTIMIZATION=false
Alok Bhattf947fc82020-11-11 04:32:33 +000066IS_HELM3=$(helm version --short|grep -e "^v3")
knowpdf882a9b2020-04-03 16:44:09 -040067
Zhe Huang38dc8572019-12-08 00:01:26 -050068while [ -n "$1" ]; do # while loop starts
69
70 case "$1" in
71
72 -f) OVERRIDEYAML=$2
73 shift
74 ;;
75 -c) LIST_OF_COMPONENTS=$2
76 shift
77 ;;
Zhe Huang1d417dc2020-04-22 13:04:47 -040078 -o) KERNEL_OPTIMIZATION=true
79 ;;
Zhe Huang38dc8572019-12-08 00:01:26 -050080 *) echo "Option $1 not recognized" ;; # In case you typed a different option other than a,b,c
81
82 esac
83
84 shift
85
86done
87
88if [ -z "$OVERRIDEYAML" ];then
89 echo "****************************************************************************************************************"
90 echo " ERROR "
91 echo "****************************************************************************************************************"
92 echo "RIC deployment without deployment recipe is currently disabled. Please specify an recipe with the -f option."
93 echo "****************************************************************************************************************"
94 exit 1
95fi
96
Alok Bhattf947fc82020-11-11 04:32:33 +000097if [ -z $IS_HELM3 ]
98then
99 HAS_COMMON_PACKAGE=$(helm search local/ric-common | grep ric-common)
100else
101 HAS_COMMON_PACKAGE=$(helm search repo local/ric-common | grep ric-common)
102fi
Zhe Huang38dc8572019-12-08 00:01:26 -0500103
104if [ -z "$HAS_COMMON_PACKAGE" ];then
105 echo "****************************************************************************************************************"
106 echo " ERROR "
107 echo "****************************************************************************************************************"
108 echo "Can't locate the ric-common helm package in the local repo. Please make sure that it is properly installed."
109 echo "****************************************************************************************************************"
110 exit 1
111fi
112
Zhe Huang38dc8572019-12-08 00:01:26 -0500113DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
knowpdf882a9b2020-04-03 16:44:09 -0400114COMMON_BLOCK=$(cat $OVERRIDEYAML | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *|^ *#.*$/) {print $0; if (getline == 0) {break}}}')
115NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^ namespace:/{getline; while ($0 ~ /^ +.*|^ *|^ *#.*$/) {print $0; if (getline == 0) {break}}}')
Zhe Huang38dc8572019-12-08 00:01:26 -0500116PLTNAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *platform:/{print $2}')
117INFRANAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *infra:/{print $2}')
118XAPPNAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *xapp:/{print $2}')
119RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
knowpdf882a9b2020-04-03 16:44:09 -0400120LOCAL_REPOSITORY=$(echo "$COMMON_BLOCK" | awk '/^ *localregistry:/{print $2}')
121
wridere68e3142020-01-28 13:08:47 -0500122# replace the dbaasha with dbaas1 if deploying non HA DBaaS
Chandrasekaran Ramachandranb515b962021-06-11 16:07:09 +0530123COMPONENTS=${LIST_OF_COMPONENTS:-"infrastructure dbaas xapp-onboarder appmgr rtmgr e2mgr e2term a1mediator submgr vespamgr jaegeradapter o1mediator alarmmanager influxdb"}
Zhe Huang38dc8572019-12-08 00:01:26 -0500124echo "Deploying RIC infra components [$COMPONENTS]"
125
126
127if ! kubectl get ns ${PLTNAMESPACE:-ricplt}> /dev/null 2>&1; then
128 kubectl create ns ${PLTNAMESPACE:-ricplt}
129fi
130if ! kubectl get ns ${INFRANAMESPACE:-ricinfra}> /dev/null 2>&1; then
131 kubectl create ns ${INFRANAMESPACE:-ricinfra}
132fi
133if ! kubectl get ns ${XAPPNAMESPACE:-ricxapp}> /dev/null 2>&1; then
134 kubectl create ns ${XAPPNAMESPACE:-ricxapp}
135fi
knowpdf882a9b2020-04-03 16:44:09 -0400136FOUND_RECIPE=$(kubectl get configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe 2>/dev/null )
137if [ ! -z "$FOUND_RECIPE" ]; then
138 kubectl delete configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe
139fi
Zhe Huang38dc8572019-12-08 00:01:26 -0500140kubectl create configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe --from-file=recipe=$OVERRIDEYAML
141
knowpdf882a9b2020-04-03 16:44:09 -0400142if [ ! -z "$LOCAL_REPOSITORY" ]; then
143 LOCAL_REPOSITORY="$LOCAL_REPOSITORY/"
144fi
145
146
Zhe Huang1d417dc2020-04-22 13:04:47 -0400147echo Add cluster roles
148 cat >ricplt-role.yaml <<EOF
149---
150apiVersion: rbac.authorization.k8s.io/v1
151kind: ClusterRole
152metadata:
153 name: ricplt-system-tiller
154rules:
155 - apiGroups: [""]
156 resources: ["deployments"]
157 verbs: ["get", "list", "create", "delete"]
158 - apiGroups: ["apiextensions.k8s.io"]
159 resources: ["customresourcedefinitions"]
160 verbs: ["get", "list", "create", "delete"]
161 - apiGroups: ["rbac.authorization.k8s.io"]
162 resources: ["clusterroles", "clusterrolebindings"]
163 verbs: ["get", "list", "create", "delete"]
164 - apiGroups: [""]
165 resources: ["events"]
166 verbs: ["create", "patch"]
167 - apiGroups: [""]
168 resources: ["nodes"]
169 verbs: ["list", "watch", "get"]
Zhe Huangdbbf31a2020-05-23 00:00:24 -0400170 - apiGroups: [""]
171 resources: ["nodes/metrics"]
172 verbs: ["list", "watch", "get"]
173 - apiGroups: [""]
174 resources: ["nodes/proxy"]
175 verbs: ["list", "watch", "get"]
Zhe Huang1d417dc2020-04-22 13:04:47 -0400176 - apiGroups: ["configuration.konghq.com"]
177 resources: ["kongconsumers"]
178 verbs: ["get", "list", "watch"]
179 - apiGroups: ["configuration.konghq.com"]
180 resources: ["kongcredentials"]
181 verbs: ["get", "list", "watch"]
182 - apiGroups: ["configuration.konghq.com"]
183 resources: ["kongingresses"]
184 verbs: ["get", "list", "watch"]
185 - apiGroups: ["configuration.konghq.com"]
186 resources: ["kongplugins"]
187 verbs: ["get", "list", "watch"]
188 - apiGroups: ["networking.k8s.io"]
189 resources: ["ingresses"]
190 verbs: ["watch", "list", "get", "create", "delete", "update"]
191 - apiGroups: [""]
Zhe Huangdbbf31a2020-05-23 00:00:24 -0400192 resources: ["ingresses"]
193 verbs: ["watch", "list", "get", "create", "delete", "update"]
194 - apiGroups: [""]
Zhe Huang1d417dc2020-04-22 13:04:47 -0400195 resources: ["persistentvolumes"]
196 verbs: ["watch", "list", "get", "create", "delete"]
197 - apiGroups: ["danm.k8s.io"]
198 resources: ["clusternetworks"]
199 verbs: ["watch", "list", "get", "create", "delete"]
200 - apiGroups: ["extensions"]
201 resources: ["ingresses/status"]
Zhe Huangdbbf31a2020-05-23 00:00:24 -0400202 verbs: ["update", "get", "list", "watch"]
Zhe Huang1d417dc2020-04-22 13:04:47 -0400203 - apiGroups: ["networking.k8s.io"]
204 resources: ["ingresses/status"]
Zhe Huangdbbf31a2020-05-23 00:00:24 -0400205 verbs: ["update", "get", "list", "watch"]
206 - apiGroups: ["certificates.k8s.io"]
207 resources: ["certificatesigningrequests"]
208 verbs: ["list", "watch"]
209 - apiGroups: ["storage.k8s.io"]
210 resources: ["storageclasses"]
211 verbs: ["list", "watch"]
212 - nonResourceURLs: ["/metrics"]
213 verbs: ["get"]
Zhe Huang1d417dc2020-04-22 13:04:47 -0400214---
Zhe Huang1d417dc2020-04-22 13:04:47 -0400215apiVersion: rbac.authorization.k8s.io/v1
216kind: ClusterRoleBinding
217metadata:
218 name: ricplt-system-tiller
219roleRef:
220 apiGroup: rbac.authorization.k8s.io
221 kind: ClusterRole
222 name: ricplt-system-tiller
223subjects:
224 - kind: ServiceAccount
225 name: tiller
226 namespace: kube-system
227EOF
Alok Bhattf947fc82020-11-11 04:32:33 +0000228
229if [ -z $IS_HELM3 ]
230then
231 kubectl apply -f ricplt-role.yaml
232 rm ricplt-role.yaml
233fi
Zhe Huang1d417dc2020-04-22 13:04:47 -0400234
235
knowpdf882a9b2020-04-03 16:44:09 -0400236# Add kernel optimization for radis services
Zhe Huang1d417dc2020-04-22 13:04:47 -0400237if $KERNEL_OPTIMIZATION; then
knowpdf882a9b2020-04-03 16:44:09 -0400238 cat >kernel_optimizer.yaml <<EOF
239apiVersion: apps/v1
240kind: DaemonSet
241metadata:
242 namespace: ${INFRANAMESPACE:-ricinfra}
243 name: redis-kernel-optimizer
244spec:
245 selector:
246 matchLabels:
247 app: redis-kernel-optimizer
248 template:
249 metadata:
250 labels:
251 app: redis-kernel-optimizer
252 spec:
253 volumes:
254 - name: sys
255 hostPath:
256 path: /sys
257 containers:
258 - name: disable-thp
259 image: ${LOCAL_REPOSITORY}busybox
260 securityContext:
261 runAsNonRoot: false
262 privileged: true
263 runAsUser: 0
264 command: ["sh", "-c"]
265 args:
266 - |-
267 set -e
268 set -o pipefail
269 trap 'exit' TERM
270 echo never > /rootfs/sys/kernel/mm/transparent_hugepage/enabled
271 echo never > /rootfs/sys/kernel/mm/transparent_hugepage/defrag
272 sysctl -w net.core.somaxconn=511
273 grep -q -F [never] /sys/kernel/mm/transparent_hugepage/enabled
274 grep -q -F [never] /sys/kernel/mm/transparent_hugepage/defrag
275 sysctl -n net.core.somaxconn | grep 511 -q
276 echo "done"
277 while true; do sleep 1; done
278 volumeMounts:
279 - name: sys
280 mountPath: /rootfs/sys
281EOF
282kubectl apply -f kernel_optimizer.yaml
283wait_for_pods redis-kernel-optimizer ${INFRANAMESPACE:-ricinfra}
284wait_for_cats redis-kernel-optimizer ${INFRANAMESPACE:-ricinfra}
285kubectl delete -f kernel_optimizer.yaml
286rm kernel_optimizer.yaml
Zhe Huang1d417dc2020-04-22 13:04:47 -0400287fi
knowpdf882a9b2020-04-03 16:44:09 -0400288
Zhe Huang38dc8572019-12-08 00:01:26 -0500289
290for component in $COMPONENTS; do
291 helm dep up $DIR/../helm/$component
Alok Bhattf947fc82020-11-11 04:32:33 +0000292 COMPONENT="${RELEASE_PREFIX}-$component"
293 if [ -z $IS_HELM3 ]
294 then
295 COMPONENT=" --name $COMPONENT"
296 fi
297 helm install -f $OVERRIDEYAML --namespace "${PLTNAMESPACE:-ricplt}" $COMPONENT $DIR/../helm/$component
Zhe Huangdbbf31a2020-05-23 00:00:24 -0400298 sleep 8
wrider7d4bbf12020-02-21 16:20:14 -0500299done
knowpdf882a9b2020-04-03 16:44:09 -0400300
301
302
303