2 ################################################################################
3 # Copyright (c) 2019 AT&T Intellectual Property. #
4 # Copyright (c) 2019 Nokia. #
6 # Licensed under the Apache License, Version 2.0 (the "License"); #
7 # you may not use this file except in compliance with the License. #
8 # You may obtain a copy of the License at #
10 # http://www.apache.org/licenses/LICENSE-2.0 #
12 # Unless required by applicable law or agreed to in writing, software #
13 # distributed under the License is distributed on an "AS IS" BASIS, #
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15 # See the License for the specific language governing permissions and #
16 # limitations under the License. #
17 ################################################################################
19 function wait_for_pods() {
20 echo -n "waiting for $1 pods to run"
23 while $STILL_WAITING; do
25 PODS=$(kubectl get pods -n $2 2>/dev/null | grep $1 | awk '{print $1}')
31 for POD in ${PODS}; do
32 if [[ $(kubectl get pod ${POD} -n $2 -o go-template --template "{{.status.phase}}") != "Running" ]]; then
44 function wait_for_cats() {
45 echo -n "waiting for $1 daemonset to complete"
48 while $STILL_WAITING; do
50 PODS=$(kubectl get pods -n $2 | grep $1 | awk '{print $1}')
51 for POD in ${PODS}; do
52 if [[ $(kubectl logs ${POD} -n $2 --tail 1) != "done" ]]; then
64 KERNEL_OPTIMIZATION=false
66 while [ -n "$1" ]; do # while loop starts
73 -c) LIST_OF_COMPONENTS=$2
76 -o) KERNEL_OPTIMIZATION=true
78 *) echo "Option $1 not recognized" ;; # In case you typed a different option other than a,b,c
86 if [ -z "$OVERRIDEYAML" ];then
87 echo "****************************************************************************************************************"
89 echo "****************************************************************************************************************"
90 echo "RIC deployment without deployment recipe is currently disabled. Please specify an recipe with the -f option."
91 echo "****************************************************************************************************************"
95 HAS_COMMON_PACKAGE=$(helm search local/ric-common | grep ric-common)
97 if [ -z "$HAS_COMMON_PACKAGE" ];then
98 echo "****************************************************************************************************************"
100 echo "****************************************************************************************************************"
101 echo "Can't locate the ric-common helm package in the local repo. Please make sure that it is properly installed."
102 echo "****************************************************************************************************************"
106 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
107 COMMON_BLOCK=$(cat $OVERRIDEYAML | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *|^ *#.*$/) {print $0; if (getline == 0) {break}}}')
108 NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^ namespace:/{getline; while ($0 ~ /^ +.*|^ *|^ *#.*$/) {print $0; if (getline == 0) {break}}}')
109 PLTNAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *platform:/{print $2}')
110 INFRANAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *infra:/{print $2}')
111 XAPPNAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *xapp:/{print $2}')
112 RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
113 LOCAL_REPOSITORY=$(echo "$COMMON_BLOCK" | awk '/^ *localregistry:/{print $2}')
115 # replace the dbaasha with dbaas1 if deploying non HA DBaaS
116 COMPONENTS=${LIST_OF_COMPONENTS:-"infrastructure dbaas xapp-onboarder appmgr rtmgr e2mgr e2term a1mediator submgr vespamgr jaegeradapter o1mediator alarmadapter"}
117 echo "Deploying RIC infra components [$COMPONENTS]"
120 if ! kubectl get ns ${PLTNAMESPACE:-ricplt}> /dev/null 2>&1; then
121 kubectl create ns ${PLTNAMESPACE:-ricplt}
123 if ! kubectl get ns ${INFRANAMESPACE:-ricinfra}> /dev/null 2>&1; then
124 kubectl create ns ${INFRANAMESPACE:-ricinfra}
126 if ! kubectl get ns ${XAPPNAMESPACE:-ricxapp}> /dev/null 2>&1; then
127 kubectl create ns ${XAPPNAMESPACE:-ricxapp}
129 FOUND_RECIPE=$(kubectl get configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe 2>/dev/null )
130 if [ ! -z "$FOUND_RECIPE" ]; then
131 kubectl delete configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe
133 kubectl create configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe --from-file=recipe=$OVERRIDEYAML
135 if [ ! -z "$LOCAL_REPOSITORY" ]; then
136 LOCAL_REPOSITORY="$LOCAL_REPOSITORY/"
140 echo Add cluster roles
141 cat >ricplt-role.yaml <<EOF
143 apiVersion: rbac.authorization.k8s.io/v1
146 name: ricplt-system-tiller
149 resources: ["deployments"]
150 verbs: ["get", "list", "create", "delete"]
151 - apiGroups: ["apiextensions.k8s.io"]
152 resources: ["customresourcedefinitions"]
153 verbs: ["get", "list", "create", "delete"]
154 - apiGroups: ["rbac.authorization.k8s.io"]
155 resources: ["clusterroles", "clusterrolebindings"]
156 verbs: ["get", "list", "create", "delete"]
158 resources: ["events"]
159 verbs: ["create", "patch"]
162 verbs: ["list", "watch", "get"]
163 - apiGroups: ["configuration.konghq.com"]
164 resources: ["kongconsumers"]
165 verbs: ["get", "list", "watch"]
166 - apiGroups: ["configuration.konghq.com"]
167 resources: ["kongcredentials"]
168 verbs: ["get", "list", "watch"]
169 - apiGroups: ["configuration.konghq.com"]
170 resources: ["kongingresses"]
171 verbs: ["get", "list", "watch"]
172 - apiGroups: ["configuration.konghq.com"]
173 resources: ["kongplugins"]
174 verbs: ["get", "list", "watch"]
175 - apiGroups: ["networking.k8s.io"]
176 resources: ["ingresses"]
177 verbs: ["watch", "list", "get", "create", "delete", "update"]
179 resources: ["persistentvolumes"]
180 verbs: ["watch", "list", "get", "create", "delete"]
181 - apiGroups: ["danm.k8s.io"]
182 resources: ["clusternetworks"]
183 verbs: ["watch", "list", "get", "create", "delete"]
184 - apiGroups: ["extensions"]
185 resources: ["ingresses/status"]
187 - apiGroups: ["networking.k8s.io"]
188 resources: ["ingresses/status"]
192 apiVersion: rbac.authorization.k8s.io/v1
193 kind: ClusterRoleBinding
195 name: ricplt-system-tiller
197 apiGroup: rbac.authorization.k8s.io
199 name: ricplt-system-tiller
201 - kind: ServiceAccount
203 namespace: kube-system
205 kubectl apply -f ricplt-role.yaml
209 # Add kernel optimization for radis services
210 if $KERNEL_OPTIMIZATION; then
211 cat >kernel_optimizer.yaml <<EOF
215 namespace: ${INFRANAMESPACE:-ricinfra}
216 name: redis-kernel-optimizer
220 app: redis-kernel-optimizer
224 app: redis-kernel-optimizer
232 image: ${LOCAL_REPOSITORY}busybox
237 command: ["sh", "-c"]
243 echo never > /rootfs/sys/kernel/mm/transparent_hugepage/enabled
244 echo never > /rootfs/sys/kernel/mm/transparent_hugepage/defrag
245 sysctl -w net.core.somaxconn=511
246 grep -q -F [never] /sys/kernel/mm/transparent_hugepage/enabled
247 grep -q -F [never] /sys/kernel/mm/transparent_hugepage/defrag
248 sysctl -n net.core.somaxconn | grep 511 -q
250 while true; do sleep 1; done
253 mountPath: /rootfs/sys
255 kubectl apply -f kernel_optimizer.yaml
256 wait_for_pods redis-kernel-optimizer ${INFRANAMESPACE:-ricinfra}
257 wait_for_cats redis-kernel-optimizer ${INFRANAMESPACE:-ricinfra}
258 kubectl delete -f kernel_optimizer.yaml
259 rm kernel_optimizer.yaml
263 for component in $COMPONENTS; do
264 helm dep up $DIR/../helm/$component
265 helm install -f $OVERRIDEYAML --namespace "${PLTNAMESPACE:-ricplt}" --name "${RELEASE_PREFIX}-$component" $DIR/../helm/$component