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

[metricbeat] split values for daemonset and deployment #572

Merged
merged 15 commits into from
Apr 17, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[metricbeat] split affinity for daemonset and deployment
  • Loading branch information
jmlrt committed Apr 14, 2020
commit 2a5e45d6cfcc05384bf4c83feac50dfd90fdfc32
4 changes: 3 additions & 1 deletion metricbeat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ helm install --name metricbeat elastic/metricbeat --set imageTag=7.6.2
## Configuration
| Parameter | Description | Default |
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| `daemonset.affinity` | Configurable [affinity][] for Metricbeat `DaemonSet`. | `{}` |
| `daemonset.metricbeatConfig` | Allows you to add any config files in `/usr/share/metricbeat` such as `metricbeat.yml` for Metricbeat `DaemonSet`. | see [values.yaml][] |
| `deployment.affinity` | Configurable [affinity][] for Metricbeat `Deployment`. | `{}` |
| `deployment.metricbeatConfig` | Allows you to add any config files in `/usr/share/metricbeat` such as `metricbeat.yml` for Metricbeat `Deployment`. | see [values.yaml][] |
| `extraContainers` | Templatable string of additional containers to be passed to the `tpl` function | `""` |
| `extraInitContainers` | Templatable string of additional containers to be passed to the `tpl` function | `""` |
Expand All @@ -93,7 +95,6 @@ helm install --name metricbeat elastic/metricbeat --set imageTag=7.6.2
| `terminationGracePeriod` | Termination period (in seconds) to wait before killing Metricbeat pod process on pod shutdown | `30` |
| `tolerations` | Configurable [tolerations][] | `[]` |
| `nodeSelector` | Configurable [nodeSelector][] | `{}` |
| `affinity` | Configurable [affinity][] | `{}` |
| `updateStrategy` | The [updateStrategy][] 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` |
| `priorityClassName` | The [name of the PriorityClass][]. No default is supplied as the PriorityClass must be created first. | `""` |
| `replicas` | The replica count for the metricbeat deployment talking to kube-state-metrics | `1` |
Expand All @@ -102,6 +103,7 @@ helm install --name metricbeat elastic/metricbeat --set imageTag=7.6.2
### Deprecated
| Parameter | Description | Default |
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
| `affinity` | Configurable [affinity][] | `{}` |
| `metricbeatConfig` | Allows you to add any config files in `/usr/share/metricbeat` such as `metricbeat.yml` for both Metricbeat `DaemonSet` and `Deployment`. | see [values.yaml][] |

## Examples
Expand Down
4 changes: 1 addition & 3 deletions metricbeat/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ spec:
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName }}
{{- end }}
{{- with .Values.affinity }}
affinity: {{ toYaml . | nindent 8 -}}
{{- end }}
affinity: {{ toYaml ( .Values.affinity | default .Values.daemonset.affinity ) | nindent 8 }}
serviceAccountName: {{ template "metricbeat.serviceAccount" . }}
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriod }}
volumes:
Expand Down
1 change: 1 addition & 0 deletions metricbeat/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ spec:
heritage: '{{ .Release.Service }}'
release: '{{ .Release.Name }}'
spec:
affinity: {{ toYaml .Values.deployment.affinity | nindent 8 }}
{{- with .Values.tolerations }}
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️ I really like all of these little cleanups here to add some consistency. I like the much cleaner and shorter versions using nindent below :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah Helm templates are a little more readable with nindents 😃.

tolerations:
{{ toYaml . | indent 6 }}
Expand Down
47 changes: 47 additions & 0 deletions metricbeat/tests/metricbeat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,53 @@ def test_adding_an_affinity_rule():
][0]["topologyKey"]
== "kubernetes.io/hostname"
)
assert (
r["deployment"][name + "-metrics"]["spec"]["template"]["spec"]["affinity"] == {}
)

config = """
daemonset:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- metricbeat
topologyKey: kubernetes.io/hostname
"""

r = helm_template(config)
assert (
r["daemonset"][name]["spec"]["template"]["spec"]["affinity"]["podAntiAffinity"][
"requiredDuringSchedulingIgnoredDuringExecution"
][0]["topologyKey"]
== "kubernetes.io/hostname"
)

config = """
deployment:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- metricbeat
topologyKey: kubernetes.io/hostname
"""

r = helm_template(config)
assert (
r["deployment"][name + "-metrics"]["spec"]["template"]["spec"]["affinity"][
"podAntiAffinity"
]["requiredDuringSchedulingIgnoredDuringExecution"][0]["topologyKey"]
== "kubernetes.io/hostname"
)


def test_priority_class_name():
Expand Down
7 changes: 5 additions & 2 deletions metricbeat/values.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---

daemonset:
affinity: {}
# Allows you to add any config files in /usr/share/metricbeat
# such as metricbeat.yml for daemonset
metricbeatConfig:
Expand Down Expand Up @@ -53,6 +54,7 @@ daemonset:
hosts: '${ELASTICSEARCH_HOSTS:elasticsearch-master:9200}'

deployment:
affinity: {}
# Allows you to add any config files in /usr/share/metricbeat
# such as metricbeat.yml for deployment
metricbeatConfig:
Expand Down Expand Up @@ -209,8 +211,6 @@ tolerations: []

nodeSelector: {}

affinity: {}

# This is the PriorityClass settings as defined in
# https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/#priorityclass
priorityClassName: ""
Expand All @@ -221,3 +221,6 @@ updateStrategy: RollingUpdate
# Only edit these if you know what you're doing
nameOverride: ""
fullnameOverride: ""

# DEPRECATED
affinity: {}