Matteo Scandolo | b4c5f4e | 2020-11-11 12:05:23 -0800 | [diff] [blame] | 1 | --- |
| 2 | |
| 3 | # Copyright 2020-present Open Networking Foundation |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | apiVersion: v1 |
| 17 | kind: ConfigMap |
| 18 | metadata: |
| 19 | name: {{ .Release.Name }}-onos-configs-loader |
| 20 | data: |
| 21 | loader.sh: > |
| 22 | set -euo pipefail |
| 23 | |
Matteo Scandolo | 9be943e | 2021-03-29 15:27:55 -0700 | [diff] [blame] | 24 | # onos-config-loader most likely start before ONOS is deployed, so check for ONOS before waiting for it to be ready |
| 25 | |
| 26 | has_onos=$(kubectl get pods -l app=onos-classic --all-namespaces | wc -l); |
| 27 | |
| 28 | while [[ $has_onos == 0 ]]; do |
| 29 | echo -e "Waiting for ONOS to be deployed"; |
| 30 | sleep 5; |
| 31 | has_onos=$(kubectl get pods -l app=onos-classic --all-namespaces | wc -l); |
| 32 | done |
| 33 | |
| 34 | # wait all ONOS pods to be ready |
| 35 | |
| 36 | onos_starting=$(kubectl get pods -l app=onos-classic --all-namespaces --field-selector=status.phase!=Running | wc -l); |
| 37 | |
| 38 | while [[ $onos_starting != 0 ]]; do |
| 39 | echo -e "$onos_starting ONOS instances are still starting..."; |
| 40 | sleep 5; |
| 41 | onos_starting=$(kubectl get pods --all-namespaces -l app=onos-classic | grep "0/" | wc -l); |
| 42 | done |
| 43 | |
Matteo Scandolo | 98c06bf | 2021-02-17 10:12:22 -0800 | [diff] [blame] | 44 | # a POST to a non ready netcfg return 207 in case of failure, while a GET returns 404, |
| 45 | # check the apps key is ready to accept data before sending them |
Matteo Scandolo | a2e4be3 | 2021-03-02 10:28:22 -0800 | [diff] [blame] | 46 | |
Matteo Scandolo | 98c06bf | 2021-02-17 10:12:22 -0800 | [diff] [blame] | 47 | until curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} -X GET -H 'Accept: application/json' "http://{{ .Release.Name }}-onos-classic-hs:8181/onos/v1/network/configuration/apps"; |
| 48 | do |
| 49 | echo -e "Waiting for netcfg to be active"; |
| 50 | sleep 5; |
| 51 | done |
| 52 | |
Matteo Scandolo | befe373 | 2021-03-25 13:45:56 -0700 | [diff] [blame] | 53 | echo -e "\n\nLoading netcfg into ONOS\n"; |
| 54 | cat /opt/configs/netcfg.json; |
Matteo Scandolo | a2e4be3 | 2021-03-02 10:28:22 -0800 | [diff] [blame] | 55 | responseCode=$(curl --write-out '%{http_code}' --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} -X POST "http://{{ .Release.Name }}-onos-classic-hs:8181/onos/v1/network/configuration/" -H Content-type:application/json -d @/opt/configs/netcfg.json); |
| 56 | if [[ $responseCode == 207 ]]; then |
| 57 | echo "Failed to load netcfg, exiting..." |
| 58 | exit 1 |
| 59 | fi |
Matteo Scandolo | b4c5f4e | 2020-11-11 12:05:23 -0800 | [diff] [blame] | 60 | |
Matteo Scandolo | befe373 | 2021-03-25 13:45:56 -0700 | [diff] [blame] | 61 | sleep 5; |
| 62 | echo -e "Updated netconfig is:"; |
| 63 | curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} -X GET -H 'Accept: application/json' "http://{{ .Release.Name }}-onos-classic-hs:8181/onos/v1/network/configuration"; |
| 64 | echo -e "\nCompleted on: "; |
| 65 | date; |
| 66 | |
| 67 | echo -e "\n\n\nLoading component configs into ONOS\n"; |
Matteo Scandolo | b4c5f4e | 2020-11-11 12:05:23 -0800 | [diff] [blame] | 68 | CFGS=$(ls /opt/configs | grep -v netcfg.json); |
| 69 | for CFG in ${CFGS}; |
| 70 | do |
Matteo Scandolo | df2ac53 | 2021-02-05 14:05:41 -0800 | [diff] [blame] | 71 | echo -e "Check that component $CFG is active"; |
| 72 | until curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} -X GET "http://{{ .Release.Name }}-onos-classic-hs:8181/onos/v1/configuration/$CFG"; |
| 73 | do |
| 74 | echo -e "Waiting for $CFG to be active"; |
| 75 | sleep 5; |
| 76 | done |
Matteo Scandolo | befe373 | 2021-03-25 13:45:56 -0700 | [diff] [blame] | 77 | echo -e "\nLoading $CFG config"; |
| 78 | cat /opt/configs/$CFG; |
Matteo Scandolo | 87ed133 | 2021-03-17 17:29:18 -0700 | [diff] [blame] | 79 | responseCode=$(curl --write-out '%{http_code}' --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} -X POST "http://{{ .Release.Name }}-onos-classic-hs:8181/onos/v1/configuration/$CFG" -H Content-type:application/json -d @/opt/configs/$CFG); |
| 80 | if [[ $responseCode == 207 ]]; then |
| 81 | echo "Failed to load $CFG, exiting..." |
| 82 | exit 1 |
| 83 | fi |
Matteo Scandolo | befe373 | 2021-03-25 13:45:56 -0700 | [diff] [blame] | 84 | echo -e "Updated component config for $CFG is:"; |
| 85 | curl --fail -sSL --user {{ .Values.onos.username }}:{{ .Values.onos.password }} -X GET "http://{{ .Release.Name }}-onos-classic-hs:8181/onos/v1/configuration/$CFG"; |
| 86 | echo -e "\nCompleted on: "; |
| 87 | date; |
| 88 | echo -e "\n\n\n" |
Matteo Scandolo | b4c5f4e | 2020-11-11 12:05:23 -0800 | [diff] [blame] | 89 | done |