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 KUBERNETESHOST=$(kube_get_controlplane_host)
37 echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
38 echo "Kubernetes control plane host: $KUBERNETESHOST"
39 echo "Host obtained from current kubectl context"
40 echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
42 echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
43 echo "Checking requirements"
44 echo " Checking if istio is installed"
45 kubectl $KUBECONF get authorizationpolicies -A &> /dev/null
47 echo " Istio api: kubectl get authorizationpolicies is not installed"
52 echo " Checking if jq is installed"
55 echo " Command utility jq (cmd-line json processor) is not installed"
60 echo " Checking if envsubst is installed"
63 echo " Command utility envsubst (env var substitution in files) is not installed"
69 echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
70 echo "Restarting istiod, workaround to refresh jwks cache"
71 kubectl rollout restart deployments/istiod -n istio-system
72 echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
74 # Generic error printout function
75 # args: <numeric-response-code> <descriptive-string>
84 ##################################################################################
85 echo "##### Installing chart: nrt-base-0"
86 ##################################################################################
87 helm install --wait --create-namespace -n nonrtric nrt-base-0 helm/nrt-base-0
89 # Create realm in keycloak
91 . scripts/populate_keycloak.sh
93 create_realms nonrtric-realm
94 while [ $? -ne 0 ]; do
95 create_realms nonrtric-realm
98 # Create client for admin calls
100 create_clients nonrtric-realm $cid
102 generate_client_secrets nonrtric-realm $cid
109 TOKEN=$(get_client_token nonrtric-realm $cid)
111 ##################################################################################
112 echo "##### Installing charts: strimzi and nrt-base-1"
113 ##################################################################################
115 helm repo add strimzi https://strimzi.io/charts/
117 helm install --wait strimzi-kafka-crds -n nonrtric strimzi/strimzi-kafka-operator
120 cp opa-rules/bundle.tar.gz helm/nrt-base-1/charts/opa-rule-db/data
122 helm install -n nonrtric nrt-base-1 helm/nrt-base-1
124 echo "Waiting for influx db - there may be error messages while trying..."
126 while [ $retcode -eq 1 ]; do
128 CONFIG=$(kubectl exec -n nonrtric influxdb2-0 -- influx config ls --json)
129 if [ $? -ne 0 ]; then
132 elif [ "$CONFIG" == "{}" ]; then
133 echo "Configuring db"
134 kubectl exec -n nonrtric influxdb2-0 -- influx setup -u admin -p mySuP3rS3cr3tT0keN -o est -b pm-bucket -f
135 if [ $? -ne 0 ]; then
140 echo "Db user configured, skipping"
144 # Save influx user api-token to secret
147 darwin*) B64FLAG="" ;;
149 INFLUXDB2_TOKEN=$(get_influxdb2_token influxdb2-0 nonrtric | base64 $B64FLAG)
150 PATCHDATA='[{"op": "add", "path": "/data/token", "value": "'$INFLUXDB2_TOKEN'"}]'
151 kubectl patch secret influxdb-api-token -n nonrtric --type json -p "$PATCHDATA"
153 echo "Wait for kafka"
155 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
156 echo -ne " $(($SECONDS-$_ts)) sec, retrying at $(($SECONDS-$_ts+5)) sec $SAMELINE"
161 # Pre-create known topic to avoid losing data when autocreated by apps
162 __topics_list="file-ready collected-file json-file-ready-kp json-file-ready-kpadp pmreports"
163 for __topic in $__topics_list; do
164 create_topic kafka-1-kafka-bootstrap.nonrtric:9092 $__topic 10
169 ##################################################################################
170 echo "##### Installing: chart ran"
171 ##################################################################################
173 ./helm/ran/certs/gen-certs.sh 10
176 helm install --wait --create-namespace -n ran -f helm/global-values.yaml ran helm/ran
180 ##################################################################################
181 echo "##### Installing chart: nrt-pm"
182 ##################################################################################
186 echo "Updating dfc truststore"
187 cd helm/nrt-pm/charts/dfc/truststore
188 cp template-truststore.jks truststore.jks
191 echo " Adding https ca cert to dfc truststore"
192 cat <<__EOF__ | keytool -importcert -alias pm-https -file $cwd/helm/ran/certs/httpsca.crt -keystore truststore.jks -storetype JKS -storepass $(< truststore.pass)
197 cid="kafka-producer-pm-xml2json"
198 create_clients nonrtric-realm $cid
200 generate_client_secrets nonrtric-realm $cid
203 export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid)
205 envsubst < helm/nrt-pm/charts/kafka-producer-pm-xml2json/values-template.yaml > helm/nrt-pm/charts/kafka-producer-pm-xml2json/values.yaml
208 cid="kafka-producer-pm-json2kafka"
209 create_clients nonrtric-realm $cid
211 generate_client_secrets nonrtric-realm $cid
214 export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid)
216 envsubst < helm/nrt-pm/charts/kafka-producer-pm-json2kafka/values-template.yaml > helm/nrt-pm/charts/kafka-producer-pm-json2kafka/values.yaml
219 cid="kafka-producer-pm-json2influx"
220 create_clients nonrtric-realm $cid
222 generate_client_secrets nonrtric-realm $cid
225 export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid)
227 envsubst < helm/nrt-pm/charts/kafka-producer-pm-json2influx/values-template.yaml > helm/nrt-pm/charts/kafka-producer-pm-json2influx/values.yaml
230 cid="pm-producer-json2kafka"
231 create_clients nonrtric-realm $cid
233 generate_client_secrets nonrtric-realm $cid
236 export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid)
238 envsubst < helm/nrt-pm/charts/pm-producer-json2kafka/values-template.yaml > helm/nrt-pm/charts/pm-producer-json2kafka/values.yaml
242 create_clients nonrtric-realm $cid
244 generate_client_secrets nonrtric-realm $cid
247 export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid)
249 envsubst < helm/nrt-pm/charts/dfc/values-template.yaml > helm/nrt-pm/charts/dfc/values.yaml
251 helm install --wait -f helm/global-values.yaml -n nonrtric nrt-pm helm/nrt-pm
255 echo "######################################################################"
256 echo "ranpm installed"
257 echo "Wait until all pods are running before installation additional charts"
258 echo "Do: 'kubectl get po -n nonrtric' and verify that all pods are in status Running"
259 echo " and all included containers are Ready"
260 echo "######################################################################"