apiVersion: apps/v1
 kind: Deployment
-metadata:
-  name: {{ include "common.fullname" . }}
-  namespace: {{ include "common.namespace" . }}
-  labels:
-    app: {{ include "common.name" . }}
-    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
-    release: {{ include "common.release" . }}
-    heritage: {{ .Release.Service }}
+metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
 spec:
-  selector:
-    matchLabels:
-      app: {{ include "common.name" . }}
+  selector: {{- include "common.selectors" . | nindent 4 }}
   replicas: {{ .Values.replicaCount }}
   strategy:
     type: {{ .Values.updateStrategy.type }}
       maxSurge: {{ .Values.updateStrategy.maxSurge }}
     {{- end }}
   template:
-    metadata:
-      labels:
-        app: {{ include "common.name" . }}
-        release: {{ include "common.release" . }}
+    metadata: {{- include "common.templateMetadata" . | nindent 6 }}
     spec:
-      initContainers:
       containers:
         - name: {{ include "common.name" . }}
           image: {{ include "repositoryGenerator.repository" . }}/{{ .Values.image }}
           imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
-          ports:
-          - containerPort: {{ .Values.service.internalPort }}
+          ports: {{ include "common.containerPorts" . | nindent 12  }}
           # disable liveness probe when breakpoints set in debugger
           # so K8s doesn't restart unresponsive container
           {{ if .Values.liveness.enabled }}
 
 # limitations under the License.
 */}}
 
-apiVersion: v1
-kind: Service
-metadata:
-  name: {{ include "common.servicename" . }}
-  namespace: {{ include "common.namespace" . }}
-  labels:
-    app: {{ include "common.name" . }}
-    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
-    release: {{ include "common.release" . }}
-    heritage: {{ .Release.Service }}
-spec:
-  type: {{ .Values.service.type }}
-  ports:
-    {{- if eq .Values.service.type "NodePort" }}
-    - port: {{ .Values.service.internalPort }}
-      nodePort: {{ .Values.global.nodePortPrefix | default .Values.nodePortPrefix }}{{ .Values.service.nodePort }}
-      name: {{ .Values.service.portName }}{{ (eq "true" (include "common.needTLS" .)) | ternary "s" "" }}
-    {{- else }}
-    - port: {{ .Values.service.externalPort }}
-      targetPort: {{ .Values.service.internalPort }}
-      name: {{ .Values.service.portName }}{{ (eq "true" (include "common.needTLS" .)) | ternary "s" "" }}
-    {{- end }}
-
-  selector:
-    app: {{ include "common.name" . }}
-    release: {{ include "common.release" . }}
+{{ include "common.service" . }}
 
 
 service:
   type: NodePort
-  portName: http
-  externalPort: 9516
   internalPort: 9516
-  nodePort: 79
+  ports:
+  - name: http
+    port: 9516
+    nodePort: 79
 
 ingress:
   enabled: false
 
   {{if eq .Values.service.type "NodePort" -}}
   - port: {{ .Values.service.internalPort }}
     nodePort: {{ .Values.global.nodePortPrefix | default .Values.nodePortPrefix }}{{ .Values.service.nodePort }}
-    name: {{ .Values.service.portName }}{{ (eq "true" (include "common.needTLS" .)) | ternary "s" "" }}
+    name: {{ .Values.service.portName }}
   - port: {{ .Values.service.internalPort2 }}
     nodePort: {{ .Values.global.nodePortPrefix | default .Values.nodePortPrefix }}{{ .Values.service.nodePort2 }}
     name: {{ .Values.service.portName2 }}
     name: {{ .Values.service.portName3 }}
   {{- else -}}
   - port: {{ .Values.service.internalPort }}
-    name: {{ .Values.service.portName }}{{ (eq "true" (include "common.needTLS" .)) | ternary "s" "" }}
+    name: {{ .Values.service.portName }}
   - port: {{ .Values.service.internalPort2 }}
     name: {{ .Values.service.portName2 }}
   - port: {{ .Values.service.internalPort3 }}
 
     migration:
       enabled: false
 
