From fbf9d94b904321a3b6ac4345cb213c835849fd6e Mon Sep 17 00:00:00 2001 From: kernkonzentrat Date: Mon, 6 Jul 2020 17:35:28 +0200 Subject: [PATCH 1/8] feat(metricbeat): add support for annotations in daemonset and deployment PR for #684 --- metricbeat/templates/daemonset.yaml | 6 ++++ metricbeat/templates/deployment.yaml | 6 ++++ metricbeat/tests/metricbeat_test.py | 22 +++++++++++++ metricbeat/values.yaml | 49 +++++++++++++++------------- 4 files changed, 60 insertions(+), 23 deletions(-) diff --git a/metricbeat/templates/daemonset.yaml b/metricbeat/templates/daemonset.yaml index faa90ca10..fe1a760e0 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 1e0e407d2..e0bb9f40f 100644 --- a/metricbeat/tests/metricbeat_test.py +++ b/metricbeat/tests/metricbeat_test.py @@ -1123,3 +1123,25 @@ 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 59b032395..8e75336f5 100755 --- a/metricbeat/values.yaml +++ b/metricbeat/values.yaml @@ -1,6 +1,7 @@ --- - daemonset: + # Annotations to apply to the daemonset + annotations: {} affinity: {} # Extra environment variables for Metricbeat container. envFrom: [] @@ -91,6 +92,8 @@ daemonset: tolerations: [] deployment: + # Annotations to apply to the deployment + annotations: {} affinity: {} # Extra environment variables for Metricbeat container. envFrom: [] @@ -196,30 +199,30 @@ labels: {} managedServiceAccount: true clusterRoleRules: -- apiGroups: [""] - resources: - - nodes - - namespaces - - events - - pods - verbs: ["get", "list", "watch"] -- apiGroups: ["extensions"] - resources: - - replicasets - verbs: ["get", "list", "watch"] -- apiGroups: ["apps"] - resources: - - statefulsets - - deployments - - replicasets - verbs: ["get", "list", "watch"] -- apiGroups: [""] - resources: - - nodes/stats - verbs: ["get"] + - apiGroups: [""] + resources: + - nodes + - namespaces + - events + - pods + verbs: ["get", "list", "watch"] + - apiGroups: ["extensions"] + resources: + - replicasets + verbs: ["get", "list", "watch"] + - apiGroups: ["apps"] + resources: + - statefulsets + - deployments + - replicasets + verbs: ["get", "list", "watch"] + - apiGroups: [""] + resources: + - nodes/stats + verbs: ["get"] podAnnotations: {} - # iam.amazonaws.com/role: es-cluster +# iam.amazonaws.com/role: es-cluster # Custom service account override that the pod will use serviceAccount: "" From afb07b53144e29a6d1beb8938e0afb8babd417ad Mon Sep 17 00:00:00 2001 From: kernkonzentrat Date: Mon, 6 Jul 2020 17:53:04 +0200 Subject: [PATCH 2/8] chore(metricbeat): add annotations spec --- metricbeat/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/metricbeat/README.md b/metricbeat/README.md index 44c44561e..1e8e2911c 100644 --- a/metricbeat/README.md +++ b/metricbeat/README.md @@ -72,6 +72,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 | `[]` | @@ -84,6 +85,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 | `[]` | From 29b3feaa7d0be7be9b9cd1e7c8b59d1d17973293 Mon Sep 17 00:00:00 2001 From: kernkonzentrat Date: Tue, 7 Jul 2020 10:20:49 +0200 Subject: [PATCH 3/8] chore(metricbeat): undo formatting --- metricbeat/values.yaml | 51 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/metricbeat/values.yaml b/metricbeat/values.yaml index 8e75336f5..2037cb1db 100755 --- a/metricbeat/values.yaml +++ b/metricbeat/values.yaml @@ -1,4 +1,5 @@ --- + daemonset: # Annotations to apply to the daemonset annotations: {} @@ -162,7 +163,7 @@ extraInitContainers: "" hostPathRoot: /var/lib image: "docker.elastic.co/beats/metricbeat" -imageTag: "7.7.1" +imageTag: "8.0.0-SNAPSHOT" imagePullPolicy: "IfNotPresent" imagePullSecrets: [] @@ -199,34 +200,38 @@ labels: {} managedServiceAccount: true clusterRoleRules: - - apiGroups: [""] - resources: - - nodes - - namespaces - - events - - pods - verbs: ["get", "list", "watch"] - - apiGroups: ["extensions"] - resources: - - replicasets - verbs: ["get", "list", "watch"] - - apiGroups: ["apps"] - resources: - - statefulsets - - deployments - - replicasets - verbs: ["get", "list", "watch"] - - apiGroups: [""] - resources: - - nodes/stats - verbs: ["get"] +- apiGroups: [""] + resources: + - nodes + - namespaces + - events + - pods + verbs: ["get", "list", "watch"] +- apiGroups: ["extensions"] + resources: + - replicasets + verbs: ["get", "list", "watch"] +- apiGroups: ["apps"] + resources: + - statefulsets + - deployments + - replicasets + verbs: ["get", "list", "watch"] +- apiGroups: [""] + resources: + - nodes/stats + verbs: ["get"] podAnnotations: {} -# iam.amazonaws.com/role: es-cluster + # iam.amazonaws.com/role: es-cluster # Custom service account override that the pod will use serviceAccount: "" +# Annotations to add to the ServiceAccount that is created if the serviceAccount value isn't set. +serviceAccountAnnotations: {} + # eks.amazonaws.com/role-arn: arn:aws:iam::111111111111:role/k8s.clustername.namespace.serviceaccount + # How long to wait for metricbeat pods to stop gracefully terminationGracePeriod: 30 From 9245f7f61a22a00410d995bfae488c283bbac667 Mon Sep 17 00:00:00 2001 From: kernkonzentrat Date: Tue, 7 Jul 2020 10:23:42 +0200 Subject: [PATCH 4/8] chore(metricbeat): undo formatting --- metricbeat/values.yaml | 45 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/metricbeat/values.yaml b/metricbeat/values.yaml index 8e75336f5..76ae1c0c7 100755 --- a/metricbeat/values.yaml +++ b/metricbeat/values.yaml @@ -1,4 +1,5 @@ --- + daemonset: # Annotations to apply to the daemonset annotations: {} @@ -199,30 +200,30 @@ labels: {} managedServiceAccount: true clusterRoleRules: - - apiGroups: [""] - resources: - - nodes - - namespaces - - events - - pods - verbs: ["get", "list", "watch"] - - apiGroups: ["extensions"] - resources: - - replicasets - verbs: ["get", "list", "watch"] - - apiGroups: ["apps"] - resources: - - statefulsets - - deployments - - replicasets - verbs: ["get", "list", "watch"] - - apiGroups: [""] - resources: - - nodes/stats - verbs: ["get"] +- apiGroups: [""] + resources: + - nodes + - namespaces + - events + - pods + verbs: ["get", "list", "watch"] +- apiGroups: ["extensions"] + resources: + - replicasets + verbs: ["get", "list", "watch"] +- apiGroups: ["apps"] + resources: + - statefulsets + - deployments + - replicasets + verbs: ["get", "list", "watch"] +- apiGroups: [""] + resources: + - nodes/stats + verbs: ["get"] podAnnotations: {} -# iam.amazonaws.com/role: es-cluster + # iam.amazonaws.com/role: es-cluster # Custom service account override that the pod will use serviceAccount: "" From 617c06b182acb1ee6493f9e782d9a729b0608f24 Mon Sep 17 00:00:00 2001 From: kernkonzentrat Date: Tue, 7 Jul 2020 10:25:46 +0200 Subject: [PATCH 5/8] chore: remove props --- metricbeat/values.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/metricbeat/values.yaml b/metricbeat/values.yaml index 2037cb1db..76ae1c0c7 100755 --- a/metricbeat/values.yaml +++ b/metricbeat/values.yaml @@ -163,7 +163,7 @@ extraInitContainers: "" hostPathRoot: /var/lib image: "docker.elastic.co/beats/metricbeat" -imageTag: "8.0.0-SNAPSHOT" +imageTag: "7.7.1" imagePullPolicy: "IfNotPresent" imagePullSecrets: [] @@ -228,10 +228,6 @@ podAnnotations: {} # Custom service account override that the pod will use serviceAccount: "" -# Annotations to add to the ServiceAccount that is created if the serviceAccount value isn't set. -serviceAccountAnnotations: {} - # eks.amazonaws.com/role-arn: arn:aws:iam::111111111111:role/k8s.clustername.namespace.serviceaccount - # How long to wait for metricbeat pods to stop gracefully terminationGracePeriod: 30 From dcc30dfd3372f4efce9eea82a0bfad1f8aeb6c22 Mon Sep 17 00:00:00 2001 From: kernkonzentrat Date: Tue, 7 Jul 2020 11:55:54 +0200 Subject: [PATCH 6/8] chore(metricbeat): format add annotation test --- metricbeat/tests/metricbeat_test.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/metricbeat/tests/metricbeat_test.py b/metricbeat/tests/metricbeat_test.py index e0bb9f40f..357361dc7 100644 --- a/metricbeat/tests/metricbeat_test.py +++ b/metricbeat/tests/metricbeat_test.py @@ -1124,7 +1124,6 @@ def test_setting_fullnameOverride(): }, } in volumes - def test_adding_annotations(): config = """ daemonset: @@ -1133,7 +1132,9 @@ def test_adding_annotations(): """ r = helm_template(config) assert "foo" in r["daemonset"][name]["metadata"]["annotations"] - assert r["daemonset"][name]["metadata"]["annotations"]["foo"] == "bar" + assert ( + r["daemonset"][name]["metadata"]["annotations"]["foo"] == "bar" + ) assert "annotations" not in r["deployment"][name + "-metrics"]["metadata"] config = """ deployment: @@ -1142,6 +1143,8 @@ def test_adding_annotations(): """ r = helm_template(config) assert "grault" in r["deployment"][name + "-metrics"]["metadata"]["annotations"] - assert r["deployment"][name + "-metrics"]["metadata"]["annotations"]["grault"] == "waldo" + assert ( + r["deployment"][name + "-metrics"]["metadata"]["annotations"]["grault"] == "waldo" + ) assert "annotations" not in r["daemonset"][name]["metadata"] From 2a5787df16b4d485eb3a1dce133f0017aaf898ca Mon Sep 17 00:00:00 2001 From: kernkonzentrat Date: Tue, 7 Jul 2020 17:08:34 +0200 Subject: [PATCH 7/8] chore(metricbeat): format tests with black --- metricbeat/tests/metricbeat_test.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/metricbeat/tests/metricbeat_test.py b/metricbeat/tests/metricbeat_test.py index 357361dc7..b5ad66e36 100644 --- a/metricbeat/tests/metricbeat_test.py +++ b/metricbeat/tests/metricbeat_test.py @@ -1124,6 +1124,7 @@ def test_setting_fullnameOverride(): }, } in volumes + def test_adding_annotations(): config = """ daemonset: @@ -1132,9 +1133,7 @@ def test_adding_annotations(): """ r = helm_template(config) assert "foo" in r["daemonset"][name]["metadata"]["annotations"] - assert ( - r["daemonset"][name]["metadata"]["annotations"]["foo"] == "bar" - ) + assert r["daemonset"][name]["metadata"]["annotations"]["foo"] == "bar" assert "annotations" not in r["deployment"][name + "-metrics"]["metadata"] config = """ deployment: @@ -1143,8 +1142,9 @@ def test_adding_annotations(): """ r = helm_template(config) assert "grault" in r["deployment"][name + "-metrics"]["metadata"]["annotations"] - assert ( - r["deployment"][name + "-metrics"]["metadata"]["annotations"]["grault"] == "waldo" + assert ( + r["deployment"][name + "-metrics"]["metadata"]["annotations"]["grault"] + == "waldo" ) assert "annotations" not in r["daemonset"][name]["metadata"] From c2bd34c108f32d1276aa3bcba7f9c9c0f410530a Mon Sep 17 00:00:00 2001 From: kernkonzentrat Date: Tue, 7 Jul 2020 19:12:42 +0200 Subject: [PATCH 8/8] chore(metricbeat): fix black formatting --- metricbeat/tests/metricbeat_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/metricbeat/tests/metricbeat_test.py b/metricbeat/tests/metricbeat_test.py index b5ad66e36..f67ea43bb 100644 --- a/metricbeat/tests/metricbeat_test.py +++ b/metricbeat/tests/metricbeat_test.py @@ -1147,4 +1147,3 @@ def test_adding_annotations(): == "waldo" ) assert "annotations" not in r["daemonset"][name]["metadata"] -