Changes to support SCTP LB pod

Change-Id: I46e2f6da984edc57235fc6c151bc4886190d921d
diff --git a/5g-control-plane/Chart.yaml b/5g-control-plane/Chart.yaml
index 4ea73b1..9c803cc 100644
--- a/5g-control-plane/Chart.yaml
+++ b/5g-control-plane/Chart.yaml
@@ -8,7 +8,7 @@
 name: 5g-control-plane
 icon: https://guide.opencord.org/logos/cord.svg
 
-version: 0.7.0
+version: 0.7.1
 
 dependencies:
   - name: mongodb
diff --git a/5g-control-plane/templates/bin/_sctplb-run.sh.tpl b/5g-control-plane/templates/bin/_sctplb-run.sh.tpl
new file mode 100644
index 0000000..e1b07f4
--- /dev/null
+++ b/5g-control-plane/templates/bin/_sctplb-run.sh.tpl
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+# Copyright 2021-present Open Networking Foundation
+#
+# SPDX-License-Identifier: Apache-2.0
+
+set -xe
+
+{{- if .Values.config.coreDump.enabled }}
+cp /sdcore/bin/sctplb /tmp/coredump/
+{{- end }}
+
+cd /sdcore
+
+cat config/sctplb.yaml
+
+GOTRACEBACK=crash ./bin/sctplb config/sctplb.yaml
diff --git a/5g-control-plane/templates/configmap-amf.yaml b/5g-control-plane/templates/configmap-amf.yaml
index f35bb56..10ecaed 100644
--- a/5g-control-plane/templates/configmap-amf.yaml
+++ b/5g-control-plane/templates/configmap-amf.yaml
@@ -14,10 +14,23 @@
 {{- $_ := .Values.config.amf.sbi.port | set $sbi "port" -}}
 {{- end }}
 
+{{- if not (hasKey $amfcfg.configuration "ngappPort") -}}
+{{- $_ := .Values.config.amf.ngapp.port | set $amfcfg.configuration "ngappPort" -}}
+{{- end }}
+
+{{- if not (hasKey $amfcfg.configuration "sctpGrpcPort") -}}
+{{- $_ := .Values.config.amf.sctp_grpc.port | set $amfcfg.configuration "sctpGrpcPort" -}}
+{{- end }}
+
 {{- if not (hasKey $amfcfg "logger") -}}
 {{- $_ := .Values.config.logger | set $amfcfg "logger" -}}
 {{- end }}
 
+{{- if not (hasKey $amfcfg.configuration "enableSctpLb") -}}
+{{- $_ := .Values.config.sctplb.deploy | set $amfcfg.configuration "enableSctpLb" -}}
+{{- end }}
+
+
 {{- end }}
 
 