-  aafEnabled: false
-
   config:
     # Specifies that the cluster connected to a dynamic
     # cluster being spinned up by kubernetes deployment
 
 
 apiVersion: apps/v1
 kind: Deployment
-metadata:
-  name: {{ include "common.fullname" . }}
-  namespace: {{ include "common.namespace" . }}
-  labels:
-    app: {{ include "common.name" . }}
-    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
-    release: {{ include "common.release" . }}
-    heritage: {{ .Release.Service }}
+metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
 spec:
+  selector: {{- include "common.selectors" . | nindent 4 }}
   replicas: {{ .Values.replicaCount }}
   strategy:
     type: {{ .Values.updateStrategy.type }}
       maxUnavailable: {{ .Values.updateStrategy.maxUnavailable }}
       maxSurge: {{ .Values.updateStrategy.maxSurge }}
     {{- end }}
-  selector:
-    matchLabels:
-      app: {{ include "common.name" . }}
   template:
-    metadata:
-      annotations:
-        sidecar.istio.io/rewriteAppHTTPProbers: "false"
-      labels:
-        app: {{ include "common.name" . }}
-        release: {{ include "common.release" . }}
-      name: {{ include "common.name" . }}
+    metadata: {{- include "common.templateMetadata" . | nindent 6 }}
     spec:
       initContainers:
       - command:
         - mountPath:  /opt/app/sparky/config/logging/logback.xml
           name: config
           subPath: logback.xml
-        ports:
-        - containerPort: {{ .Values.service.internalPort }}
-        - containerPort: {{ .Values.service.internalPlainPort }}
+        ports: {{ include "common.containerPorts" . | nindent 10  }}
         # disable liveness probe when breakpoints set in debugger
         # so K8s doesn't restart unresponsive container
         {{- if eq .Values.liveness.enabled true }}
         livenessProbe:
           tcpSocket:
-            port: {{ .Values.service.internalPlainPort }}
+            port: {{ .Values.service.internalPort }}
           initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
           periodSeconds: {{ .Values.liveness.periodSeconds }}
         {{ end -}}
         readinessProbe:
           tcpSocket:
-            port: {{ .Values.service.internalPlainPort }}
+            port: {{ .Values.service.internalPort }}
           initialDelaySeconds: {{ .Values.readiness.initialDelaySeconds }}
           periodSeconds: {{ .Values.readiness.periodSeconds }}
         resources: {{ include "common.resources" . | nindent 10 }}
 
 # limitations under the License.
 */}}
 
-apiVersion: v1
-kind: Service
-metadata:
-  name: {{ include "common.servicename" . }}
-  namespace: {{ include "common.namespace" . }}
-  labels:
-    app: {{ include "common.name" . }}
-    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
-    release: {{ include "common.release" . }}
-    heritage: {{ .Release.Service }}
-spec:
-  ports:
-  - name: {{ .Values.service.portName }}{{ if (include "common.needTLS" .) }}s{{ end }}
-    port: {{ .Values.service.externalPort }}
-    targetPort: {{ (eq "true" (include "common.needTLS" .)) | ternary .Values.service.internalPort .Values.service.internalPlainPort }}
-    {{- if eq .Values.service.type "NodePort" }}
-    nodePort: {{ .Values.global.nodePortPrefix | default .Values.nodePortPrefix }}{{ .Values.service.nodePort }}
-    {{- end }}
-  type: {{ .Values.service.type }}
-  selector:
-    app: {{ include "common.name" . }}
+{{ include "common.service" . }}
 
   portalOnapEnabled: true
 #
 
-# override chart name (sparky-be) to share a common namespace
-# suffix with parent chart (aai)
-nsSuffix: aai
-
-
 # default number of instances
 replicaCount: 1
 
 
 service:
   type: NodePort
