NONRTRIC-946: Servicemanager - update README and fix stand-alone deployment 53/12753/2
authorDenisGNoonan <denis.noonan@est.tech>
Wed, 17 Apr 2024 19:15:39 +0000 (20:15 +0100)
committerDenisGNoonan <denis.noonan@est.tech>
Thu, 18 Apr 2024 10:15:20 +0000 (11:15 +0100)
Change-Id: I4bfba42225f792683c4fe6f50f794b1bc46358fc
Signed-off-by: DenisGNoonan <denis.noonan@est.tech>
servicemanager/README.md
servicemanager/deploy/manifests/capifcore.yaml
servicemanager/deploy/manifests/servicemanager.yaml
servicemanager/deploy/src/delete-from-k8s.sh
servicemanager/deploy/src/deploy-to-k8s.sh
servicemanager/generate.sh

index e5a1b63..74c92aa 100644 (file)
@@ -40,20 +40,19 @@ specifications from 3GPP, fixes them and then generates the APIs. While these fi
 ```
 
 The specifications are downloaded from the following site; https://www.3gpp.org/ftp/Specs/archive/29_series. To see
-the APIs in swagger format, see the following link; https://github.com/jdegre/5GC_APIs/tree/Rel-16#common-api-framework-capif.
-**NOTE!** The documentation in this link is for release 16 of CAPIF, the downloaded specifications are for release 17.
+the APIs in swagger format, see the following link; https://github.com/jdegre/5GC_APIs/tree/Rel-17#common-api-framework-capif.
 
 To fix the specifications there are three tools.
 - `commoncollector`, collects type definitions from peripheral specifications to keep down the number of dependencies to
-  other specifications. The types to collect are listed in the `definitions.txt`file. Some fixes are hard coded.
+  other specifications. The types to collect are listed in the `definitions.txt` file. Some fixes are hard-coded.
 - `enumfixer`, fixes enumeration definitions so they can be properly generated.
-- `specificationfixer`, fixes flaws in the specifications so they can be properly generated. All fixes are hard coded.
+- `specificationfixer`, fixes flaws in the specifications so they can be properly generated. All fixes are hard-coded.
 
 ## Set Up
 
 First, we need to run `generate.sh` as described above to generate our API code from the 3GPP spec.
 
-Before we can test or run R1-SME-Manager, we need to configure a .env file with the required parameters. Please see the template .env.example in the servicemanager directory.
+Before we can test or run Service Manager, we need to configure a .env file with the required parameters. Please see the template .env.example in the servicemanager directory.
 
 You can set the environmental variable SERVICE_MANAGER_ENV to specify the .env file. For example, the following command specifies to use the config file
 .env.development. If this flag is not set, first we try .env.development and then .env.
@@ -62,9 +61,9 @@ You can set the environmental variable SERVICE_MANAGER_ENV to specify the .env f
 export SERVICE_MANAGER_ENV=development
 ```
 
-### Capifcore and Kong
+### CAPIFcore and Kong
 
-We also need Kong and Capifcore to be running. Please see the examples in the `configs` folder.
+We also need Kong and CAPIFcore to be running. Please see the examples in the `deploy` folder. You can also use https://gerrit.o-ran-sc.org/r/it/dep for deployment. Please see the notes at https://wiki.o-ran-sc.org/display/RICNR/%5BWIP%5D+Service+Manager.
 
 ## Build
 
@@ -76,11 +75,11 @@ go build
 
 ## Unit Tests
 
-To run the unit tests for the application, first ensure that the .env file is configured. In the following example, we specify `.env.test`. For now, we need to disable parallelism in the unit tests with -p=1.
+To run the unit tests for the application, first ensure that the .env file is configured. In the following example, we specify `.env.test`.
 
 ```sh
 export SERVICE_MANAGER_ENV=test
-go test -p=1 -count=1 ./...
+go test ./...
 ```
 
 ## Run Locally
@@ -92,11 +91,11 @@ export SERVICE_MANAGER_ENV=development
 ./servicemanager
 ```
 
-R1-SME-Manager is then available on the port configured in .env.
+Service Manager is then available on the port configured in .env.
 
 ## Building the Docker Image
 
-The application can also be built as a Docker image, by using the following command. We build the image without a .env file. This is supplied by volume mounting at container run-time. Because we need to include Capifcore in the Docker build context, we build from the git repo's root directory, sme.
+The application can also be built as a Docker image, by using the following command. We build the image without a .env file. This is supplied by volume mounting at container run-time. Because we need to include CAPIFcore in the Docker build context, we build from the git repo's root directory, sme.
 
 ```sh
 docker build -t servicemanager -f servicemanager/Dockerfile .
