COMAC-255 Improve ONOS chart for better support of various ONOS apps

- Add release name to configmap to allow multiple deployments
- Add ability to support additional Services

Change-Id: I16f45dbd6129aa1cc3e1fbf41bfd8de27b565bd2
diff --git a/onos/Chart.yaml b/onos/Chart.yaml
index f1c3bc4..d647b55 100644
--- a/onos/Chart.yaml
+++ b/onos/Chart.yaml
@@ -15,6 +15,6 @@
 
 name: onos
 description: Open Network Operating System
-version: 1.1.2
+version: 1.1.3
 icon: https://guide.opencord.org/logos/onos.svg
 appVersion: 1.13.9
diff --git a/onos/templates/_helpers.tpl b/onos/templates/_helpers.tpl
index 1dab05a..6d82564 100644
--- a/onos/templates/_helpers.tpl
+++ b/onos/templates/_helpers.tpl
@@ -106,5 +106,37 @@
 
 # Application logs
 {{ .Values.application_logs }}
+{{- end -}}
 
+{{/*
+Render a Service.
+*/}}
+{{- define "onos.service" -}}
+{{- $name := index . 0 -}}
+{{- $spec := index . 1 -}}
+{{- $context := index . 2 -}}
+{{- $namespace := $context.Release.Namespace }}
+{{- $serviceName := printf "%s-%s" (include "onos.fullname" $context) $name }}
+---
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ $serviceName }}
+  namespace: {{ $namespace }}
+  labels:
+    app: {{ template "onos.name" $context }}
+    chart: {{ template "onos.chart" $context }}
+    release: {{ $context.Release.Name }}
+    heritage: {{ $context.Release.Service }}
+spec:
+  type: {{ $spec.type }}
+  ports:
+  - name: {{ $name }}
+    port: {{ $spec.port }}
+{{- if and $spec.type (eq (printf "%s" $spec.type) "NodePort") }}
+    nodePort: {{ $spec.nodePort }}
+{{- end }}
+  selector:
+    app: {{ template "onos.name" $context }}
+    release: {{ $context.Release.Name }}
 {{- end -}}
diff --git a/onos/templates/configmap.yaml b/onos/templates/configmap.yaml
index 0aaec49..4193c64 100644
--- a/onos/templates/configmap.yaml
+++ b/onos/templates/configmap.yaml
@@ -16,7 +16,7 @@
 apiVersion: v1
 kind: ConfigMap
 metadata:
-  name: onos
+  name: {{ template "onos.fullname" . }}-onos
 data:
   logCfg: |
-{{ include "onos.logCfg" . | indent 4 }}
\ No newline at end of file
+{{ include "onos.logCfg" . | indent 4 }}
diff --git a/onos/templates/debugger-service.yaml b/onos/templates/debugger-service.yaml
deleted file mode 100644
index 79f266b..0000000
--- a/onos/templates/debugger-service.yaml
+++ /dev/null
@@ -1,32 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-apiVersion: v1
-kind: Service
-metadata:
-  name: {{ template "onos.fullname" . }}-debugger
-  namespace: {{ .Values.namespace }}
-  labels:
-    app: {{ template "onos.name" . }}
-    chart: {{ template "onos.chart" . }}
-    release: {{ .Release.Name }}
-    heritage: {{ .Release.Service }}
-spec:
-  type: {{ .Values.services.debuggerServiceType }}
-  ports:
-  - name: debugger
-{{ toYaml .Values.services.debugger | indent 4 }}
-  selector:
-    app: {{ template "onos.name" . }}
-    release: {{ .Release.Name }}
diff --git a/onos/templates/deployment.yaml b/onos/templates/deployment.yaml
index f463c1d..499a821 100644
--- a/onos/templates/deployment.yaml
+++ b/onos/templates/deployment.yaml
@@ -50,19 +50,6 @@
           command: ["./bin/onos-service", "server", "debug"]
           env:
 {{ toYaml .Values.onos_env | indent 12 }}
-          ports:
-            - name: ovsdb
-              containerPort: {{ .Values.services.ovsdb.port }}
-            - name: openflow
-              containerPort: {{ .Values.services.openflow.port }}
-            - name: ssh
-              containerPort: {{ .Values.services.ssh.port }}
-            - name: ui
-              containerPort: {{ .Values.services.ui.port }}
-            - name: cluster
-              containerPort: {{ .Values.services.cluster.port }}
-            - name: debugger
-              containerPort: {{ .Values.services.debugger.port }}
           resources:
 {{ toYaml .Values.resources | indent 12 }}
           volumeMounts:
@@ -102,7 +89,7 @@
             optional: true
         - name: onos-logs-cfg
           configMap:
-            name: onos
+            name: {{ template "onos.fullname" . }}-onos
             items:
               - key: logCfg
                 path: org.ops4j.pax.logging.cfg
@@ -111,7 +98,7 @@
 {{- if .Values.log_agent.enabled }}
         - name: log-agent-configmap-volume
           configMap:
-            name: log-agent-configmap
+            name: {{ template "onos.fullname" . }}-log-agent-configmap
             items:
               - key: config
                 path: filebeat.yml
diff --git a/onos/templates/log-agent-configmap.yaml b/onos/templates/log-agent-configmap.yaml
index 44e2763..945e146 100644
--- a/onos/templates/log-agent-configmap.yaml
+++ b/onos/templates/log-agent-configmap.yaml
@@ -18,7 +18,7 @@
 kind: ConfigMap
 apiVersion: v1
 metadata:
