Add upf-adapter pod helm chart changes

Change-Id: I400e0fe521b97c46acfb937514c8889429eed8bb
diff --git a/5g-control-plane/Chart.yaml b/5g-control-plane/Chart.yaml
index 159184f..56e05f6 100644
--- a/5g-control-plane/Chart.yaml
+++ b/5g-control-plane/Chart.yaml
@@ -1,5 +1,7 @@
 ---
+# SPDX-FileCopyrightText: 2022-present Intel Corporation
 # Copyright 2020-present Open Networking Foundation
+
 #
 # SPDX-License-Identifier: Apache-2.0
 
@@ -8,7 +10,7 @@
 name: 5g-control-plane
 icon: https://guide.opencord.org/logos/cord.svg
 
-version: 0.7.6
+version: 0.7.7
 
 dependencies:
   - name: mongodb
diff --git a/5g-control-plane/templates/bin/_upf-adapter-run.sh.tpl b/5g-control-plane/templates/bin/_upf-adapter-run.sh.tpl
new file mode 100644
index 0000000..d823139
--- /dev/null
+++ b/5g-control-plane/templates/bin/_upf-adapter-run.sh.tpl
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# SPDX-FileCopyrightText: 2022-present Intel Corporation
+#
+# SPDX-License-Identifier: Apache-2.0
+
+set -xe
+
+{{- if .Values.config.coreDump.enabled }}
+cp /free5gc/bin/upf-adapter /tmp/coredump/
+{{- end }}
+
+cd /free5gc
+
+cat config/config.yaml
+
+GOTRACEBACK=crash ./bin/upf-adapter config/config.yaml
diff --git a/5g-control-plane/templates/configmap-smf.yaml b/5g-control-plane/templates/configmap-smf.yaml
index a5ff8cf..8cf4c81 100644
--- a/5g-control-plane/templates/configmap-smf.yaml
+++ b/5g-control-plane/templates/configmap-smf.yaml
@@ -1,4 +1,5 @@
 {{/*
+# SPDX-FileCopyrightText: 2022-present Intel Corporation
 # Copyright 2020-present Open Networking Foundation
 
 # SPDX-License-Identifier: Apache-2.0
@@ -20,6 +21,9 @@
 {{- if not (hasKey $sbi "port") -}}
 {{- $_ := .Values.config.smf.sbi.port | set $sbi "port" -}}
 {{- end }}
+{{- if not (hasKey $smfcfg.configuration "enableUPFAdapter") -}}
+{{- $_ := .Values.config.upfadapter.deploy | set $smfcfg.configuration "enableUPFAdapter" -}}
+{{- end }}
 {{- if not (hasKey $smfcfg.configuration "nfKafka") -}}
 {{- $_ := .Values.kafka.nfKafka | set $smfcfg.configuration "nfKafka" -}}
 {{- $_ := .Values.kafka.deploy | set $smfcfg.configuration.nfKafka "enable" -}}
diff --git a/5g-control-plane/templates/configmap-upf-adapter.yaml b/5g-control-plane/templates/configmap-upf-adapter.yaml
new file mode 100644
index 0000000..5caf460
--- /dev/null
+++ b/5g-control-plane/templates/configmap-upf-adapter.yaml
@@ -0,0 +1,35 @@
+{{/*
+
+# SPDX-FileCopyrightText: 2022-present Intel Corporation
+
+# SPDX-License-Identifier: Apache-2.0
+*/}}
+
+{{- if .Values.config.upfadapter.deploy }}
+
+{{- if not .Values.config.useExistingConfigMap -}}
+{{- $upfadaptercfg := index .Values.config.upfadapter.cfgFiles "config.yaml" }}
+
+{{- if not (hasKey $upfadaptercfg "mongodb") -}}
+{{- $_ := dict "name" .Values.config.mongodb.name "url" .Values.config.mongodb.url | set $upfadaptercfg "mongodb" -}}
+{{- end }}
+
+{{- end }}
+
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: upf-adapter
+  labels:
+{{ tuple "upfadapter" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+data:
+  upf-adapter-run.sh: |
+{{ tuple "bin/_upf-adapter-run.sh.tpl" . | include "5g-control-plane.template" | indent 4 }}
+{{- if not .Values.config.useExistingConfigMap -}}
+{{- range $key, $value := .Values.config.upfadapter.cfgFiles }}
+  {{ $key }}: |-
+{{ toYaml $value | indent 4 }}
+{{- end }}
+{{- end }}
+{{- end }}
diff --git a/5g-control-plane/templates/deployment-upf-adapter.yaml b/5g-control-plane/templates/deployment-upf-adapter.yaml
new file mode 100644
index 0000000..7317537
--- /dev/null
+++ b/5g-control-plane/templates/deployment-upf-adapter.yaml
@@ -0,0 +1,83 @@
+{{/*
+# SPDX-FileCopyrightText: 2022-present Intel Corporation
+
+# SPDX-License-Identifier: Apache-2.0
+*/}}
+
+{{- if .Values.config.upfadapter.deploy }}
+{{ tuple "upfadapter" . | include "5g-control-plane.service_account" }}
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: upf-adapter
+  labels:
+{{ tuple "upfadapter" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+spec:
+  replicas: 1
+  #serviceName: upfadapter-headless
+  selector:
+    matchLabels:
+{{ tuple "upfadapter" . | include "5g-control-plane.metadata_labels" | indent 6 }}
+  template:
+    metadata:
+      labels:
+{{ tuple "upfadapter" . | include "5g-control-plane.metadata_labels" | indent 8 }}
+    {{- with .Values.config.upfadapter.podAnnotations }}
+      annotations:
+        {{- toYaml . | nindent 8 }}
+    {{- end }}
+    spec:
+      serviceAccountName: upfadapter
+    {{- if hasKey .Values.images "pullSecrets" }}
+      imagePullSecrets:
+{{ toYaml .Values.images.pullSecrets | indent 8 }}
+    {{- end }}
+      containers:
+      - name: upfadapter
+        image: {{ .Values.images.tags.upfadapter }}
+        imagePullPolicy: {{ .Values.images.pullPolicy }}
+      {{- if .Values.config.coreDump.enabled }}
+        securityContext:
+          runAsUser: 0
+      {{- end }}
+        stdin: true
+        tty: true
+        command: ["/free5gc/script/upf-adapter-run.sh"]
+        env:
+        - name: POD_IP
+          valueFrom:
+            fieldRef:
+              fieldPath: status.podIP
+      {{- if .Values.resources.enabled }}
+        resources:
+{{ toYaml .Values.resources.upfadapter | indent 10 }}
+      {{- end }}
+        volumeMounts:
+        - name: run-script
+          mountPath: /free5gc/script/upf-adapter-run.sh
+          subPath: upf-adapter-run.sh
+        - name: upfadapter-config
+          mountPath: /free5gc/config
+      {{- if .Values.config.coreDump.enabled }}
+        - name: coredump
+          mountPath: /tmp/coredump
+      {{- end }}
+      volumes:
+      - name: run-script
+        configMap:
+          name: upf-adapter
+          defaultMode: 493
+      - name: upfadapter-config
+        configMap:
+          name: upf-adapter
+          defaultMode: 493
+    {{- if .Values.config.coreDump.enabled }}
+      - name: host-rootfs
+        hostPath:
+          path: /
+      - name: coredump
+        hostPath:
+          path: {{ .Values.config.coreDump.path }}
+    {{- end }}
+{{- end }}
diff --git a/5g-control-plane/templates/service-smf.yaml b/5g-control-plane/templates/service-smf.yaml
index cda2739..d37cb61 100644
--- a/5g-control-plane/templates/service-smf.yaml
+++ b/5g-control-plane/templates/service-smf.yaml
@@ -17,6 +17,7 @@
   selector:
 {{ tuple "smf" . | include "5g-control-plane.metadata_labels" | indent 4 }}
   ports:
+{{- if eq .Values.config.upfadapter.deploy false }}
   - name: pfcp
     port: {{ .Values.config.smf.n4.port }}
     protocol: UDP
@@ -25,6 +26,7 @@
     nodePort: {{ .Values.config.smf.n4.nodePort }}
 {{- end }}
 {{- end }}
+{{- end }}
   - name: prometheus-exporter
     port: {{ .Values.config.smf.prometheus.port }}
     protocol: TCP
diff --git a/5g-control-plane/templates/service-upf-adapter.yaml b/5g-control-plane/templates/service-upf-adapter.yaml
new file mode 100644
index 0000000..99235b9
--- /dev/null
+++ b/5g-control-plane/templates/service-upf-adapter.yaml
@@ -0,0 +1,31 @@
+{{/*
+# SPDX-FileCopyrightText: 2022-present Intel Corporation
+
+# SPDX-License-Identifier: Apache-2.0
+*/}}
+
+{{- if .Values.config.upfadapter.deploy }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: upf-adapter
+  labels:
+{{ tuple "upfadapter" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+spec:
+  type: {{ .Values.config.upfadapter.serviceType }}
+  selector:
+{{ tuple "upfadapter" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+  ports:
+  - name: pfcp
+    port: {{ .Values.config.upfadapter.n4.port }}
+    protocol: UDP
+{{- if eq .Values.config.upfadapter.serviceType "NodePort" }}
+{{- if .Values.config.upfadapter.n4.nodePort }}
+    nodePort: {{ .Values.config.upfadapter.n4.nodePort }}
+{{- end }}
+{{- end }}
+  - name: upfadapter-rest
+    port: {{ .Values.config.upfadapter.rest.port }}
+    protocol: TCP
+{{- end }}
diff --git a/5g-control-plane/values.yaml b/5g-control-plane/values.yaml
index e21b71f..41284b8 100644
--- a/5g-control-plane/values.yaml
+++ b/5g-control-plane/values.yaml
@@ -1,3 +1,4 @@
+# SPDX-FileCopyrightText: 2022-present Intel Corporation
 # Copyright 2020-present Open Networking Foundation
 #
 # SPDX-License-Identifier: Apache-2.0
@@ -17,6 +18,7 @@
     webui: omecproject/5gc-webui:master-fec9bfc
     sctplb: omecproject/sctplb:master-538dad6
     metricfunc: metricfunc:0.0.1-dev-local0
+    upfadapter: omecproject/5gc-smf:master-b73f587
   pullPolicy: IfNotPresent
 
 resources:
@@ -49,6 +51,13 @@
     limits:
       cpu: 2
       memory: 1Gi
+  upfadapter:
+    requests:
+      cpu: 1
+      memory: 1Gi
+    limits:
+      cpu: 1
+      memory: 1Gi
   ausf:
     requests:
       cpu: 2
@@ -394,7 +403,6 @@
       port: 38412
       #nodePort: 30071
     cfgFiles:
-      # https://github.com/free5gc/free5gc/blob/main/config/amfcfg.yaml
       sctplb.yaml:
         info:
           version: 1.0.0
@@ -434,6 +442,8 @@
           version: 1.0.0
           description: AMF initial local configuration
         configuration:
+          amfDBName: sdcore_amf
+          enableDBStore: false
           ngapIpList:
             - "0.0.0.0"
           amfName: AMF
@@ -528,6 +538,9 @@
           version: 1.0.0
           description: NRF initial local configuration
         configuration:
+          mongoDBStreamEnable: true
+          nfProfileExpiryEnable: true
+          nfKeepAliveTime: 60
           sbi:
             scheme: http
             bindingIPv4: "0.0.0.0"
@@ -564,6 +577,8 @@
           version: 1.0.0
           description: SMF initial local configuration
         configuration:
+          smfDBName: sdcore_smf
+          enableDBStore: false
           pfcp:
              addr: "POD_IP"
           smfName: SMF
@@ -675,4 +690,21 @@
             urls:
                - "sd-core-kafka-headless:9092"
             topic: "sdcore-analytics-feed"
+  upfadapter:
+    deploy: false
+    serviceType: ClusterIP
+    n4:
+      port: 8805
+      # Provide nodePort when serviceType is NodePort
+      # nodePort: 30021
+    rest:
+      port: 8090
+      #nodePort: 30080
+    cfgFiles:
+      config.yaml:
+        info:
+          version: 1.0.0
+          description: UPF Adapter initial local configuration
+        logger:
+          level: info