3 # ============LICENSE_START=======================================================
5 # ================================================================================
6 # Copyright (C) 2020-2021 Nokia. All rights reserved.
7 # ================================================================================
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 # 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=========================================================
23 spec_configmap_filename=$1
26 generation_directory=$4
29 MAX_CONFIG_MAP_UPDATE_SIZE=262144 # If ConfigMaps is bigger then this value (in Bytes) it can not be updated
30 MAX_SPEC_SIZE=1048576 # 1MB
33 alias kubectl_onap="kubectl -n onap"
35 # Checks whether ConfigMap exists
36 # When file does not exist exits with return code 1
37 # $1 - name of spec_configmap_filename
38 check_if_spec_exists() {
39 check_arguments $# $EXPECTED_1_ARG
41 if [ ! -f "$spec_filename" ]; then
42 echo "Spec file $spec_filename does not exist."
43 # todo add location of spec with filename
48 # If spec file is to big to be apply it needs to be created
49 # If ConfigMap with same name exists, iot needs do be destroyed
50 # $1 - name of spec file
52 echo "ConfigMap spec file is too long for 'kubectl apply'. Actual spec length: $spec_size, max spec length: $MAX_CONFIG_MAP_UPDATE_SIZE"
53 echo "Creating new ConfigMap $k8s_configmap_name"
54 kubectl_onap replace --force -f "$spec_filename"
57 # Install ConfigMap from spec
58 # $1 - name of spec file
59 # $2 - size of spec file
60 install_config_map() {
61 check_arguments $# $EXPECTED_2_ARGS
64 if [ "$spec_size" -le $MAX_CONFIG_MAP_UPDATE_SIZE ]; then
65 echo "Applying ConfigMap $k8s_configmap_name"
66 kubectl_onap apply -f "$spec_filename"
72 # Uploads ConfigMap spec to Kubernetes
73 # $1 - name of spec_configmap_filename
75 check_arguments $# $EXPECTED_1_ARG
77 spec_size=$(stat --printf="%s" "$spec_filename")
78 if [ "$spec_size" -le "$MAX_SPEC_SIZE" ]; then
79 install_config_map $spec_filename $spec_size
82 echo " Config file is to big to be installed"
83 echo " Config file size is: $spec_size Bytes"
84 echo " Max size is: $MAX_SPEC_SIZE Bytes"
88 # install all specs located in generated specs directory
90 install_all_spec_in_directory() {
95 check_if_spec_exists $f
100 # Moving to directory containing specs
101 move_to_specs_directory() {
102 target_directory="$generation_directory/$specs_directory"
103 echo "Moving to directory containing specs: $target_directory"
104 cd ./"$target_directory"
108 check_arguments $arguments_number $EXPECTED_4_ARGS
109 move_to_specs_directory
110 install_all_spec_in_directory
111 move_to_starting_directory