From 70fec1f086f2b428b57f996fbd9c0bc833d8d5f2 Mon Sep 17 00:00:00 2001 From: kernkonzentrat Date: Wed, 8 Jul 2020 11:08:03 +0200 Subject: [PATCH] feat(metricbeat): annotation support for daemonset and deployment (#713) --- metricbeat/README.md | 2 ++ metricbeat/templates/daemonset.yaml | 6 ++++++ metricbeat/templates/deployment.yaml | 6 ++++++ metricbeat/tests/metricbeat_test.py | 24 ++++++++++++++++++++++++ metricbeat/values.yaml | 4 ++++ 5 files changed, 42 insertions(+) diff --git a/metricbeat/README.md b/metricbeat/README.md index 188d5bd4e..377c1c83a 100644 --- a/metricbeat/README.md +++ b/metricbeat/README.md @@ -92,6 +92,7 @@ as a reference. They are also used in the automated testing of this chart. | Parameter | Description | Default | |--------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------| | `clusterRoleRules` | Configurable [cluster role rules][] that Metricbeat uses to access Kubernetes resources | see [values.yaml][] | +| `daemonset.annotations` | Configurable [annotations][] for Metricbeat daemonset | `{}` | | `daemonset.affinity` | Configurable [affinity][] for Metricbeat daemonset | `{}` | | `daemonset.envFrom` | Templatable string of `envFrom` to be passed to the [environment from variables][] which will be appended to Metricbeat container for DaemonSet | `[]` | | `daemonset.extraEnvs` | Extra [environment variables][] which will be appended to Metricbeat container for DaemonSet | `[]` | @@ -104,6 +105,7 @@ as a reference. They are also used in the automated testing of this chart. | `daemonset.secretMounts` | Allows you easily mount a secret as a file inside the DaemonSet. Useful for mounting certificates and other secrets. See [values.yaml][] for an example | `[]` | | `daemonset.securityContext` | Configurable [securityContext][] for Metricbeat DaemonSet pod execution environment | see [values.yaml][] | | `daemonset.tolerations` | Configurable [tolerations][] for Metricbeat DaemonSet | `[]` | +| `deployment.annotations` | Configurable [annotations][] for Metricbeat Deployment | `{}` | | `deployment.affinity` | Configurable [affinity][] for Metricbeat Deployment | `{}` | | `deployment.envFrom` | Templatable string of `envFrom` to be passed to the [environment from variables][] which will be appended to Metricbeat container for Deployment | `[]` | | `deployment.extraEnvs` | Extra [environment variables][] which will be appended to Metricbeat container for Deployment | `[]` | diff --git a/metricbeat/templates/daemonset.yaml b/metricbeat/templates/daemonset.yaml index 73ef678ae..3ca25d8f6 100644 --- a/metricbeat/templates/daemonset.yaml +++ b/metricbeat/templates/daemonset.yaml @@ -11,6 +11,12 @@ metadata: {{- range $key, $value := .Values.labels }} {{ $key }}: {{ $value | quote }} {{- end }} + {{- if .Values.daemonset.annotations}} + annotations: + {{- range $key, $value := .Values.daemonset.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} + {{- end }} spec: selector: matchLabels: diff --git a/metricbeat/templates/deployment.yaml b/metricbeat/templates/deployment.yaml index 830438835..3e62e7e51 100644 --- a/metricbeat/templates/deployment.yaml +++ b/metricbeat/templates/deployment.yaml @@ -8,6 +8,12 @@ metadata: chart: '{{ .Chart.Name }}-{{ .Chart.Version }}' heritage: '{{ .Release.Service }}' release: '{{ .Release.Name }}' + {{- if .Values.deployment.annotations}} + annotations: + {{- range $key, $value := .Values.deployment.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} + {{- end }} spec: replicas: {{ .Values.replicas }} selector: diff --git a/metricbeat/tests/metricbeat_test.py b/metricbeat/tests/metricbeat_test.py index fae116de9..a0c97798c 100644 --- a/metricbeat/tests/metricbeat_test.py +++ b/metricbeat/tests/metricbeat_test.py @@ -1137,3 +1137,27 @@ def test_setting_fullnameOverride(): "type": "DirectoryOrCreate", }, } in volumes + + +def test_adding_annotations(): + config = """ +daemonset: + annotations: + foo: "bar" +""" + r = helm_template(config) + assert "foo" in r["daemonset"][name]["metadata"]["annotations"] + assert r["daemonset"][name]["metadata"]["annotations"]["foo"] == "bar" + assert "annotations" not in r["deployment"][name + "-metrics"]["metadata"] + config = """ +deployment: + annotations: + grault: "waldo" +""" + r = helm_template(config) + assert "grault" in r["deployment"][name + "-metrics"]["metadata"]["annotations"] + assert ( + r["deployment"][name + "-metrics"]["metadata"]["annotations"]["grault"] + == "waldo" + ) + assert "annotations" not in r["daemonset"][name]["metadata"] diff --git a/metricbeat/values.yaml b/metricbeat/values.yaml index f34440136..abe13312e 100755 --- a/metricbeat/values.yaml +++ b/metricbeat/values.yaml @@ -1,6 +1,8 @@ --- daemonset: + # Annotations to apply to the daemonset + annotations: {} affinity: {} # Extra environment variables for Metricbeat container. envFrom: [] @@ -91,6 +93,8 @@ daemonset: tolerations: [] deployment: + # Annotations to apply to the deployment + annotations: {} affinity: {} # Extra environment variables for Metricbeat container. envFrom: []