Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

[metricbeat] support deployment/daemonset specific metrics #820

Merged
merged 2 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion metricbeat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ as a reference. They are also used in the automated testing of this chart.
|--------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|
| `clusterRoleRules` | Configurable [cluster role rules][] that Metricbeat uses to access Kubernetes resources | see [values.yaml][] |
| `daemonset.annotations` | Configurable [annotations][] for Metricbeat daemonset | `{}` |
| `daemonset.labels` | Configurable [labels][] applied to all Metricbeat DaemonSet pods | `{}` |
| `daemonset.affinity` | Configurable [affinity][] for Metricbeat daemonset | `{}` |
| `daemonset.enabled` | If true, enable daemonset | `true` |
| `daemonset.envFrom` | Templatable string of `envFrom` to be passed to the [environment from variables][] which will be appended to Metricbeat container for DaemonSet | `[]` |
Expand All @@ -104,6 +105,7 @@ as a reference. They are also used in the automated testing of this chart.
| `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.labels` | Configurable [labels][] applied to all Metricbeat Deployment pods | `{}` |
| `deployment.affinity` | Configurable [affinity][] for Metricbeat Deployment | `{}` |
| `deployment.enabled` | If true, enable deployment | `true` |
| `deployment.envFrom` | Templatable string of `envFrom` to be passed to the [environment from variables][] which will be appended to Metricbeat container for Deployment | `[]` |
Expand All @@ -126,7 +128,6 @@ as a reference. They are also used in the automated testing of this chart.
| `image` | The Metricbeat Docker image | `docker.elastic.co/beats/metricbeat` |
| `kube_state_metrics.enabled` | Install [kube-state-metrics](https://github.com/helm/charts/tree/master/stable/kube-state-metrics) as a dependency | `true` |
| `kube_state_metrics.host` | Define kube-state-metrics endpoint for an existing deployment. Works only if `kube_state_metrics.enabled: false` | `""` |
| `labels` | Configurable [labels][] applied to all Metricbeat pods | `{}` |
| `livenessProbe` | Parameters to pass to liveness [probe][] checks for values such as timeouts and thresholds | see [values.yaml][] |
| `managedServiceAccount` | Whether the `serviceAccount` should be managed by this helm chart. Set this to `false` in order to manage your own service account and related roles | `true` |
| `nameOverride` | Overrides the chart name for resources. If not set the name will default to `.Chart.Name` | `""` |
Expand Down Expand Up @@ -155,6 +156,7 @@ as a reference. They are also used in the automated testing of this chart.
| `resources` | Allows you to set the [resources][] for both Metricbeat DaemonSet and Deployment | `{}` |
| `secretMounts` | Allows you easily mount a secret as a file inside DaemonSet and Deployment Useful for mounting certificates and other secrets | `[]` |
| `tolerations` | Configurable [tolerations][] for both Metricbeat DaemonSet and Deployment | `[]` |
| `labels` | Configurable [labels][] applied to all Metricbeat pods | `[]` |


## FAQ
Expand Down
12 changes: 12 additions & 0 deletions metricbeat/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ metadata:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
{{- if .Values.daemonset.labels }}
{{- range $key, $value := .Values.daemonset.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- else }}
{{- range $key, $value := .Values.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- if .Values.daemonset.annotations}}
annotations:
{{- range $key, $value := .Values.daemonset.annotations }}
Expand Down Expand Up @@ -41,9 +47,15 @@ spec:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
{{- if .Values.daemonset.labels }}
{{- range $key, $value := .Values.daemonset.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- else }}
{{- range $key, $value := .Values.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
spec:
affinity: {{ toYaml ( .Values.affinity | default .Values.daemonset.affinity ) | nindent 8 }}
nodeSelector: {{ toYaml ( .Values.nodeSelector | default .Values.daemonset.nodeSelector ) | nindent 8 }}
Expand Down
15 changes: 15 additions & 0 deletions metricbeat/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ metadata:
chart: '{{ .Chart.Name }}-{{ .Chart.Version }}'
heritage: '{{ .Release.Service }}'
release: '{{ .Release.Name }}'
{{- if .Values.deployment.labels }}
{{- range $key, $value := .Values.deployment.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- else }}
{{- range $key, $value := .Values.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- if .Values.deployment.annotations}}
annotations:
{{- range $key, $value := .Values.deployment.annotations }}
Expand Down Expand Up @@ -38,9 +47,15 @@ spec:
chart: '{{ .Chart.Name }}-{{ .Chart.Version }}'
heritage: '{{ .Release.Service }}'
release: '{{ .Release.Name }}'
{{- if .Values.deployment.labels }}
{{- range $key, $value := .Values.deployment.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- else }}
{{- range $key, $value := .Values.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
spec:
affinity: {{ toYaml .Values.deployment.affinity | nindent 8 }}
nodeSelector: {{ toYaml .Values.deployment.nodeSelector | nindent 8 }}
Expand Down
87 changes: 82 additions & 5 deletions metricbeat/tests/metricbeat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,24 +968,101 @@ def test_cluster_role_rules():
assert rules["resources"][0] == "something"


def test_adding_pod_labels():
def test_adding_legacy_labels():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer naming this test test_adding_deprecated_labels to be more consistent with the other related test names.

config = """
labels:
app.kubernetes.io/name: metricbeat
app-test: metricbeat
"""
r = helm_template(config)
assert r["daemonset"][name]["metadata"]["labels"]["app-test"] == "metricbeat"
assert (
r["daemonset"][name]["metadata"]["labels"]["app.kubernetes.io/name"]
r["deployment"][name + "-metrics"]["metadata"]["labels"]["app-test"]
== "metricbeat"
)
assert (
r["daemonset"][name]["spec"]["template"]["metadata"]["labels"][
"app.kubernetes.io/name"
r["daemonset"][name]["spec"]["template"]["metadata"]["labels"]["app-test"]
== "metricbeat"
)
assert (
r["deployment"][name + "-metrics"]["spec"]["template"]["metadata"]["labels"][
"app-test"
]
== "metricbeat"
)


def test_adding_daemonset_labels():
config = """
daemonset:
labels:
app-test: metricbeat
"""
r = helm_template(config)
assert r["daemonset"][name]["metadata"]["labels"]["app-test"] == "metricbeat"
assert (
r["daemonset"][name]["spec"]["template"]["metadata"]["labels"]["app-test"]
== "metricbeat"
)


def test_adding_daemonset_labels_surpasses_root_labels():
config = """
labels:
app-test: root-metricbeat
daemonset:
labels:
app-test: daemonset-metricbeat
"""
r = helm_template(config)
assert (
r["daemonset"][name]["metadata"]["labels"]["app-test"] == "daemonset-metricbeat"
)
assert (
r["daemonset"][name]["spec"]["template"]["metadata"]["labels"]["app-test"]
== "daemonset-metricbeat"
)


def test_adding_deployment_labels():
config = """
deployment:
labels:
app-test: metricbeat
"""
r = helm_template(config)
assert (
r["deployment"][name + "-metrics"]["metadata"]["labels"]["app-test"]
== "metricbeat"
)
assert (
r["deployment"][name + "-metrics"]["spec"]["template"]["metadata"]["labels"][
"app-test"
]
== "metricbeat"
)


def test_adding_deployment_labels_surpasses_root_labels():
config = """
labels:
app-test: root-metricbeat
deployment:
labels:
app-test: deployment-metricbeat
"""
r = helm_template(config)
assert (
r["deployment"][name + "-metrics"]["metadata"]["labels"]["app-test"]
== "deployment-metricbeat"
)
assert (
r["deployment"][name + "-metrics"]["spec"]["template"]["metadata"]["labels"][
"app-test"
]
== "deployment-metricbeat"
)


def test_adding_serviceaccount_annotations():
config = """
serviceAccountAnnotations:
Expand Down
8 changes: 5 additions & 3 deletions metricbeat/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
daemonset:
# Annotations to apply to the daemonset
annotations: {}
# additionals labels
labels: {}
affinity: {}
# Include the daemonset
enabled: true
Expand Down Expand Up @@ -97,6 +99,8 @@ daemonset:
deployment:
# Annotations to apply to the deployment
annotations: {}
# additionals labels
labels: {}
affinity: {}
# Include the deployment
enabled: true
Expand Down Expand Up @@ -197,9 +201,6 @@ readinessProbe:
periodSeconds: 10
timeoutSeconds: 5

# additionals labels
labels: {}

# Whether this chart should self-manage its service account, role, and associated role binding.
managedServiceAccount: true

Expand Down Expand Up @@ -285,3 +286,4 @@ podSecurityContext: {}
resources: {}
secretMounts: []
tolerations: []
labels: {}