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

[filebeat][metricbeat] Add configurable nodeSelector and affinity spec #243

Merged
merged 1 commit into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions filebeat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ helm install --name filebeat elastic/filebeat --set imageTag=7.3.0
| `secretMounts` | Allows you easily mount a secret as a file inside the `DaemonSet`. Useful for mounting certificates and other secrets. See [values.yaml](./values.yaml) for an example | `[]` |
| `terminationGracePeriod` | Termination period (in seconds) to wait before killing Filebeat pod process on pod shutdown | `30` |
| `tolerations` | Configurable [tolerations](https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/) | `[]` |
| `nodeSelector` | Configurable [nodeSelector](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector) | `{}` |
| `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` |

## Examples
Expand Down
9 changes: 7 additions & 2 deletions filebeat/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ spec:
release: {{ .Release.Name | quote }}
spec:
{{- with .Values.tolerations }}
tolerations:
{{ toYaml . | indent 6 }}
tolerations: {{ toYaml . | nindent 6 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector: {{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity: {{ toYaml . | nindent 8 -}}
{{- end }}
serviceAccountName: {{ template "serviceAccount" . }}
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriod }}
Expand Down
28 changes: 28 additions & 0 deletions filebeat/tests/filebeat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,31 @@ def test_adding_pod_labels():
'''
r = helm_template(config)
assert r['daemonset'][name]['metadata']['labels']['app.kubernetes.io/name'] == 'filebeat'


def test_adding_a_node_selector():
config = '''
nodeSelector:
disktype: ssd
'''
r = helm_template(config)
assert r['daemonset'][name]['spec']['template']['spec']['nodeSelector']['disktype'] == 'ssd'


def test_adding_an_affinity_rule():
config = '''
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- filebeat
topologyKey: kubernetes.io/hostname
'''

r = helm_template(config)
assert r['daemonset'][name]['spec']['template']['spec']['affinity']['podAntiAffinity'][
'requiredDuringSchedulingIgnoredDuringExecution'][0]['topologyKey'] == 'kubernetes.io/hostname'
4 changes: 4 additions & 0 deletions filebeat/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ terminationGracePeriod: 30

tolerations: []

nodeSelector: {}

affinity: {}

updateStrategy: RollingUpdate

# Override various naming aspects of this chart
Expand Down
2 changes: 2 additions & 0 deletions metricbeat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ helm install --name metricbeat elastic/metricbeat --set imageTag=7.3.0
| `secretMounts` | Allows you easily mount a secret as a file inside the `DaemonSet`. Useful for mounting certificates and other secrets. See [values.yaml](./values.yaml) for an example | `[]` |
| `terminationGracePeriod` | Termination period (in seconds) to wait before killing Metricbeat pod process on pod shutdown | `30` |
| `tolerations` | Configurable [tolerations](https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/) | `[]` |
| `nodeSelector` | Configurable [nodeSelector](https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector) | `{}` |
| `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` |

Expand Down
9 changes: 7 additions & 2 deletions metricbeat/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ spec:
release: {{ .Release.Name | quote }}
spec:
{{- with .Values.tolerations }}
tolerations:
{{ toYaml . | indent 6 }}
tolerations: {{ toYaml . | nindent 6 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector: {{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity: {{ toYaml . | nindent 8 -}}
{{- end }}
serviceAccountName: {{ template "serviceAccount" . }}
terminationGracePeriodSeconds: {{ .Values.terminationGracePeriod }}
Expand Down
28 changes: 28 additions & 0 deletions metricbeat/tests/metricbeat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,31 @@ def test_adding_a_extra_volume_with_volume_mount():
assert {'name': 'extras', 'emptyDir': {}} in extraVolume
extraVolumeMounts = r['daemonset'][name]['spec']['template']['spec']['containers'][0]['volumeMounts']
assert {'name': 'extras', 'mountPath': '/usr/share/extras', 'readOnly': True} in extraVolumeMounts


def test_adding_a_node_selector():
config = '''
nodeSelector:
disktype: ssd
'''
r = helm_template(config)
assert r['daemonset'][name]['spec']['template']['spec']['nodeSelector']['disktype'] == 'ssd'


def test_adding_an_affinity_rule():
config = '''
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'
4 changes: 4 additions & 0 deletions metricbeat/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ terminationGracePeriod: 30

tolerations: []

nodeSelector: {}

affinity: {}

updateStrategy: RollingUpdate

# Override various naming aspects of this chart
Expand Down