@@ -104,27 +103,23 @@ docker build -t servicemanager -f servicemanager/Dockerfile .
 
 ## Kongclearup
 
-Please note that a special executable has been provided for deleting Kong routes and services that have been created ServiceManager in Kong. This executable is called `kongclearup` and is found in the working directory of the ServiceManger Docker image, at `/app/kongclearup`. When we create a Kong route or service, we add Kong tags with information as follows.
+Please note that a special executable has been provided for deleting Kong routes and services that have been created by Service Manager in Kong. This executable is called `kongclearup` and is found in the working directory of the Service Manger Docker image, at `/app/servicemanager`. When we create a Kong route or service, we add Kong tags with information as follows.
   * apfId
   * aefId
   * apiId
   * apiVersion
   * resourceName
 
-When we delete Kong routes and services using `kongclearup`, we check for the existance of these tags, specifically, apfId, apiId and aefId. Only if these tags exist and have values do we proceed to delete the Kong service or route.
-
-The executable `kongclearup` uses the volume-mounted .env file to load the configuration giving the location of Kong.
-
-Please refer to `sme/servicemanager/internal/kongclearup.go`.
+When we delete Kong routes and services using `kongclearup`, we check for the existance of these tags, specifically, apfId, apiId and aefId. Only if these tags exist and have values do we proceed to delete the Kong service or route. The executable `kongclearup` uses the volume-mounted .env file to load the configuration giving the location of Kong. Please refer to `sme/servicemanager/internal/kongclearup.go`.
 
 ## Stand-alone Deployment on Kubernetes
 
-For a stand-alone deployment, please see the `deploy` folder for configurations to deploy to R1-SME-Manager to Kubernetes. We need the following steps.
- - Deploy a PV for Kong's Postgres database (depends on your Kubernetes cluster)
+For a stand-alone deployment, please see the `deploy` folder for configurations to deploy to Service Manager to Kubernetes. We need the following steps.
+ - Deploy a PV for Kong's Postgres database (depends on your Kubernetes cluster, not needed for Minikube)
  - Deploy a PVC for Kong's Postgres database
  - Deploy Kong with Postgres
- - Deploy Capifcore
- - Deploy R1-SME-Manager
+ - Deploy CAPIFcore
+ - Deploy Service Manager
 
 We consolidate the above steps into the script `deploy-to-k8s.sh`. To delete the full deployment, you can use `delete-from-k8s.sh`. The deploy folder has the following structure.
 
@@ -136,10 +131,14 @@ We consolidate the above steps into the script `deploy-to-k8s.sh`. To delete the
 
 We store the Kubernetes manifests files in the manifests in the subfolder. We store the shell scripts in the src folder.
 
-In `deploy-to-k8s.sh`, we copy .env.example and use sed to replace the template values with values for testing/production. You will need to update this part of the script with your own values. There is an example sed replacement in function `substitute_manifest()` in `deploy-to-k8s.sh`. Here, you can substitute your own Docker images for Capifcore and Service Manager for local development.
+In `deploy-to-k8s.sh`, we copy .env.example and use `sed` to replace the template values with values for running the Service Manager container. You will need to update this part of the script with your own values. There is an example sed replacement in function `substitute_manifest()` in `deploy-to-k8s.sh`. Here, you can substitute your own Docker images for CAPIFcore and Service Manager for local development.
 
 In addition there are 2 switches that are added for developer convenience.
- * --repo # allow you to specify your own docker repo
- * --env  # allow you to specify an additional env file, and set SERVICE_MANAGER_ENV to point to this file.
+ * --repo # allows you to specify your own docker repo, e.g. your Docker Hub id
+ * --env  # allows you to specify an additional env file, and sets SERVICE_MANAGER_ENV in the Docker environment to point to this file.
+
+The additional env file needs to exist in the sme/servicemanager folder so that kongclearup can access is. It is specified by its filename. The relative path ../.. is added in the `deploy-to-k8s.sh` script. For example, to use
+
+`./deploy-to-k8s.sh --env .env.development`
 
-`./deploy-to-k8s.sh --repo your-docker-repo-id --env ../../.env.minikube`
+ ../../.env.development needs to exist.
\ No newline at end of file
index 7efc107..0c98592 100644 (file)
@@ -36,7 +36,7 @@ spec:
     spec:
       containers:
       - name: capifcore
