2 ##############################################################################
4 # Copyright (C) 2024: OpenInfra Foundation Europe
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.
18 ##############################################################################
20 create_env_from_template(){
21 # Set up .env file for Kubernetes Config Map
22 echo "create_env_from_template"
23 if [ ! -f ../../.env ]; then
24 cp -v ../../.env.example ../../.env
25 sed -i 's/KONG_DOMAIN=<string>/KONG_DOMAIN=kong/' ../../.env
26 sed -i 's/KONG_PROTOCOL=<http or https protocol scheme>/KONG_PROTOCOL=http/' ../../.env
27 sed -i 's/KONG_IPV4=<host string>/KONG_IPV4=10.101.1.101/' ../../.env
28 sed -i 's/KONG_DATA_PLANE_PORT=<port number>/KONG_DATA_PLANE_PORT=32080/' ../../.env
29 sed -i 's/KONG_CONTROL_PLANE_PORT=<port number>/KONG_CONTROL_PLANE_PORT=32081/' ../../.env
30 sed -i 's/CAPIF_PROTOCOL=<http or https protocol scheme>/CAPIF_PROTOCOL=http/' ../../.env
31 sed -i 's/CAPIF_IPV4=<host>/CAPIF_IPV4=10.101.1.101/' ../../.env
32 sed -i 's/CAPIF_PORT=<port number>/CAPIF_PORT=31570/' ../../.env
33 sed -i 's/LOG_LEVEL=<Trace, Debug, Info, Warning, Error, Fatal or Panic>/LOG_LEVEL=Info/' ../../.env
34 sed -i 's/SERVICE_MANAGER_PORT=<port number>/SERVICE_MANAGER_PORT=8095/' ../../.env
35 sed -i 's/TEST_SERVICE_IPV4=<host string>/TEST_SERVICE_IPV4=10.101.1.101/' ../../.env
36 sed -i 's/TEST_SERVICE_PORT=<port number>/TEST_SERVICE_PORT=30951/' ../../.env
44 echo "substitute_repo"
47 # Use our own Capificore and ServiceManager images
48 sed -i "s/image: o-ran-sc.org\/nonrtric\/plt\/capifcore/image: $docker_repo\/capifcore:latest/" ../manifests/capifcore.yaml
49 sed -i 's/imagePullPolicy: IfNotPresent/imagePullPolicy: Always/' ../manifests/capifcore.yaml
50 sed -i "s/image: o-ran-sc.org\/nonrtric\/plt\/servicemanager/image: $docker_repo\/servicemanager:latest/" ../manifests/servicemanager.yaml
51 sed -i 's/imagePullPolicy: IfNotPresent/imagePullPolicy: Always/' ../manifests/servicemanager.yaml
56 # Our additional .env has to exist in the project root folder
57 additional_env="../../$1"
59 # Add our own .env file
60 if [ -f $additional_env ]; then
61 echo "found additional env $1"
62 kubectl create configmap env-configmap --from-file=../../.env --from-file=$additional_env -n servicemanager
64 # Add additional env file to volume mounting
65 env_filename=$(basename "$additional_env")
66 echo "env_filename $env_filename"
68 mount_path_wc=$(grep "mountPath: /app/servicemanager/$env_filename" ../manifests/servicemanager.yaml | wc -l)
69 env_path_count=$((mount_path_wc))
70 if [ $env_path_count -eq 0 ]; then
71 echo "Adding mount path"
72 sed -i -e '/subPath: .env/a\' \
73 -e " - name: config-volume\n mountPath: /app/servicemanager/$env_filename\n subPath: $env_filename" ../manifests/servicemanager.yaml
76 # Update SERVICE_MANAGER_ENV to point to additional env
77 env_extension=$(basename "$additional_env" | awk -F. '{print $NF}')
78 echo "SERVICE_MANAGER_ENV=$env_extension"
79 sed -i "/- name: SERVICE_MANAGER_ENV/{n;s/ value: \"\"/ value: \"$env_extension\"/}" ../manifests/servicemanager.yaml
80 return 0 # Return zero for success
82 echo "additional env $additional_env NOT found"
83 return 1 # Return non-zero for failure
87 echo $(date -u) "deploy-to-k8s started"
89 # Check if the development switch is provided as a command-line argument
93 while [[ "$#" -gt 0 ]]; do
97 shift # consume the switch
100 shift # consume the value
102 echo "Error: Argument for $1 is missing." >&2
108 shift # consume the switch
111 shift # consume the value
113 echo "Error: Argument for $1 is missing." >&2
118 echo "Unknown argument: $1"
124 kubectl create ns kong
126 # Set up storage for Postgres, used by Kong
127 # Minikube uses dynamic provisioning
128 CURRENT_CONTEXT=$(kubectl config current-context)
129 if [ "$CURRENT_CONTEXT" != "minikube" ]; then
130 kubectl create -f ../manifests/kong-postgres-pv.yaml
132 kubectl create -f ../manifests/kong-postgres-pvc.yaml
135 helm repo add kong https://charts.konghq.com
137 helm install kong kong/kong -n kong -f ../manifests/values.yaml
139 create_env_from_template
141 # Check if the development switch is enabled
142 if [ "$USE_OWN_REPO" = true ]; then
143 substitute_repo $DOCKER_REPO
146 kubectl create ns servicemanager
148 if [ "$ADD_ENV" = true ]; then
150 # Check if the function failed
151 if [ $? -ne 0 ]; then
152 kubectl create configmap env-configmap --from-file=../../.env -n servicemanager
155 kubectl create configmap env-configmap --from-file=../../.env -n servicemanager
158 # Create the Kubernetes resources
159 kubectl create -f ../manifests/capifcore.yaml
160 kubectl create -f ../manifests/servicemanager.yaml
162 kubectl rollout status deployment capifcore -n servicemanager --timeout=90s
163 kubectl rollout status deployment servicemanager -n servicemanager --timeout=90s
164 kubectl rollout status deployment kong-kong -n kong --timeout=90s
166 echo $(date -u) "deploy-to-k8s completed"