diff --git a/5g-control-plane/templates/configmap-sctplb.yaml b/5g-control-plane/templates/configmap-sctplb.yaml
new file mode 100644
index 0000000..be96dfa
--- /dev/null
+++ b/5g-control-plane/templates/configmap-sctplb.yaml
@@ -0,0 +1,38 @@
+{{/*
+# Copyright 2020-present Open Networking Foundation
+
+# SPDX-License-Identifier: Apache-2.0
+*/}}
+
+{{- if .Values.config.sctplb.deploy }}
+
+{{- if not .Values.config.useExistingConfigMap -}}
+{{- $sctplbcfg := index .Values.config.sctplb.cfgFiles "sctplb.yaml" }}
+
+{{- if not (hasKey $sctplbcfg.configuration "ngappPort") -}}
+{{- $_ := .Values.config.sctplb.ngapp.port | set $sctplbcfg.configuration "ngappPort" -}}
+{{- end }}
+
+{{- if not (hasKey $sctplbcfg.configuration "sctpGrpcPort") -}}
+{{- $_ := .Values.config.sctplb.sctp_grpc.port | set $sctplbcfg.configuration "sctpGrpcPort" -}}
+{{- end }}
+
+{{- end }}
+
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: sctplb
+  labels:
+{{ tuple "sctplb" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+data:
+  sctplb-run.sh: |
+{{ tuple "bin/_sctplb-run.sh.tpl" . | include "5g-control-plane.template" | indent 4 }}
+{{- if not .Values.config.useExistingConfigMap -}}
+{{- range $key, $value := .Values.config.sctplb.cfgFiles }}
+  {{ $key }}: |-
+{{ toYaml $value | indent 4 }}
+{{- end }}
+{{- end }}
+{{- end }}
diff --git a/5g-control-plane/templates/deployment-sctplb.yaml b/5g-control-plane/templates/deployment-sctplb.yaml
new file mode 100644
index 0000000..74aeb36
--- /dev/null
+++ b/5g-control-plane/templates/deployment-sctplb.yaml
@@ -0,0 +1,103 @@
+{{/*
+# Copyright 2020-present Open Networking Foundation
+
+# SPDX-License-Identifier: Apache-2.0
+*/}}
+
+{{- if .Values.config.sctplb.deploy }}
+{{ tuple "sctplb" . | include "5g-control-plane.service_account" }}
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: sctplb
+  labels:
+{{ tuple "sctplb" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+spec:
+  replicas: 1
+  #serviceName: sctplb-headless
+  selector:
+    matchLabels:
+{{ tuple "sctplb" . | include "5g-control-plane.metadata_labels" | indent 6 }}
+  template:
+    metadata:
+      labels:
+{{ tuple "sctplb" . | include "5g-control-plane.metadata_labels" | indent 8 }}
+    {{- with .Values.config.sctplb.podAnnotations }}
+      annotations:
+        {{- toYaml . | nindent 8 }}
+    {{- end }}
+    spec:
+      serviceAccountName: sctplb
+    {{- if hasKey .Values.images "pullSecrets" }}
+      imagePullSecrets:
+{{ toYaml .Values.images.pullSecrets | indent 8 }}
+    {{- end }}
+      initContainers:
+      - name: wait-nrf-module
+        image: {{ .Values.images.tags.init | quote }}
+        imagePullPolicy: {{ .Values.images.pullPolicy }}
+        command: ['sh', '-c', 'until nslookup nrf; do echo waiting for nrf; sleep 4; done;']
+    {{- if .Values.config.coreDump.enabled }}
+{{ tuple "sctplb" . | include "5g-control-plane.coredump_init" | indent 6 }}
+    {{- end }}
+      containers:
+      - name: sctplb
+        image: {{ .Values.images.tags.sctplb }}
+        imagePullPolicy: {{ .Values.images.pullPolicy }}
+      {{- if .Values.config.coreDump.enabled }}
+        securityContext:
+          runAsUser: 0
+      {{- end }}
+        stdin: true
+        tty: true
+        command: ["/sdcore/script/sctplb-run.sh"]
+        env:
+        - name: GRPC_GO_LOG_VERBOSITY_LEVEL
+          value: {{ .Values.config.grpc.golog_verbosity | quote }}
+        - name: GRPC_GO_LOG_SEVERITY_LEVEL
+          value: {{ .Values.config.grpc.severity | quote }}
+        - name: GRPC_TRACE
+          value: {{ .Values.config.grpc.trace | quote }}
+        - name: GRPC_VERBOSITY
+          value: {{ .Values.config.grpc.verbosity | quote }}
+        - name: POD_IP
+          valueFrom:
+            fieldRef:
+              fieldPath: status.podIP
+      {{- if .Values.config.managedByConfigPod.enabled }}
+        - name: MANAGED_BY_CONFIG_POD 
+          value: "true"
+      {{- end }}
+      {{- if .Values.resources.enabled }}
+        resources:
+{{ toYaml .Values.resources.sctplb | indent 10 }}
+      {{- end }}
+        volumeMounts:
+        - name: run-script
+          mountPath: /sdcore/script/sctplb-run.sh
+          subPath: sctplb-run.sh
+        - name: sctplb-config
+          mountPath: /sdcore/config
+      {{- if .Values.config.coreDump.enabled }}
+        - name: coredump
+          mountPath: /tmp/coredump
+      {{- end }}
+      volumes:
+      - name: run-script
+        configMap:
+          name: sctplb
+          defaultMode: 493
+      - name: sctplb-config
+        configMap:
+          name: sctplb
+          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-amf.yaml b/5g-control-plane/templates/service-amf.yaml
index 1cac3be..5df3447 100644
--- a/5g-control-plane/templates/service-amf.yaml
+++ b/5g-control-plane/templates/service-amf.yaml
@@ -45,4 +45,27 @@
     nodePort: {{ .Values.config.amf.ngapp.nodePort }}
 {{- end }}
 {{- end }}
+  - name: sctp-grpc
+    port: {{ .Values.config.amf.sctp_grpc.port }}
+    protocol: TCP
+{{- if eq .Values.config.amf.serviceType "NodePort" }}
+{{- if .Values.config.amf.sctp_grpc.nodePort }}
+    nodePort: {{ .Values.config.amf.sctp_grpc.nodePort }}
+{{- end }}
+{{- end }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: amf-headless
+  labels:
+{{ tuple "amf" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+spec:
+  selector:
+{{ tuple "amf" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+  clusterIP: None
+  ports:
+  - name: grpc
+    port: 9000
+    protocol: TCP
 {{- end }}
diff --git a/5g-control-plane/templates/service-sctplb.yaml b/5g-control-plane/templates/service-sctplb.yaml
new file mode 100644
index 0000000..8dea0e0
--- /dev/null
+++ b/5g-control-plane/templates/service-sctplb.yaml
@@ -0,0 +1,32 @@
+{{/*
+# Copyright 2020-present Open Networking Foundation
+
+# SPDX-License-Identifier: Apache-2.0
+*/}}
+
+{{- if .Values.config.sctplb.deploy }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: sctplb
+  labels:
+{{ tuple "sctplb" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+spec:
+  type: {{ .Values.config.sctplb.serviceType }}
+{{- if .Values.config.sctplb.ngapp.externalIp }}
+  externalIPs:
+    - {{ .Values.config.sctplb.ngapp.externalIp }}
+{{- end }}
+  selector:
+{{ tuple "sctplb" . | include "5g-control-plane.metadata_labels" | indent 4 }}
+  ports:
+  - name: ngapp
+    port: {{ .Values.config.sctplb.ngapp.port }}
+    protocol: SCTP
+{{- if eq .Values.config.sctplb.serviceType "NodePort" }}
+{{- if .Values.config.sctplb.ngapp.nodePort }}
+    nodePort: {{ .Values.config.sctplb.ngapp.nodePort }}
+{{- end }}
+{{- end }}
+{{- end }}
diff --git a/5g-control-plane/values.yaml b/5g-control-plane/values.yaml
index 7c85a8d..49e9200 100644
--- a/5g-control-plane/values.yaml
+++ b/5g-control-plane/values.yaml
@@ -15,10 +15,18 @@
     udr: omecproject/5gc-udr:master-3756e35
     udm: omecproject/5gc-udm:master-15369ab
     webui: omecproject/5gc-webui:master-727636a
+    sctplb: sctplb:0.0.1-dev-local1
   pullPolicy: IfNotPresent
 
 resources:
   enabled: false
+  sctplb:
+    requests:
+      cpu: 2
+      memory: 1Gi
+    limits:
+      cpu: 2
+      memory: 1Gi
   amf:
     requests:
       cpu: 2
@@ -357,6 +365,33 @@
               nsiInformationList:
                 - nrfId: http://nrf:29510/nnrf-nfm/v1/nf-instances
                   nsiId: 22
+  sctplb:
+    deploy: false
+    podAnnotations:
+      field.cattle.io/workloadMetrics: '[{"path":"/metrics","port":9089,"schema":"HTTP"}]'
+    serviceType: ClusterIP
+    sctp_grpc:
+      port: 9000
+      #nodePort: 30088
+    ngapp:
+      #externalIp:
+      port: 38412
+      #nodePort: 30071
+    cfgFiles:
+      # https://github.com/free5gc/free5gc/blob/main/config/amfcfg.yaml
+      sctplb.yaml:
+        info:
+          version: 1.0.0
+          description: SCTPLB initial local configuration
+        logger:
+          sctpLogs: info
+          dispatcherLogs: info
+          clientdiscLogs: info
+        configuration:
+          serviceNames:
+          - "amf-headless"
+          ngapIpList:
+            - "0.0.0.0"
   amf:
     deploy: true
     podAnnotations:
@@ -366,6 +401,9 @@
       port: 9089
       # Provide nodePort when serviceType is NodePort
       #nodePort: 30084
+    sctp_grpc:
+      port: 9000
+      #nodePort: 30088
     sbi:
       port: 29518
       #nodePort: 30088