-        image: o-ran-sc.org/nonrtric/plt/capifcore
+        image: "nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-plt-capifcore:1.3.1"
         imagePullPolicy: IfNotPresent
         ports:
         - containerPort: 8090
index 3f937ff..c49a9a6 100644 (file)
@@ -36,7 +36,7 @@ spec:
     spec:
       containers:
       - name: servicemanager
-        image: o-ran-sc.org/nonrtric/plt/servicemanager
+        image: "nexus3.o-ran-sc.org:10004/o-ran-sc/nonrtric-plt-servicemanager:0.1.1"
         imagePullPolicy: IfNotPresent
         env:
             - name: SERVICE_MANAGER_ENV
@@ -52,7 +52,7 @@ spec:
             cpu: "80m"
         volumeMounts:
         - name: config-volume
-          mountPath: /app/.env
+          mountPath: /app/servicemanager/.env
           subPath: .env
       volumes:
       - name: config-volume
index fd5289c..f86af1f 100755 (executable)
 echo $(date -u) "delete-from-k8s started"
 
 # Delete R1-SME-Manager with Capifcore
+echo "Warning - deleting Kong routes and services for ServiceManager"
+SERVICEMANAGER_POD=$(kubectl get pods -o custom-columns=NAME:.metadata.name -l app=servicemanager --no-headers -n servicemanager)
+if [[ -n $SERVICEMANAGER_POD ]]; then
+    kubectl exec $SERVICEMANAGER_POD -n servicemanager -- ./kongclearup
+else
+    echo "Error - Servicemanager pod not found, didn't delete Kong routes and services for ServiceManager"
+fi
+
 kubectl delete -f ../manifests/servicemanager.yaml
 kubectl delete configmap env-configmap -n servicemanager
 kubectl delete -f ../manifests/capifcore.yaml
+
 kubectl delete ns servicemanager
 
 # Delete Kong
-go run ../../internal/kongclearup.go
 helm uninstall kong -n kong
 helm repo remove kong
-kubectl wait deploy/kong-kong --for=delete --timeout=-300s -n kong 
+kubectl wait deploy/kong-kong --for=delete --timeout=-300s -n kong
 
 # Delete storage for the Postgres used by Kong
 kubectl delete -f ../manifests/kong-postgres-pvc.yaml
