EDGEPOD-60 Add support of multiple UPFs

- Enable configuring multiple UPF mode
- Add support of ZMQ mode when multple UPF enabled
- Change to create three types of services for each application,
  cluster IP, headless, and external

Change-Id: Ic004a4ff7cdc5708d28ce2717677041f71b4d819
diff --git a/omec/omec-control-plane/templates/_helpers.tpl b/omec/omec-control-plane/templates/_helpers.tpl
index 53bd471..7427461 100644
--- a/omec/omec-control-plane/templates/_helpers.tpl
+++ b/omec/omec-control-plane/templates/_helpers.tpl
@@ -37,18 +37,18 @@
 {{- end -}}
 
 {{/*
-Return s6a service for Diameter identity, realm, and hostname for a given application.
+Return domain name for Diameter identity, realm, and hostname for a given application.
 */}}
 {{- define "omec-control-plane.diameter_endpoint" -}}
 {{- $service := index . 0 -}}
 {{- $type := index . 1 -}}
 {{- $context := index . 2 -}}
 {{- if eq $type "identity" -}}
-{{- printf "%s-s6a.%s.svc.%s" $service $context.Release.Namespace $context.Values.config.clusterDomain -}}
+{{- printf "%s.%s.svc.%s" $service $context.Release.Namespace $context.Values.config.clusterDomain -}}
 {{- else if eq $type "realm" -}}
 {{- printf "%s.svc.%s" $context.Release.Namespace $context.Values.config.clusterDomain -}}
 {{- else if eq $type "host" -}}
-{{- printf "%s-s6a" $service -}}
+{{- printf "%s" $service -}}
 {{- end -}}
 {{- end -}}
 
diff --git a/omec/omec-control-plane/templates/configmap-spgwc.yaml b/omec/omec-control-plane/templates/configmap-spgwc.yaml
index a331c91..4a049c2 100644
--- a/omec/omec-control-plane/templates/configmap-spgwc.yaml
+++ b/omec/omec-control-plane/templates/configmap-spgwc.yaml
@@ -37,10 +37,18 @@
     APP_ARGS="${MGMT_INFO} ${APN_INFO} ${MISC} ${SPGW_CFG}"
   interface.cfg: |
     [0]
-    dp_comm_ip = {{ .Values.config.spgwc.dpComm.addr }}
-    dp_comm_port = {{ .Values.config.spgwc.dpComm.port }}
+    zmq_protocol = tcp
     cp_comm_ip = CP_ADDR
     cp_comm_port = 21
+{{- if .Values.config.spgwc.multiUpfs }}
+    cp_nb_ip = CP_ADDR
+    cp_nb_port = 21
+    dp_comm_ip = 127.0.0.1
+    dp_comm_port = 20
+{{- else }}
+    dp_comm_ip = {{ .Values.config.spgwc.dpComm.addr }}
+    dp_comm_port = {{ .Values.config.spgwc.dpComm.port }}
+{{- end }}
   spgwc-run.sh: |
 {{ tuple "bin/_spgwc-run.sh.tpl" . | include "omec-control-plane.template" | indent 4 }}
 {{- range $key, $value := .Values.config.spgwc.cfgFiles }}
diff --git a/omec/omec-control-plane/templates/service-hss.yaml b/omec/omec-control-plane/templates/service-hss.yaml
index dbfccf5..14bfbda 100644
--- a/omec/omec-control-plane/templates/service-hss.yaml
+++ b/omec/omec-control-plane/templates/service-hss.yaml
@@ -18,19 +18,46 @@
 apiVersion: v1
 kind: Service
 metadata:
