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 if ! kubectl get ns ${PLTNAMESPACE:-ricplt}> /dev/null 2>&1; then
123 kubectl create ns ${PLTNAMESPACE:-ricplt}
125 if ! kubectl get ns ${INFRANAMESPACE:-ricinfra}> /dev/null 2>&1; then
126 kubectl create ns ${INFRANAMESPACE:-ricinfra}
128 if ! kubectl get ns ${XAPPNAMESPACE:-ricxapp}> /dev/null 2>&1; then
129 kubectl create ns ${XAPPNAMESPACE:-ricxapp}
132 IS_INFLUX_PERSIST=$( kubectl get storageclass nfs 2>/dev/null | awk '{print $1}' | grep nfs)
133 if [[ ${LIST_OF_COMPONENTS} == *"influxdb"* ]]; then
134 if [ -z "$IS_INFLUX_PERSIST" ]; then
135 echo "nfs storage does not exist, create PersistentVolume through the storage class for the influxdb database"
136 LIST_OF_COMPONENTS=$(echo "$LIST_OF_COMPONENTS" | sed "s/influxdb//")
137 echo "skipping influxdb component"
139 echo "nfs storage exist"
143 # replace the dbaasha with dbaas1 if deploying non HA DBaaS
144 COMPONENTS="infrastructure dbaas appmgr rtmgr e2mgr e2term a1mediator submgr vespamgr o1mediator alarmmanager $LIST_OF_COMPONENTS"
146 echo "Deploying RIC infra components [$COMPONENTS]"
147 if [[ ${COMPONENTS} != *"influxdb"* ]]; then
148 OPTIONAL_COMPONENTS="influxdb"
150 if [[ ${COMPONENTS} != *"jaegeradapter"* ]]; then
151 OPTIONAL_COMPONENTS={"$OPTIONAL_COMPONENTS jaegeradapter"}
153 if [ ! -z "$OPTIONAL_COMPONENTS" ]; then
154 echo "Note that the following optional components are NOT being deployed: $OPTIONAL_COMPONENTS. To deploy them add them with -c to the default component list of the install command"
157 FOUND_RECIPE=$(kubectl get configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe 2>/dev/null )
158 if [ ! -z "$FOUND_RECIPE" ]; then
159 kubectl delete configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe
161 kubectl create configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe --from-file=recipe=$OVERRIDEYAML
163 if [ ! -z "$LOCAL_REPOSITORY" ]; then
164 LOCAL_REPOSITORY="$LOCAL_REPOSITORY/"
168 echo Add cluster roles
169 cat >ricplt-role.yaml <<EOF
171 apiVersion: rbac.authorization.k8s.io/v1
174 name: ricplt-system-tiller
177 resources: ["deployments"]
178 verbs: ["get", "list", "create", "delete"]
179 - apiGroups: ["apiextensions.k8s.io"]
180 resources: ["customresourcedefinitions"]
181 verbs: ["get", "list", "create", "delete"]
182 - apiGroups: ["rbac.authorization.k8s.io"]
183 resources: ["clusterroles", "clusterrolebindings"]
184 verbs: ["get", "list", "create", "delete"]
186 resources: ["events"]
187 verbs: ["create", "patch"]
190 verbs: ["list", "watch", "get"]
192 resources: ["nodes/metrics"]
193 verbs: ["list", "watch", "get"]
195 resources: ["nodes/proxy"]
196 verbs: ["list", "watch", "get"]
197 - apiGroups: ["configuration.konghq.com"]
198 resources: ["kongconsumers"]
199 verbs: ["get", "list", "watch"]
200 - apiGroups: ["configuration.konghq.com"]
201 resources: ["kongcredentials"]
202 verbs: ["get", "list", "watch"]
203 - apiGroups: ["configuration.konghq.com"]
204 resources: ["kongingresses"]
205 verbs: ["get", "list", "watch"]
206 - apiGroups: ["configuration.konghq.com"]
207 resources: ["kongplugins"]
208 verbs: ["get", "list", "watch"]
209 - apiGroups: ["networking.k8s.io"]
210 resources: ["ingresses"]
211 verbs: ["watch", "list", "get", "create", "delete", "update"]
213 resources: ["ingresses"]
214 verbs: ["watch", "list", "get", "create", "delete", "update"]
216 resources: ["persistentvolumes"]
217 verbs: ["watch", "list", "get", "create", "delete"]
218 - apiGroups: ["danm.k8s.io"]
219 resources: ["clusternetworks"]
220 verbs: ["watch", "list", "get", "create", "delete"]
221 - apiGroups: ["extensions"]
222 resources: ["ingresses/status"]
223 verbs: ["update", "get", "list", "watch"]
224 - apiGroups: ["networking.k8s.io"]
225 resources: ["ingresses/status"]
226 verbs: ["update", "get", "list", "watch"]
227 - apiGroups: ["certificates.k8s.io"]
228 resources: ["certificatesigningrequests"]
229 verbs: ["list", "watch"]
230 - apiGroups: ["storage.k8s.io"]
231 resources: ["storageclasses"]
232 verbs: ["list", "watch"]
233 - nonResourceURLs: ["/metrics"]
236 apiVersion: rbac.authorization.k8s.io/v1
237 kind: ClusterRoleBinding
239 name: ricplt-system-tiller
241 apiGroup: rbac.authorization.k8s.io
243 name: ricplt-system-tiller
245 - kind: ServiceAccount
247 namespace: kube-system
252 kubectl apply -f ricplt-role.yaml
257 # Add kernel optimization for radis services
258 if $KERNEL_OPTIMIZATION; then
259 cat >kernel_optimizer.yaml <<EOF
263 namespace: ${INFRANAMESPACE:-ricinfra}
264 name: redis-kernel-optimizer
268 app: redis-kernel-optimizer
272 app: redis-kernel-optimizer
280 image: ${LOCAL_REPOSITORY}busybox
285 command: ["sh", "-c"]
291 echo never > /rootfs/sys/kernel/mm/transparent_hugepage/enabled
292 echo never > /rootfs/sys/kernel/mm/transparent_hugepage/defrag
293 sysctl -w net.core.somaxconn=511
294 grep -q -F [never] /sys/kernel/mm/transparent_hugepage/enabled
295 grep -q -F [never] /sys/kernel/mm/transparent_hugepage/defrag
296 sysctl -n net.core.somaxconn | grep 511 -q
298 while true; do sleep 1; done
301 mountPath: /rootfs/sys
303 kubectl apply -f kernel_optimizer.yaml
304 wait_for_pods redis-kernel-optimizer ${INFRANAMESPACE:-ricinfra}
305 wait_for_cats redis-kernel-optimizer ${INFRANAMESPACE:-ricinfra}
306 kubectl delete -f kernel_optimizer.yaml
307 rm kernel_optimizer.yaml
310 for component in $COMPONENTS; do
311 helm dep up $DIR/../helm/$component
312 COMPONENT="${RELEASE_PREFIX}-$component"
315 COMPONENT=" --name $COMPONENT"
317 helm install -f $OVERRIDEYAML --namespace "${PLTNAMESPACE:-ricplt}" $COMPONENT $DIR/../helm/$component