-  portName: http
-  externalPort: 8000
-  internalPort: 8000
-  internalPlainPort: 9517
-  nodePort: 20
+  internalPort: 9517
+  ports:
+  - name: http
+    port: 8000
+    internal_port: 9517
+    nodePort: 20
 
 ingress:
   enabled: false
   config:
     ssl: "redirect"
 
+podAnnotations:
+  sidecar.istio.io/rewriteAppHTTPProbers: "false"
+
 # Configure resource requests and limits
 # ref: http://kubernetes.io/docs/user-guide/compute-resources/
 resources:
 
 # Declare variables to be passed into your templates.
 global: # global defaults
   nodePortPrefix: 302
-  aafEnabled: false
 
   cassandra:
     #Service Name of the cassandra cluster to connect to.
 
           name: haproxy-cfg
         ports:
         - containerPort: {{ .Values.service.internalPort }}
-        - containerPort: {{ .Values.service.internalPlainPort }}
         - containerPort: {{ .Values.metricsService.internalPort }}
         # disable liveness probe when breakpoints set in debugger
         # so K8s doesn't restart unresponsive container
         {{- if eq .Values.liveness.enabled true }}
         livenessProbe:
           tcpSocket:
-            port: {{ .Values.service.internalPlainPort }}
+            port: {{ .Values.service.internalPort }}
           initialDelaySeconds: {{ .Values.liveness.initialDelaySeconds }}
           periodSeconds: {{ .Values.liveness.periodSeconds }}
         {{ end -}}
         readinessProbe:
           httpGet:
             path: /aai/util/echo
-            port: {{ .Values.service.internalPlainPort }}
+            port: {{ .Values.service.internalPort }}
             scheme: HTTP
             httpHeaders:
             - name: X-FromAppId
 
     heritage: {{ .Release.Service }}
 spec:
   ports:
-  - name: {{ .Values.service.portName }}{{ if (include "common.needTLS" .) }}s{{ end }}
-    port: {{ (eq "true" (include "common.needTLS" .)) | ternary .Values.service.externalPort .Values.service.externalPlainPort }}
-    targetPort: {{ (eq "true" (include "common.needTLS" .)) | ternary .Values.service.internalPort .Values.service.internalPlainPort }}
+  - name: {{ .Values.service.portName }}
+    port: {{ .Values.service.externalPort }}
+    targetPort: {{ .Values.service.internalPort }}
     {{- if eq .Values.service.type "NodePort" }}
+    {{    if not (include "common.ingressEnabled" .) }}
     nodePort: {{ .Values.global.nodePortPrefix | default .Values.nodePortPrefix }}{{ .Values.service.nodePort }}
+    {{    end }}
     {{- end }}
-  type: {{ .Values.service.type }}
+  type: {{ if (include "common.ingressEnabled" .) }}ClusterIP{{ else }}{{ .Values.service.type }}{{ end }}
   selector:
     app: {{ include "common.name" . }}
-  clusterIP: {{ .Values.service.aaiServiceClusterIp }}
   sessionAffinity: {{ .Values.service.sessionAffinity }}
 ---
 apiVersion: v1
 spec:
   ports:
     - name: {{ .Values.service.portName }}
-      port: {{ .Values.service.externalPlainPort }}
-      targetPort: {{ .Values.service.internalPlainPort }}
+      port: {{ .Values.service.externalPort }}
+      targetPort: {{ .Values.service.internalPort }}
   type: ClusterIP
   selector:
     app: {{ include "common.name" . }}
 
 
   restartPolicy: Always
 
-  aafEnabled: false
   msbEnabled: false
   centralizedLoggingEnabled: false
 
 service:
   type: NodePort
   portName: http
-  externalPort: 8443
-  internalPort: 8443
+  externalPort: 80
+  internalPort: 8080
   nodePort: 33
-  externalPlainPort: 80
-  internalPlainPort: 8080
-  nodeport: 33
-  aaiServiceClusterIp:
   sessionAffinity: None
 
 metricsService:
   service:
     - baseaddr: "aai-api"
       name: "aai"
-      port: 8443
-      plain_port: 80
+      port: 80
       config:
        ssl: "redirect"