-  name: log-agent-configmap
+  name: {{ template "onos.fullname" . }}-log-agent-configmap
 data:
   config: |
     ---
diff --git a/onos/templates/openflow-service.yaml b/onos/templates/openflow-service.yaml
deleted file mode 100644
index 05fadeb..0000000
--- a/onos/templates/openflow-service.yaml
+++ /dev/null
@@ -1,32 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-apiVersion: v1
-kind: Service
-metadata:
-  name: {{ template "onos.fullname" . }}-openflow
-  namespace: {{ .Values.namespace }}
-  labels:
-    app: {{ template "onos.name" . }}
-    chart: {{ template "onos.chart" . }}
-    release: {{ .Release.Name }}
-    heritage: {{ .Release.Service }}
-spec:
-  type: {{ .Values.services.openflowServiceType }}
-  ports:
-  - name: openflow
-{{ toYaml .Values.services.openflow | indent 4 }}
-  selector:
-    app: {{ template "onos.name" . }}
-    release: {{ .Release.Name }}
diff --git a/onos/templates/ovsdb-service.yaml b/onos/templates/ovsdb-service.yaml
deleted file mode 100644
index f0760fe..0000000
--- a/onos/templates/ovsdb-service.yaml
+++ /dev/null
@@ -1,32 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-apiVersion: v1
-kind: Service
-metadata:
-  name: {{ template "onos.fullname" . }}-ovsdb
-  namespace: {{ .Values.namespace }}
-  labels:
-    app: {{ template "onos.name" . }}
-    chart: {{ template "onos.chart" . }}
-    release: {{ .Release.Name }}
-    heritage: {{ .Release.Service }}
-spec:
-  type: {{ .Values.services.ovsdbServiceType }}
-  ports:
-  - name: ovsdb
-{{ toYaml .Values.services.ovsdb | indent 4 }}
-  selector:
-    app: {{ template "onos.name" . }}
-    release: {{ .Release.Name }}
diff --git a/onos/templates/service.yaml b/onos/templates/service.yaml
new file mode 100644
index 0000000..322a981
--- /dev/null
+++ b/onos/templates/service.yaml
@@ -0,0 +1,17 @@
+# Copyright 2019-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+{{- range $key, $value := .Values.services }}
+  {{ tuple $key $value $ | include "onos.service" }}
+{{- end }}
diff --git a/onos/templates/ssh-service.yaml b/onos/templates/ssh-service.yaml
deleted file mode 100644
index bf0b8a0..0000000
--- a/onos/templates/ssh-service.yaml
+++ /dev/null
@@ -1,32 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-apiVersion: v1
-kind: Service
-metadata:
-  name: {{ template "onos.fullname" . }}-ssh
-  namespace: {{ .Values.namespace }}
-  labels:
-    app: {{ template "onos.name" . }}
-    chart: {{ template "onos.chart" . }}
-    release: {{ .Release.Name }}
-    heritage: {{ .Release.Service }}
-spec:
-  type: {{ .Values.services.sshServiceType }}
-  ports:
-  - name: ssh
-{{ toYaml .Values.services.ssh | indent 4 }}
-  selector:
-    app: {{ template "onos.name" . }}
-    release: {{ .Release.Name }}
diff --git a/onos/templates/ui-service.yaml b/onos/templates/ui-service.yaml
deleted file mode 100644
index 4c05f4d..0000000
--- a/onos/templates/ui-service.yaml
+++ /dev/null
@@ -1,32 +0,0 @@
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-apiVersion: v1
-kind: Service
-metadata:
-  name: {{ template "onos.fullname" . }}-ui
-  namespace: {{ .Values.namespace }}
-  labels:
-    app: {{ template "onos.name" . }}
-    chart: {{ template "onos.chart" . }}
-    release: {{ .Release.Name }}
-    heritage: {{ .Release.Service }}
-spec:
-  type: {{ .Values.services.uiServiceType }}
-  ports:
-  - name: ui
-{{ toYaml .Values.services.ui | indent 4 }}
-  selector:
-    app: {{ template "onos.name" . }}
-    release: {{ .Release.Name }}
diff --git a/onos/values.yaml b/onos/values.yaml
index 9ab6274..57fb42f 100644
--- a/onos/values.yaml
+++ b/onos/values.yaml
@@ -47,32 +47,30 @@
 serviceAccountName: default
 
 services:
-  openflowServiceType: NodePort
   openflow:
+    type: NodePort
     port: 6653
     nodePort: 31653
-
-  sshServiceType: NodePort
   ssh:
+    type: NodePort
     port: 8101
     nodePort: 30115
-
-  uiServiceType: NodePort
   ui:
+    type: NodePort
     port: 8181
     nodePort: 30120
-
-  debuggerServiceType: NodePort
   debugger:
+    type: NodePort
     port: 5005
     nodePort: 30555
-
-  ovsdbServiceType: ClusterIP
   ovsdb:
+    type: ClusterIP
     port: 6640
-
-  cluster:
-    port: 9876
+  # Add application specific ports
+  #progran:
+  #  type: NodePort
+  #  port: 4010
+  #  nodePort: 30410
 
 onos_env:
 - name: POD_IP