BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 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 |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 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================================================= |
| 18 | # |
| 19 | |
| 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 |
| 25 | |
| 26 | # Constants |
| 27 | SAMELINE="\033[0K\r" |
| 28 | |
| 29 | # Variables |
BjornMagnussonXA | 6ab531b | 2023-05-15 11:23:35 +0200 | [diff] [blame] | 30 | export KUBERNETESHOST=$(kube_get_controlplane_host) |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 31 | if [ $? -ne 0 ]; then |
BjornMagnussonXA | 6ab531b | 2023-05-15 11:23:35 +0200 | [diff] [blame] | 32 | echo $KUBERNETESHOST |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 33 | echo "Exiting" |
| 34 | exit 1 |
| 35 | fi |
| 36 | |
| 37 | echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" |
BjornMagnussonXA | 6ab531b | 2023-05-15 11:23:35 +0200 | [diff] [blame] | 38 | echo "Kubernetes control plane host: $KUBERNETESHOST" |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 39 | echo "Host obtained from current kubectl context" |
| 40 | echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" |
| 41 | |
| 42 | echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" |
BjornMagnussonXA | 6ab531b | 2023-05-15 11:23:35 +0200 | [diff] [blame] | 43 | echo "Checking requirements" |
| 44 | echo " Checking if istio is installed" |
| 45 | kubectl $KUBECONF get authorizationpolicies -A &> /dev/null |
| 46 | if [ $? -ne 0 ]; then |
| 47 | echo " Istio api: kubectl get authorizationpolicies is not installed" |
| 48 | exit 1 |
| 49 | else |
| 50 | echo " OK" |
| 51 | fi |
| 52 | echo " Checking if jq is installed" |
| 53 | tmp=$(type jq) |
| 54 | if [ $? -ne 0 ]; then |
| 55 | echo " Command utility jq (cmd-line json processor) is not installed" |
| 56 | exit 1 |
| 57 | else |
| 58 | echo " OK" |
| 59 | fi |
| 60 | echo " Checking if envsubst is installed" |
| 61 | tmp=$(type envsubst) |
| 62 | if [ $? -ne 0 ]; then |
| 63 | echo " Command utility envsubst (env var substitution in files) is not installed" |
| 64 | exit 1 |
| 65 | else |
| 66 | echo " OK" |
| 67 | fi |
| 68 | |
| 69 | echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 70 | echo "Restarting istiod, workaround to refresh jwks cache" |
| 71 | kubectl rollout restart deployments/istiod -n istio-system |
| 72 | echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" |
| 73 | |
| 74 | # Generic error printout function |
| 75 | # args: <numeric-response-code> <descriptive-string> |
| 76 | check_error() { |
| 77 | if [ $1 -ne 0 ]; then |
| 78 | echo "Failed: $2" |
| 79 | echo "Exiting..." |
| 80 | exit 1 |
| 81 | fi |
| 82 | } |
| 83 | |
| 84 | ################################################################################## |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 85 | echo "##### Installing chart: nrt-base-0" |
| 86 | ################################################################################## |
rohithrajneesh | b3ba53a | 2023-08-08 12:22:37 +0100 | [diff] [blame] | 87 | helm install --wait --create-namespace -n nonrtric nrt-base-0 helm/nrt-base-0 |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 88 | |
| 89 | # Create realm in keycloak |
| 90 | |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 91 | . scripts/populate_keycloak.sh |
| 92 | |
| 93 | create_realms nonrtric-realm |
| 94 | while [ $? -ne 0 ]; do |
| 95 | create_realms nonrtric-realm |
| 96 | done |
| 97 | |
| 98 | # Create client for admin calls |
| 99 | cid="console-setup" |
| 100 | create_clients nonrtric-realm $cid |
| 101 | check_error $? |
| 102 | generate_client_secrets nonrtric-realm $cid |
| 103 | check_error $? |
| 104 | |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 105 | echo "" |
| 106 | |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 107 | cid="console-setup" |
| 108 | __get_admin_token |
| 109 | TOKEN=$(get_client_token nonrtric-realm $cid) |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 110 | |
| 111 | ################################################################################## |
| 112 | echo "##### Installing charts: strimzi and nrt-base-1" |
| 113 | ################################################################################## |
| 114 | |
| 115 | helm repo add strimzi https://strimzi.io/charts/ |
| 116 | |
| 117 | helm install --wait strimzi-kafka-crds -n nonrtric strimzi/strimzi-kafka-operator |
| 118 | |
| 119 | |
| 120 | cp opa-rules/bundle.tar.gz helm/nrt-base-1/charts/opa-rule-db/data |
| 121 | |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 122 | helm install -n nonrtric nrt-base-1 helm/nrt-base-1 |
| 123 | |
BjornMagnussonXA | 6ab531b | 2023-05-15 11:23:35 +0200 | [diff] [blame] | 124 | echo "Waiting for influx db - there may be error messages while trying..." |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 125 | retcode=1 |
| 126 | while [ $retcode -eq 1 ]; do |
| 127 | retcode=0 |
| 128 | CONFIG=$(kubectl exec -n nonrtric influxdb2-0 -- influx config ls --json) |
| 129 | if [ $? -ne 0 ]; then |
| 130 | retcode=1 |
| 131 | sleep 1 |
| 132 | elif [ "$CONFIG" == "{}" ]; then |
| 133 | echo "Configuring db" |
BjornMagnussonXA | 6ab531b | 2023-05-15 11:23:35 +0200 | [diff] [blame] | 134 | kubectl exec -n nonrtric influxdb2-0 -- influx setup -u admin -p mySuP3rS3cr3tT0keN -o est -b pm-bucket -f |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 135 | if [ $? -ne 0 ]; then |
| 136 | retcode=1 |
| 137 | sleep 1 |
| 138 | fi |
| 139 | else |
| 140 | echo "Db user configured, skipping" |
| 141 | fi |
| 142 | done |
| 143 | |
| 144 | # Save influx user api-token to secret |
BjornMagnussonXA | 1b0fb0b | 2023-05-31 01:46:20 +0200 | [diff] [blame] | 145 | B64FLAG="-w 0" |
| 146 | case "$OSTYPE" in |
| 147 | darwin*) B64FLAG="" ;; |
| 148 | esac |
| 149 | INFLUXDB2_TOKEN=$(get_influxdb2_token influxdb2-0 nonrtric | base64 $B64FLAG) |
BjornMagnussonXA | 6ab531b | 2023-05-15 11:23:35 +0200 | [diff] [blame] | 150 | PATCHDATA='[{"op": "add", "path": "/data/token", "value": "'$INFLUXDB2_TOKEN'"}]' |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 151 | kubectl patch secret influxdb-api-token -n nonrtric --type json -p "$PATCHDATA" |
| 152 | |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 153 | echo "Wait for kafka" |
| 154 | _ts=$SECONDS |
| 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" |
| 157 | sleep 5 |
| 158 | done |
| 159 | echo "" |
| 160 | |
| 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 |
| 165 | done |
| 166 | |
| 167 | echo "" |
| 168 | |
| 169 | ################################################################################## |
DenisGNoonan | 54872c9 | 2023-09-05 11:55:40 +0100 | [diff] [blame] | 170 | echo "##### Installing: chart nonrtricgateway" |
| 171 | ################################################################################## |
| 172 | |
| 173 | helm install --wait -n nonrtric nonrtricgateway helm/nonrtricgateway |
| 174 | echo "" |
| 175 | |
| 176 | ################################################################################## |
| 177 | echo "##### Installing: chart controlpanel" |
| 178 | ################################################################################## |
| 179 | |
| 180 | helm install --wait -n nonrtric controlpanel helm/controlpanel |
| 181 | echo "" |
| 182 | |
| 183 | ################################################################################## |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 184 | echo "##### Installing: chart ran" |
| 185 | ################################################################################## |
| 186 | |
| 187 | ./helm/ran/certs/gen-certs.sh 10 |
| 188 | check_error $? |
| 189 | |
rohithrajneesh | b3ba53a | 2023-08-08 12:22:37 +0100 | [diff] [blame] | 190 | helm install --wait --create-namespace -n ran -f helm/global-values.yaml ran helm/ran |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 191 | |
| 192 | echo "" |
| 193 | |
| 194 | ################################################################################## |
| 195 | echo "##### Installing chart: nrt-pm" |
| 196 | ################################################################################## |
| 197 | |
| 198 | |
| 199 | cwd=$PWD |
| 200 | echo "Updating dfc truststore" |
| 201 | cd helm/nrt-pm/charts/dfc/truststore |
| 202 | cp template-truststore.jks truststore.jks |
| 203 | check_error $? |
| 204 | |
| 205 | echo " Adding https ca cert to dfc truststore" |
| 206 | cat <<__EOF__ | keytool -importcert -alias pm-https -file $cwd/helm/ran/certs/httpsca.crt -keystore truststore.jks -storetype JKS -storepass $(< truststore.pass) |
| 207 | yes |
| 208 | __EOF__ |
| 209 | cd $cwd |
| 210 | |
| 211 | cid="kafka-producer-pm-xml2json" |
| 212 | create_clients nonrtric-realm $cid |
| 213 | check_error $? |
| 214 | generate_client_secrets nonrtric-realm $cid |
| 215 | check_error $? |
| 216 | |
| 217 | export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid) |
| 218 | |
| 219 | envsubst < helm/nrt-pm/charts/kafka-producer-pm-xml2json/values-template.yaml > helm/nrt-pm/charts/kafka-producer-pm-xml2json/values.yaml |
| 220 | |
| 221 | |
| 222 | cid="kafka-producer-pm-json2kafka" |
| 223 | create_clients nonrtric-realm $cid |
| 224 | check_error $? |
| 225 | generate_client_secrets nonrtric-realm $cid |
| 226 | check_error $? |
| 227 | |
| 228 | export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid) |
| 229 | |
| 230 | envsubst < helm/nrt-pm/charts/kafka-producer-pm-json2kafka/values-template.yaml > helm/nrt-pm/charts/kafka-producer-pm-json2kafka/values.yaml |
| 231 | |
| 232 | |
| 233 | cid="kafka-producer-pm-json2influx" |
| 234 | create_clients nonrtric-realm $cid |
| 235 | check_error $? |
| 236 | generate_client_secrets nonrtric-realm $cid |
| 237 | check_error $? |
| 238 | |
| 239 | export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid) |
| 240 | |
| 241 | envsubst < helm/nrt-pm/charts/kafka-producer-pm-json2influx/values-template.yaml > helm/nrt-pm/charts/kafka-producer-pm-json2influx/values.yaml |
| 242 | |
| 243 | |
| 244 | cid="pm-producer-json2kafka" |
| 245 | create_clients nonrtric-realm $cid |
| 246 | check_error $? |
| 247 | generate_client_secrets nonrtric-realm $cid |
| 248 | check_error $? |
| 249 | |
| 250 | export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid) |
| 251 | |
| 252 | envsubst < helm/nrt-pm/charts/pm-producer-json2kafka/values-template.yaml > helm/nrt-pm/charts/pm-producer-json2kafka/values.yaml |
| 253 | |
| 254 | |
| 255 | cid="dfc" |
| 256 | create_clients nonrtric-realm $cid |
| 257 | check_error $? |
| 258 | generate_client_secrets nonrtric-realm $cid |
| 259 | check_error $? |
| 260 | |
| 261 | export APP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid) |
| 262 | |
| 263 | envsubst < helm/nrt-pm/charts/dfc/values-template.yaml > helm/nrt-pm/charts/dfc/values.yaml |
| 264 | |
BjornMagnussonXA | 6ab531b | 2023-05-15 11:23:35 +0200 | [diff] [blame] | 265 | helm install --wait -f helm/global-values.yaml -n nonrtric nrt-pm helm/nrt-pm |
BjornMagnussonXA | c5655db | 2023-03-17 14:55:16 +0100 | [diff] [blame] | 266 | |
| 267 | echo "" |
| 268 | |
| 269 | echo "######################################################################" |
| 270 | echo "ranpm installed" |
| 271 | echo "Wait until all pods are running before installation additional charts" |
| 272 | echo "Do: 'kubectl get po -n nonrtric' and verify that all pods are in status Running" |
| 273 | echo " and all included containers are Ready" |
DenisGNoonan | 54872c9 | 2023-09-05 11:55:40 +0100 | [diff] [blame] | 274 | echo "######################################################################" |