3 # ============LICENSE_START===============================================
4 # Copyright (C) 2023 Nordix Foundation. All rights reserved.
5 # ========================================================================
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 # ============LICENSE_END=================================================
20 . scripts/kube_get_controlplane_host.sh
21 . scripts/kube_get_nodeport.sh
22 . scripts/wait_for_server_ok.sh
23 . scripts/get_influxdb2_token.sh
24 . scripts/create_topic.sh
30 export KHOST=$(kube_get_controlplane_host)
37 echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
38 echo "Kubernetes control plane host: $KHOST"
39 echo "Host obtained from current kubectl context"
40 echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
42 echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
43 echo "Restarting istiod, workaround to refresh jwks cache"
44 kubectl rollout restart deployments/istiod -n istio-system
45 echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
47 # Generic error printout function
48 # args: <numeric-response-code> <descriptive-string>
57 ##################################################################################
58 echo "##### Installing chart: namespaces"
59 ##################################################################################
61 helm install --wait namespaces helm/namespaces
65 ##################################################################################
66 echo "##### Installing chart: nrt-base-0"
67 ##################################################################################
68 helm install --wait -n nonrtric nrt-base-0 helm/nrt-base-0
70 # Create realm in keycloak
72 ##export KC_PORT=$(kube_get_nodeport keycloak nonrtric http)
73 . scripts/populate_keycloak.sh
75 create_realms nonrtric-realm
76 while [ $? -ne 0 ]; do
77 create_realms nonrtric-realm
80 # Create client for admin calls
82 create_clients nonrtric-realm $cid
84 generate_client_secrets nonrtric-realm $cid
88 # while [ $retcode -eq 0 ]; do
89 # #NRT_REALM_JWKS=$(kubectl exec -n nonrtric client -- curl -f http://keycloak.nonrtric:8080/realms/nonrtric-realm/protocol/openid-connect/certs)
90 # NRT_REALM_JWKS=$(curl -fs localhost:31788/realms/nonrtric-realm/protocol/openid-connect/certs)
91 # if [ $? -eq 0 ]; then
93 # #echo $NRT_REALM_JWKS
94 # echo "JWKS for nonrtric-realm obtained"
97 # echo "Wating for keycloak to publish JWKS for nonrtric-realm"
101 # export NRT_REALM_JWKS
105 # ##################################################################################
106 # echo "##### Installing chart httpecho"
107 # ##################################################################################
109 #helm install --wait -n nonrtric httpecho helm/httpecho
115 # while [ $numok -lt 10 ]; do
117 # echo "Time: $(($SECONDS-$TSEC))"
118 # cid="console-setup"
120 # TOKEN=$(get_client_token nonrtric-realm $cid)
121 # decode_token "$TOKEN"
122 # curl -fv localhost:31789/ -H "Authorization: Bearer $TOKEN"
123 # if [ $? -eq 0 ]; then
132 # echo "Time: $(($SECONDS-$TSEC))"
133 # cid="console-setup"
135 # TOKEN=$(get_client_token nonrtric-realm $cid)
136 # decode_token "$TOKEN"
137 # curl -v localhost:31789/ -H "Authorization: Bearer $TOKEN"
142 TOKEN=$(get_client_token nonrtric-realm $cid)
143 decode_token "$TOKEN"
145 ##################################################################################
146 echo "##### Installing charts: strimzi and nrt-base-1"
147 ##################################################################################
149 helm repo add strimzi https://strimzi.io/charts/
151 helm install --wait strimzi-kafka-crds -n nonrtric strimzi/strimzi-kafka-operator
154 cp opa-rules/bundle.tar.gz helm/nrt-base-1/charts/opa-rule-db/data
156 #envsubst < helm/nrt-base-1/charts/httpecho/values-template.yaml > helm/nrt-base-1/charts/httpecho/values.yaml
158 helm install -n nonrtric nrt-base-1 helm/nrt-base-1
162 while [ $retcode -eq 1 ]; do
164 CONFIG=$(kubectl exec -n nonrtric influxdb2-0 -- influx config ls --json)
165 if [ $? -ne 0 ]; then
168 elif [ "$CONFIG" == "{}" ]; then
169 echo "Configuring db"
170 kubectl exec -n nonrtric influxdb2-0 -- influx setup -u bm -p mySuP3rS3cr3tT0keN -o est -b pm-bucket -f
171 if [ $? -ne 0 ]; then
176 echo "Db user configured, skipping"
180 # Save influx user api-token to secret
181 INFLUXDB2_TOKEN=$(get_influxdb2_token influxdb2-0 nonrtric)
182 INFLUXDB2_TOKEN=$(echo -n $INFLUXDB2_TOKEN | base64)
183 PATCHDATA='[{"op": "add", "path": "/data/token", "value": "'$INFLUXDB2_TOKEN'" }]'
184 kubectl patch secret influxdb-api-token -n nonrtric --type json -p "$PATCHDATA"
187 echo "Wait for kafka"
189 until $(kubectl exec -n nonrtric kafka-client -- kafka-topics --list --bootstrap-server kafka-1-kafka-bootstrap.nonrtric:9092 1> /dev/null 2> /dev/null); do
190 echo -ne " $(($SECONDS-$_ts)) sec, retrying at $(($SECONDS-$_ts+5)) sec $SAMELINE"
195 # Pre-create known topic to avoid losing data when autocreated by apps
196 __topics_list="file-ready collected-file json-file-ready-kp json-file-ready-kpadp pmreports"
197 for __topic in $__topics_list; do
198 create_topic kafka-1-kafka-bootstrap.nonrtric:9092 $__topic 10
203 ##################################################################################
204 echo "##### Installing: chart ran"
205 ##################################################################################
207 ./helm/ran/certs/gen-certs.sh 10
210 helm install --wait -n ran ran helm/ran
214 ##################################################################################
215 echo "##### Installing chart: nrt-pm"
216 ##################################################################################
220 echo "Updating dfc truststore"
221 cd helm/nrt-pm/charts/dfc/truststore
222 cp template-truststore.jks truststore.jks
225 echo " Adding https ca cert to dfc truststore"
226 cat <<__EOF__ | keytool -importcert -alias pm-https -file $cwd/helm/ran/certs/httpsca.crt -keystore truststore.jks -storetype JKS -storepass $(< truststore.pass)
231 cid="kafka-producer-pm-xml2json"
232 create_clients nonrtric-realm $cid
234 generate_client_secrets nonrtric-realm $cid
237 export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid)
239 envsubst < helm/nrt-pm/charts/kafka-producer-pm-xml2json/values-template.yaml > helm/nrt-pm/charts/kafka-producer-pm-xml2json/values.yaml
242 cid="kafka-producer-pm-json2kafka"
243 create_clients nonrtric-realm $cid
245 generate_client_secrets nonrtric-realm $cid
248 export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid)
250 envsubst < helm/nrt-pm/charts/kafka-producer-pm-json2kafka/values-template.yaml > helm/nrt-pm/charts/kafka-producer-pm-json2kafka/values.yaml
253 cid="kafka-producer-pm-json2influx"
254 create_clients nonrtric-realm $cid
256 generate_client_secrets nonrtric-realm $cid
259 export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid)
261 envsubst < helm/nrt-pm/charts/kafka-producer-pm-json2influx/values-template.yaml > helm/nrt-pm/charts/kafka-producer-pm-json2influx/values.yaml
264 cid="pm-producer-json2kafka"
265 create_clients nonrtric-realm $cid
267 generate_client_secrets nonrtric-realm $cid
270 export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid)
272 envsubst < helm/nrt-pm/charts/pm-producer-json2kafka/values-template.yaml > helm/nrt-pm/charts/pm-producer-json2kafka/values.yaml
276 create_clients nonrtric-realm $cid
278 generate_client_secrets nonrtric-realm $cid
281 export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid)
283 envsubst < helm/nrt-pm/charts/dfc/values-template.yaml > helm/nrt-pm/charts/dfc/values.yaml
286 #envsubst < helm/nrt-pm/charts/ics/values-template.yaml > helm/nrt-pm/charts/ics/values.yaml
288 helm install --wait -n nonrtric nrt-pm helm/nrt-pm
292 echo "######################################################################"
293 echo "ranpm installed"
294 echo "Wait until all pods are running before installation additional charts"
295 echo "Do: 'kubectl get po -n nonrtric' and verify that all pods are in status Running"
296 echo " and all included containers are Ready"
297 echo "######################################################################"