-  name: hss-s6a
+  name: hss
   labels:
 {{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 spec:
   selector:
 {{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-{{- if .Values.config.hss.s6a.nodePort.enabled }}
-  type: NodePort
-{{- end }}
   ports:
   - name: s6a
     port: 3868
     protocol: TCP
-  {{- if .Values.config.hss.s6a.nodePort.enabled }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: hss-headless
+  labels:
+{{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+spec:
+  selector:
+{{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+  clusterIP: None
+  ports:
+  - name: s6a
+    port: 3868
+    protocol: TCP
+{{- if .Values.config.hss.s6a.nodePort.enabled }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: hss-external
+  labels:
+{{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+spec:
+  selector:
+{{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+  type: NodePort
+  ports:
+  - name: s6a
+    port: 3868
+    protocol: TCP
     nodePort: {{ .Values.config.hss.s6a.nodePort.port }}
-  {{- end }}
+{{- end }}
diff --git a/omec/omec-control-plane/templates/service-mme.yaml b/omec/omec-control-plane/templates/service-mme.yaml
index b8b6a30..7012f84 100644
--- a/omec/omec-control-plane/templates/service-mme.yaml
+++ b/omec/omec-control-plane/templates/service-mme.yaml
@@ -21,54 +21,68 @@
 apiVersion: v1
 kind: Service
 metadata:
-  name: mme-s11
+  name: mme
   labels:
 {{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 spec:
   selector:
 {{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-{{- if .Values.config.mme.s11.nodePort.enabled }}
-  type: NodePort
-{{- end }}
+  type: ClusterIP
   ports:
-  - name: s11
-    port: {{ index $configJsonS11 "egtp_default_port" }}
-    protocol: UDP
+    - name: s11
+      port: {{ index $configJsonS11 "egtp_default_port" }}
+      protocol: UDP
+    - name: s6a
+      port: 3868
+      protocol: TCP
+    - name: s1ap
+      port: {{ index $configJsonS1ap "sctp_port" }}
+      protocol: SCTP
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: mme-headless
+  labels:
+{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+spec:
+  selector:
+{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+  clusterIP: None
+  ports:
+    - name: s11
+      port: {{ index $configJsonS11 "egtp_default_port" }}
+      protocol: UDP
+    - name: s6a
+      port: 3868
+      protocol: TCP
+    - name: s1ap
+      port: {{ index $configJsonS1ap "sctp_port" }}
+      protocol: SCTP
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: mme-external
+  labels:
+{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+spec:
+  selector:
+{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+  type: NodePort
+  ports:
   {{- if .Values.config.mme.s11.nodePort.enabled }}
-    nodePort: {{ .Values.config.mme.s11.nodePort.port }}
+    - name: s11
+      port: {{ index $configJsonS11 "egtp_default_port" }}
+      protocol: UDP
+      nodePort: {{ .Values.config.mme.s11.nodePort.port }}
   {{- end }}
----
-apiVersion: v1
-kind: Service
-metadata:
-  name: mme-s6a
-  labels:
-{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-{{- if .Values.config.mme.s6a.nodePort.enabled }}
-  type: NodePort
-{{- end }}
-spec:
-  selector:
-{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-  ports:
-  - name: s6a
-    port: 3868
-    protocol: TCP
   {{- if .Values.config.mme.s6a.nodePort.enabled }}
-    nodePort: {{ .Values.config.mme.s6a.nodePort.port }}
+    - name: s6a
+      port: 3868
+      protocol: TCP
+      nodePort: {{ .Values.config.mme.s6a.nodePort.port }}
   {{- end }}
----
-apiVersion: v1
-kind: Service
-metadata:
-  name: mme-s1ap
-  labels:
-{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-spec:
-  selector:
-{{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-  type: NodePort
-  ports:
     - name: s1ap
       port: {{ index $configJsonS1ap "sctp_port" }}
       nodePort: {{ index $configJsonS1ap "sctp_port_external" }}
diff --git a/omec/omec-control-plane/templates/service-spgwc.yaml b/omec/omec-control-plane/templates/service-spgwc.yaml
index b406350..fe1e68c 100644
--- a/omec/omec-control-plane/templates/service-spgwc.yaml
+++ b/omec/omec-control-plane/templates/service-spgwc.yaml
@@ -18,39 +18,69 @@
 apiVersion: v1
 kind: Service
 metadata:
-  name: spgwc-cp-comm
+  name: spgwc
   labels:
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 spec:
+  type: ClusterIP
   selector:
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-{{- if .Values.config.spgwc.cpComm.nodePort.enabled }}
-  type: NodePort
-{{- end }}
   ports:
   - name: cp-comm
-    port: 21
+    port: {{ .Values.config.spgwc.cpComm.port }}
+{{- if .Values.config.spgwc.multiUpfs }}
+    protocol: TCP
+{{- else }}
     protocol: UDP
-  {{- if .Values.config.spgwc.cpComm.nodePort.enabled }}
-    nodePort: {{ .Values.config.spgwc.cpComm.nodePort.port }}
-  {{- end }}
+{{- end }}
+  - name: s11
+    port: {{ .Values.config.spgwc.s11.port }}
+    protocol: UDP
 ---
 apiVersion: v1
 kind: Service
 metadata:
-  name: spgwc-s11
+  name: spgwc-headless
   labels:
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 spec:
+  clusterIP: None
   selector:
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
-{{- if .Values.config.spgwc.s11.nodePort.enabled }}
-  type: NodePort
-{{- end }}
   ports:
-  - name: s11
-    port: 2123
+  - name: cp-comm
+    port: {{ .Values.config.spgwc.cpComm.port }}
+{{- if .Values.config.spgwc.multiUpfs }}
+    protocol: TCP
+{{- else }}
     protocol: UDP
-  {{- if .Values.config.spgwc.s11.nodePort.enabled }}
-    nodePort: {{ .Values.config.spgwc.s11.nodePort.port }}
-  {{- end }}
+{{- end }}
+  - name: s11
+    port: {{ .Values.config.spgwc.s11.port }}
+    protocol: UDP
+{{- if not .Values.config.spgwc.multiUpfs }}
+{{- if or .Values.config.spgwc.cpComm.nodePort.enabled .Values.config.spgwc.s11.nodePort.enabled }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: spgwc-external
+  labels:
+{{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+spec:
+  type: NodePort
+  selector:
+{{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
+  ports:
+{{- if .Values.config.spgwc.cpComm.nodePort.enabled }}
+  - name: cp-comm
+    port: {{ .Values.config.spgwc.cpComm.port }}
+    protocol: TCP
+{{- end }}
+{{- if .Values.config.spgwc.s11.nodePort.enabled }}
+  - name: s11
+    port: {{ .Values.config.spgwc.s11.port }}
+    protocol: UDP
+{{- end }}
+{{- end }}
+{{- end }}
diff --git a/omec/omec-control-plane/templates/statefulset-hss.yaml b/omec/omec-control-plane/templates/statefulset-hss.yaml
index 291205e..93c8721 100644
--- a/omec/omec-control-plane/templates/statefulset-hss.yaml
+++ b/omec/omec-control-plane/templates/statefulset-hss.yaml
@@ -28,6 +28,7 @@
 {{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 spec:
   replicas: 1
+  serviceName: hss-headless
   selector:
     matchLabels:
 {{ tuple "hss" . | include "omec-control-plane.metadata_labels" | indent 6 }}
diff --git a/omec/omec-control-plane/templates/statefulset-mme.yaml b/omec/omec-control-plane/templates/statefulset-mme.yaml
index bb8b3c6..ff64007 100644
--- a/omec/omec-control-plane/templates/statefulset-mme.yaml
+++ b/omec/omec-control-plane/templates/statefulset-mme.yaml
@@ -24,6 +24,7 @@
 {{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 spec:
   replicas: 1
+  serviceName: mme-headless
   selector:
     matchLabels:
 {{ tuple "mme" . | include "omec-control-plane.metadata_labels" | indent 6 }}
diff --git a/omec/omec-control-plane/templates/statefulset-spgwc.yaml b/omec/omec-control-plane/templates/statefulset-spgwc.yaml
index 9faadca..ebc0cd0 100644
--- a/omec/omec-control-plane/templates/statefulset-spgwc.yaml
+++ b/omec/omec-control-plane/templates/statefulset-spgwc.yaml
@@ -24,6 +24,7 @@
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 4 }}
 spec:
   replicas: 1
+  serviceName: spgwc-headless
   selector:
     matchLabels:
 {{ tuple "spgwc" . | include "omec-control-plane.metadata_labels" | indent 6 }}