From 541dcff7dd33d1ad560e3883822cefd82821fb3a Mon Sep 17 00:00:00 2001 From: Alecs Tusciuc Date: Tue, 15 Oct 2019 15:51:48 +0300 Subject: [PATCH] [Issue #267] Support fullnameOverride in kibana, filebeat, metricbeat charts --- filebeat/README.md | 1 + filebeat/templates/_helpers.tpl | 4 ++++ filebeat/tests/filebeat_test.py | 21 ++++++++++++++++++++- kibana/README.md | 1 + kibana/templates/_helpers.tpl | 4 ++++ kibana/tests/kibana_test.py | 13 +++++++++++++ metricbeat/README.md | 1 + metricbeat/templates/_helpers.tpl | 4 ++++ metricbeat/tests/metricbeat_test.py | 19 +++++++++++++++++++ 9 files changed, 67 insertions(+), 1 deletion(-) diff --git a/filebeat/README.md b/filebeat/README.md index d8b57c9bd..43d181db0 100644 --- a/filebeat/README.md +++ b/filebeat/README.md @@ -68,6 +68,7 @@ helm install --name filebeat elastic/filebeat --set imageTag=7.4.0 | `affinity` | Configurable [affinity](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity) | `{}` | | `priorityClassName` | The [name of the PriorityClass](https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/#priorityclass). No default is supplied as the PriorityClass must be created first. | `""` | | `updateStrategy` | The [updateStrategy](https://kubernetes.io/docs/tasks/manage-daemon/update-daemon-set/#daemonset-update-strategy) for the `DaemonSet`. By default Kubernetes will kill and recreate pods on updates. Setting this to `OnDelete` will require that pods be deleted manually. | `RollingUpdate` | +| `fullnameOverride` | Overrides the full name of the resources. If not set the name will default to "`.Release.Name`-`.Values.nameOverride or .Chart.Name`" | `""` | ## Examples diff --git a/filebeat/templates/_helpers.tpl b/filebeat/templates/_helpers.tpl index 769546335..3c5ec7678 100755 --- a/filebeat/templates/_helpers.tpl +++ b/filebeat/templates/_helpers.tpl @@ -11,9 +11,13 @@ Create a default fully qualified app name. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). */}} {{- define "fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} {{- $name := default .Chart.Name .Values.nameOverride -}} {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} {{- end -}} +{{- end -}} {{/* Use the fullname if the serviceAccount value is not set diff --git a/filebeat/tests/filebeat_test.py b/filebeat/tests/filebeat_test.py index 5bd288921..7e74f1029 100644 --- a/filebeat/tests/filebeat_test.py +++ b/filebeat/tests/filebeat_test.py @@ -39,7 +39,7 @@ def test_defaults(): assert { 'name': 'data', 'hostPath': { - 'path': '/var/lib/release-name-filebeat-default-data', + 'path': '/var/lib/' + name + '-default-data', 'type': 'DirectoryOrCreate' } } in volumes @@ -231,3 +231,22 @@ def test_priority_class_name(): r = helm_template(config) priority_class_name = r['daemonset'][name]['spec']['template']['spec']['priorityClassName'] assert priority_class_name == "highest" + +def test_setting_fullnameOverride(): + config = ''' +fullnameOverride: 'filebeat-custom' +''' + r = helm_template(config) + + custom_name = 'filebeat-custom' + assert custom_name in r['daemonset'] + assert r['daemonset'][custom_name]['spec']['template']['spec']['containers'][0]['name'] == project + assert r['daemonset'][custom_name]['spec']['template']['spec']['serviceAccountName'] == name + volumes = r['daemonset'][custom_name]['spec']['template']['spec']['volumes'] + assert { + 'name': 'data', + 'hostPath': { + 'path': '/var/lib/' + custom_name + '-default-data', + 'type': 'DirectoryOrCreate' + } + } in volumes diff --git a/kibana/README.md b/kibana/README.md index 6c6e3db8d..480af4e18 100644 --- a/kibana/README.md +++ b/kibana/README.md @@ -71,6 +71,7 @@ helm install --name kibana elastic/kibana --set imageTag=7.4.0 | `service` | Configurable [service](https://kubernetes.io/docs/concepts/services-networking/service/) to expose the Kibana service. See [`values.yaml`](./values.yaml) for an example | `type: ClusterIP`
`port: 5601`
`nodePort:`
`annotations: {}` | | `labels` | Configurable [label](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/) applied to all Kibana pods | `{}` | | `lifecycle` | Allows you to add lifecycle configuration. See [values.yaml](./values.yaml) for an example of the formatting. | `{}` | +| `fullnameOverride` | Overrides the full name of the resources. If not set the name will default to "`.Release.Name`-`.Values.nameOverride or .Chart.Name`" | `""` | ## Examples diff --git a/kibana/templates/_helpers.tpl b/kibana/templates/_helpers.tpl index a5254f445..517c2daa2 100755 --- a/kibana/templates/_helpers.tpl +++ b/kibana/templates/_helpers.tpl @@ -11,9 +11,13 @@ Create a default fully qualified app name. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). */}} {{- define "fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} {{- $name := default .Release.Name .Values.nameOverride -}} {{- printf "%s-%s" $name .Chart.Name | trunc 63 | trimSuffix "-" -}} {{- end -}} +{{- end -}} {{/* Return the appropriate apiVersion for ingress. diff --git a/kibana/tests/kibana_test.py b/kibana/tests/kibana_test.py index de4ddb3a8..afc37e8fd 100644 --- a/kibana/tests/kibana_test.py +++ b/kibana/tests/kibana_test.py @@ -406,3 +406,16 @@ def test_adding_lifecycle_events(): d = r['deployment'][name]['spec']['template']['spec'] p = d['containers'][0]['lifecycle']['postStart'] assert p['exec']['command'][0] == '/bin/true' + +def test_setting_fullnameOverride(): + config = ''' +fullnameOverride: 'kibana-custom' +''' + r = helm_template(config) + + custom_name = 'kibana-custom' + assert custom_name in r['deployment'] + assert custom_name in r['service'] + + assert r['service'][custom_name]['spec']['ports'][0]['port'] == 5601 + assert r['deployment'][custom_name]['spec']['template']['spec']['containers'][0]['name'] == 'kibana' diff --git a/metricbeat/README.md b/metricbeat/README.md index abe26b7c8..00fe89d45 100644 --- a/metricbeat/README.md +++ b/metricbeat/README.md @@ -64,6 +64,7 @@ helm install --name metricbeat elastic/metricbeat --set imageTag=7.4.0 | `affinity` | Configurable [affinity](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity) | `{}` | | `updateStrategy` | The [updateStrategy](https://kubernetes.io/docs/tasks/manage-daemon/update-daemon-set/#daemonset-update-strategy) for the `DaemonSet`. By default Kubernetes will kill and recreate pods on updates. Setting this to `OnDelete` will require that pods be deleted manually. | `RollingUpdate` | | `replicas` | The replica count for the metricbeat deployment talking to kube-state-metrics | `1` | +| `fullnameOverride` | Overrides the full name of the resources. If not set the name will default to "`.Release.Name`-`.Values.nameOverride or .Chart.Name`" | `""` | ## Examples diff --git a/metricbeat/templates/_helpers.tpl b/metricbeat/templates/_helpers.tpl index 769546335..3c5ec7678 100755 --- a/metricbeat/templates/_helpers.tpl +++ b/metricbeat/templates/_helpers.tpl @@ -11,9 +11,13 @@ Create a default fully qualified app name. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). */}} {{- define "fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} {{- $name := default .Chart.Name .Values.nameOverride -}} {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} {{- end -}} +{{- end -}} {{/* Use the fullname if the serviceAccount value is not set diff --git a/metricbeat/tests/metricbeat_test.py b/metricbeat/tests/metricbeat_test.py index 6148f45a8..987963a43 100644 --- a/metricbeat/tests/metricbeat_test.py +++ b/metricbeat/tests/metricbeat_test.py @@ -230,3 +230,22 @@ def test_cluster_role_rules(): assert rules['apiGroups'][0] == 'someone' assert rules['verbs'][0] == 'or' assert rules['resources'][0] == 'something' + +def test_setting_fullnameOverride(): + config = ''' +fullnameOverride: 'metricbeat-custom' +''' + r = helm_template(config) + + custom_name = 'metricbeat-custom' + assert custom_name in r['daemonset'] + assert r['daemonset'][custom_name]['spec']['template']['spec']['containers'][0]['name'] == project + assert r['daemonset'][custom_name]['spec']['template']['spec']['serviceAccountName'] == name + volumes = r['daemonset'][custom_name]['spec']['template']['spec']['volumes'] + assert { + 'name': 'data', + 'hostPath': { + 'path': '/var/lib/' + custom_name + '-default-data', + 'type': 'DirectoryOrCreate' + } + } in volumes