Add ability to configure whether to deploy kpi-exporter

Also, add release name as a prefix to kpi-exporter resource names to
in line with other resources created by nem-monitoring.

Change-Id: I2b15f97128795e19d56a1be2a9290e8775f389e2
diff --git a/nem-monitoring/templates/_helpers.tpl b/nem-monitoring/templates/_helpers.tpl
index 9b0b99b..1237811 100644
--- a/nem-monitoring/templates/_helpers.tpl
+++ b/nem-monitoring/templates/_helpers.tpl
@@ -32,3 +32,20 @@
   port: 8080
   description: http target for prometheus
 {{- end -}}
+
+{{/*
+Create a default fully qualified kpi-exporter name.
+We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
+*/}}
+{{- define "kpi-exporter.fullname" -}}
+{{- if .Values.kpi_exporter.fullnameOverride -}}
+{{- .Values.kpi_exporter.fullnameOverride | trunc 63 | trimSuffix "-" -}}
+{{- else -}}
+{{- $name := default "nem-kpi-exporter" .Values.kpi_exporter.nameOverride -}}
+{{- if contains $name .Release.Name -}}
+{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
+{{- else -}}
+{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
+{{- end -}}
+{{- end -}}
+{{- end -}}
diff --git a/nem-monitoring/templates/exporter-configmap.yaml b/nem-monitoring/templates/exporter-configmap.yaml
index 69d2ae3..6107f7e 100644
--- a/nem-monitoring/templates/exporter-configmap.yaml
+++ b/nem-monitoring/templates/exporter-configmap.yaml
@@ -1,7 +1,9 @@
+{{- if .Values.kpi_exporter.enabled }}
 apiVersion: v1
 kind: ConfigMap
 metadata:
-  name: exporter-configmap
+  name: {{ template "kpi-exporter.fullname" . }}
 data:
   conf.yaml: |
 {{ include "exporter.config" . | indent 4 }}
+{{- end }}
diff --git a/nem-monitoring/templates/exporter-deployment.yaml b/nem-monitoring/templates/exporter-deployment.yaml
index 1611239..f49029f 100644
--- a/nem-monitoring/templates/exporter-deployment.yaml
+++ b/nem-monitoring/templates/exporter-deployment.yaml
@@ -13,10 +13,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+{{- if .Values.kpi_exporter.enabled }}
 apiVersion: extensions/v1beta1
 kind: Deployment
 metadata:
-  name: kpi-exporter
+  name: {{ template "kpi-exporter.fullname" . }}
   labels:
     release: {{ .Release.Name }}
 spec:
@@ -43,4 +44,5 @@
       volumes:
         - name: exporter-config
           configMap:
-            name: exporter-configmap
+            name: {{ template "kpi-exporter.fullname" . }}
+{{- end }}
diff --git a/nem-monitoring/templates/exporter-service.yaml b/nem-monitoring/templates/exporter-service.yaml
index f29a913..72434ef 100644
--- a/nem-monitoring/templates/exporter-service.yaml
+++ b/nem-monitoring/templates/exporter-service.yaml
@@ -13,10 +13,11 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+{{- if .Values.kpi_exporter.enabled }}
 apiVersion: v1
 kind: Service
 metadata:
-  name: kpi-exporter
+  name: {{ template "kpi-exporter.fullname" . }}
   labels:
     release: {{ .Release.Name }}
 spec:
@@ -28,3 +29,4 @@
       protocol: TCP
   selector:
     app: "kpi-exporter"
+{{- end }}