index 9e81d61..be890dd 100755 (executable)
 create_env_from_template(){
     # Set up .env file for Kubernetes Config Map
     echo "create_env_from_template"
-    cp -v ../../.env.example ./.env
-    sed -i 's/KONG_DOMAIN=<string>/KONG_DOMAIN=kong/' .env
-    sed -i 's/KONG_PROTOCOL=<http or https protocol scheme>/KONG_PROTOCOL=http/' .env
-    sed -i 's/KONG_IPV4=<host string>/KONG_IPV4=10.101.1.101/' .env
-    sed -i 's/KONG_DATA_PLANE_PORT=<port number>/KONG_DATA_PLANE_PORT=32080/' .env
-    sed -i 's/KONG_CONTROL_PLANE_PORT=<port number>/KONG_CONTROL_PLANE_PORT=32081/' .env
-    sed -i 's/CAPIF_PROTOCOL=<http or https protocol scheme>/CAPIF_PROTOCOL=http/' .env
-    sed -i 's/CAPIF_IPV4=<host>/CAPIF_IPV4=10.101.1.101/' .env
-    sed -i 's/CAPIF_PORT=<port number>/CAPIF_PORT=31570/' .env
-    sed -i 's/LOG_LEVEL=<Trace, Debug, Info, Warning, Error, Fatal or Panic>/LOG_LEVEL=Info/' .env
-    sed -i 's/SERVICE_MANAGER_PORT=<port number>/SERVICE_MANAGER_PORT=8095/' .env
-    sed -i 's/TEST_SERVICE_IPV4=<host string>/TEST_SERVICE_IPV4=10.101.1.101/' .env
-    sed -i 's/TEST_SERVICE_PORT=<port number>/TEST_SERVICE_PORT=30951/' .env
+    if [ ! -f ../../.env ]; then
+        cp -v ../../.env.example ../../.env
+        sed -i 's/KONG_DOMAIN=<string>/KONG_DOMAIN=kong/' ../../.env
+        sed -i 's/KONG_PROTOCOL=<http or https protocol scheme>/KONG_PROTOCOL=http/' ../../.env
+        sed -i 's/KONG_IPV4=<host string>/KONG_IPV4=10.101.1.101/' ../../.env
+        sed -i 's/KONG_DATA_PLANE_PORT=<port number>/KONG_DATA_PLANE_PORT=32080/' ../../.env
+        sed -i 's/KONG_CONTROL_PLANE_PORT=<port number>/KONG_CONTROL_PLANE_PORT=32081/' ../../.env
+        sed -i 's/CAPIF_PROTOCOL=<http or https protocol scheme>/CAPIF_PROTOCOL=http/' ../../.env
+        sed -i 's/CAPIF_IPV4=<host>/CAPIF_IPV4=10.101.1.101/' ../../.env
+        sed -i 's/CAPIF_PORT=<port number>/CAPIF_PORT=31570/' ../../.env
+        sed -i 's/LOG_LEVEL=<Trace, Debug, Info, Warning, Error, Fatal or Panic>/LOG_LEVEL=Info/' ../../.env
+        sed -i 's/SERVICE_MANAGER_PORT=<port number>/SERVICE_MANAGER_PORT=8095/' ../../.env
+        sed -i 's/TEST_SERVICE_IPV4=<host string>/TEST_SERVICE_IPV4=10.101.1.101/' ../../.env
+        sed -i 's/TEST_SERVICE_PORT=<port number>/TEST_SERVICE_PORT=30951/' ../../.env
+        echo "created .env"
+    else
+        echo "found .env"
+    fi
 }
 
 substitute_repo(){
@@ -48,28 +53,34 @@ substitute_repo(){
 
 add_env(){
     echo "add_env"
-    additional_env=$1
+    # Our additional .env has to exist in the project root folder
+    additional_env="../../$1"
+
     # Add our own .env file
     if [ -f $additional_env ]; then
-        echo "found additional env"
-        kubectl create configmap env-configmap --from-file=.env --from-file=$additional_env -n servicemanager
+        echo "found additional env $1"
+        kubectl create configmap env-configmap --from-file=../../.env --from-file=$additional_env -n servicemanager
 
         # Add additional env file to volume mounting
         env_filename=$(basename "$additional_env")
         echo "env_filename $env_filename"
 
-        mount_path_wc=$(grep "mountPath: /app/$env_filename" ../manifests/servicemanager.yaml | wc -l)
+        mount_path_wc=$(grep "mountPath: /app/servicemanager/$env_filename" ../manifests/servicemanager.yaml | wc -l)
         env_path_count=$((mount_path_wc))
         if [ $env_path_count -eq 0 ]; then
             echo "Adding mount path"
-            sed -i -e '/subPath: .env/a\' -e "        - name: config-volume\n          mountPath: /app/$env_filename\n          subPath: $env_filename" ../manifests/servicemanager.yaml
+            sed -i -e '/subPath: .env/a\' \
+                -e "        - name: config-volume\n          mountPath: /app/servicemanager/$env_filename\n          subPath: $env_filename" ../manifests/servicemanager.yaml
         fi
 
         # Update SERVICE_MANAGER_ENV to point to additional env
         env_extension=$(basename "$additional_env" | awk -F. '{print $NF}')
-        echo "env_extension $env_extension"
-
+        echo "SERVICE_MANAGER_ENV=$env_extension"
         sed -i "/- name: SERVICE_MANAGER_ENV/{n;s/              value: \"\"/              value: \"$env_extension\"/}" ../manifests/servicemanager.yaml
+        return 0  # Return zero for success
+    else
+        echo "additional env $additional_env NOT found"
+        return 1  # Return non-zero for failure
     fi
 }
 
@@ -136,8 +147,12 @@ kubectl create ns servicemanager
 
 if [ "$ADD_ENV" = true ]; then
     add_env $ENV_PATH
+    # Check if the function failed
+    if [ $? -ne 0 ]; then
+        kubectl create configmap env-configmap --from-file=../../.env -n servicemanager
+    fi
 else
-    kubectl create configmap env-configmap --from-file=.env -n servicemanager
+    kubectl create configmap env-configmap --from-file=../../.env -n servicemanager
 fi
 
 # Create the Kubernetes resources
index efe7a1a..3292703 100755 (executable)
@@ -170,10 +170,10 @@ generate_apis_from_spec () {
 }
 
 run_tests () {
-    # Make sure that SERVICE_MANAGER_ENV is configured with the required .env file, e.g. 
+    # Make sure that SERVICE_MANAGER_ENV is configured with the required .env file, e.g.
     # export SERVICE_MANAGER_ENV=development
     cd "$cwd"
-    go test -p=1 -count=1 ./...
+    go test ./...
 }
 
 # Main code block