2 ################################################################################
3 # Copyright (c) 2019 AT&T Intellectual Property. #
4 # Copyright (c) 2019 Nokia. #
5 # Copyright (c) 2021 HCL Technologies Limited. #
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 #
11 # http://www.apache.org/licenses/LICENSE-2.0 #
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 ################################################################################
20 function wait_for_pods() {
21 echo -n "waiting for $1 pods to run"
24 while $STILL_WAITING; do
26 PODS=$(kubectl get pods -n $2 2>/dev/null | grep $1 | awk '{print $1}')
32 for POD in ${PODS}; do
33 if [[ $(kubectl get pod ${POD} -n $2 -o go-template --template "{{.status.phase}}") != "Running" ]]; then
45 function wait_for_cats() {
46 echo -n "waiting for $1 daemonset to complete"
49 while $STILL_WAITING; do
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
65 KERNEL_OPTIMIZATION=false
66 IS_HELM3=$(helm version --short|grep -e "^v3")
68 while [ -n "$1" ]; do # while loop starts
75 -c) LIST_OF_COMPONENTS=$2
78 -o) KERNEL_OPTIMIZATION=true
80 *) echo "Option $1 not recognized" ;; # In case you typed a different option other than a,b,c
88 if [ -z "$OVERRIDEYAML" ];then
89 echo "****************************************************************************************************************"
91 echo "****************************************************************************************************************"
92 echo "RIC deployment without deployment recipe is currently disabled. Please specify an recipe with the -f option."
93 echo "****************************************************************************************************************"
99 HAS_COMMON_PACKAGE=$(helm search local/ric-common | grep ric-common)
101 HAS_COMMON_PACKAGE=$(helm search repo local/ric-common | grep ric-common)
104 if [ -z "$HAS_COMMON_PACKAGE" ];then
105 echo "****************************************************************************************************************"
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 "****************************************************************************************************************"
113 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
114 COMMON_BLOCK=$(cat $OVERRIDEYAML | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *|^ *#.*$/) {print $0; if (getline == 0) {break}}}')
115 NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^ namespace:/{getline; while ($0 ~ /^ +.*|^ *|^ *#.*$/) {print $0; if (getline == 0) {break}}}')
116 PLTNAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *platform:/{print $2}')
117 INFRANAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *infra:/{print $2}')
118 XAPPNAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *xapp:/{print $2}')
119 RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
120 LOCAL_REPOSITORY=$(echo "$COMMON_BLOCK" | awk '/^ *localregistry:/{print $2}')
122 # replace the dbaasha with dbaas1 if deploying non HA DBaaS
123 COMPONENTS=${LIST_OF_COMPONENTS:-"infrastructure dbaas xapp-onboarder appmgr rtmgr e2mgr e2term a1mediator submgr vespamgr jaegeradapter o1mediator alarmmanager influxdb"}
124 echo "Deploying RIC infra components [$COMPONENTS]"
127 if ! kubectl get ns ${PLTNAMESPACE:-ricplt}> /dev/null 2>&1; then
128 kubectl create ns ${PLTNAMESPACE:-ricplt}
130 if ! kubectl get ns ${INFRANAMESPACE:-ricinfra}> /dev/null 2>&1; then
131 kubectl create ns ${INFRANAMESPACE:-ricinfra}
133 if ! kubectl get ns ${XAPPNAMESPACE:-ricxapp}> /dev/null 2>&1; then
134 kubectl create ns ${XAPPNAMESPACE:-ricxapp}
136 FOUND_RECIPE=$(kubectl get configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe 2>/dev/null )
137 if [ ! -z "$FOUND_RECIPE" ]; then
138 kubectl delete configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe
140 kubectl create configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe --from-file=recipe=$OVERRIDEYAML
142 if [ ! -z "$LOCAL_REPOSITORY" ]; then
143 LOCAL_REPOSITORY="$LOCAL_REPOSITORY/"
147 echo Add cluster roles
148 cat >ricplt-role.yaml <<EOF
150 apiVersion: rbac.authorization.k8s.io/v1
153 name: ricplt-system-tiller
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"]
165 resources: ["events"]
166 verbs: ["create", "patch"]
169 verbs: ["list", "watch", "get"]
171 resources: ["nodes/metrics"]
172 verbs: ["list", "watch", "get"]
174 resources: ["nodes/proxy"]
175 verbs: ["list", "watch", "get"]
176 - 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"]
192 resources: ["ingresses"]
193 verbs: ["watch", "list", "get", "create", "delete", "update"]
195 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"]
202 verbs: ["update", "get", "list", "watch"]
203 - apiGroups: ["networking.k8s.io"]
204 resources: ["ingresses/status"]
205 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"]
215 apiVersion: rbac.authorization.k8s.io/v1
216 kind: ClusterRoleBinding
218 name: ricplt-system-tiller
220 apiGroup: rbac.authorization.k8s.io
222 name: ricplt-system-tiller
224 - kind: ServiceAccount
226 namespace: kube-system
231 kubectl apply -f ricplt-role.yaml
236 # Add kernel optimization for radis services
237 if $KERNEL_OPTIMIZATION; then
238 cat >kernel_optimizer.yaml <<EOF
242 namespace: ${INFRANAMESPACE:-ricinfra}
243 name: redis-kernel-optimizer
247 app: redis-kernel-optimizer
251 app: redis-kernel-optimizer
259 image: ${LOCAL_REPOSITORY}busybox
264 command: ["sh", "-c"]
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
277 while true; do sleep 1; done
280 mountPath: /rootfs/sys
282 kubectl apply -f kernel_optimizer.yaml
283 wait_for_pods redis-kernel-optimizer ${INFRANAMESPACE:-ricinfra}
284 wait_for_cats redis-kernel-optimizer ${INFRANAMESPACE:-ricinfra}
285 kubectl delete -f kernel_optimizer.yaml
286 rm kernel_optimizer.yaml
290 for component in $COMPONENTS; do
291 helm dep up $DIR/../helm/$component
292 COMPONENT="${RELEASE_PREFIX}-$component"
295 COMPONENT=" --name $COMPONENT"
297 helm install -f $OVERRIDEYAML --namespace "${PLTNAMESPACE:-ricplt}" $COMPONENT $DIR/../helm/$component