From f9640d7f2e5cbe8c793f59e912286135de21dddb Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Tue, 6 Jul 2021 09:04:02 +0200 Subject: [PATCH] [logstash] feat: add podAffinity settings (#1257) (#1275) Co-authored-by: t.decaux Co-authored-by: Thomas Decaux Co-authored-by: t.decaux --- logstash/README.md | 4 +++- logstash/templates/statefulset.yaml | 8 ++++++-- logstash/tests/logstash_test.py | 22 ++++++++++++++++++++++ logstash/values.yaml | 6 +++++- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/logstash/README.md b/logstash/README.md index 40c3e798b..2af59a9fe 100644 --- a/logstash/README.md +++ b/logstash/README.md @@ -133,6 +133,7 @@ useful for the [http input plugin][], for instance. | `maxUnavailable` | The [maxUnavailable][] value for the pod disruption budget. By default this will prevent Kubernetes from having more than 1 unhealthy pod in the node group | `1` | | `nameOverride` | Overrides the chart name for resources. If not set the name will default to `.Chart.Name` | `""` | | `nodeAffinity` | Value for the [node affinity settings][] | `{}` | +| `podAffinity` | Value for the [pod affinity settings][] | `{}` | | `nodeSelector` | Configurable [nodeSelector][] so that you can target specific nodes for your Logstash cluster | `{}` | | `persistence` | Enables a persistent volume for Logstash data | see [values.yaml][] | | `podAnnotations` | Configurable [annotations][] applied to all Logstash pods | `{}` | @@ -220,7 +221,8 @@ about our development and testing process. [logstash docker image]: https://www.elastic.co/guide/en/logstash/6.8/docker.html [logstash oss docker image]: https://www.docker.elastic.co/r/logstash/logstash-oss [maxUnavailable]: https://kubernetes.io/docs/tasks/run-application/configure-pdb/#specifying-a-poddisruptionbudget -[node affinity settings]: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#node-affinity-beta-feature +[node affinity settings]: https://kubernetes.io/docs/tasks/configure-pod-container/assign-pods-nodes-using-node-affinity/ +[pod affinity settings]: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity [nodeSelector]: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector [note]: https://www.elastic.co/guide/en/logstash/6.8/docker-config.html#docker-env-config [priorityClass]: https://kubernetes.io/docs/concepts/configuration/pod-priority-preemption/#priorityclass diff --git a/logstash/templates/statefulset.yaml b/logstash/templates/statefulset.yaml index de511c03f..f66d492d6 100644 --- a/logstash/templates/statefulset.yaml +++ b/logstash/templates/statefulset.yaml @@ -80,7 +80,7 @@ spec: nodeSelector: {{ toYaml . | indent 8 }} {{- end }} - {{- if or (eq .Values.antiAffinity "hard") (eq .Values.antiAffinity "soft") .Values.nodeAffinity }} + {{- if or (eq .Values.antiAffinity "hard") (eq .Values.antiAffinity "soft") .Values.nodeAffinity .Values.podAffinity }} {{- if .Values.priorityClassName }} priorityClassName: {{ .Values.priorityClassName }} {{- end }} @@ -111,6 +111,10 @@ spec: {{- end }} {{- with .Values.nodeAffinity }} nodeAffinity: +{{ toYaml . | indent 10 }} + {{- end }} + {{- with .Values.podAffinity }} + podAffinity: {{ toYaml . | indent 10 }} {{- end }} terminationGracePeriodSeconds: {{ .Values.terminationGracePeriod }} @@ -204,7 +208,7 @@ spec: {{- range $path, $config := .Values.logstashPattern }} - name: logstashpattern mountPath: {{ $logstashPatternDir }}{{ $path }} - subPath: {{ $path }} + subPath: {{ $path }} {{- end -}} {{- end -}} {{- if .Values.extraVolumeMounts }} diff --git a/logstash/tests/logstash_test.py b/logstash/tests/logstash_test.py index 3f44ceb9c..0f539aca2 100755 --- a/logstash/tests/logstash_test.py +++ b/logstash/tests/logstash_test.py @@ -557,6 +557,28 @@ def test_adding_a_node_affinity(): } +def test_adding_a_pod_affinity_rule(): + config = """ +podAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchExpressions: + - key: app + operator: In + values: + - elasticsearch + topologyKey: kubernetes.io/hostname +""" + + r = helm_template(config) + assert ( + r["statefulset"][name]["spec"]["template"]["spec"]["affinity"]["podAffinity"][ + "requiredDuringSchedulingIgnoredDuringExecution" + ][0]["topologyKey"] + == "kubernetes.io/hostname" + ) + + def test_adding_in_logstash_config(): config = """ logstashConfig: diff --git a/logstash/values.yaml b/logstash/values.yaml index 4bfcdd794..86d508ba1 100755 --- a/logstash/values.yaml +++ b/logstash/values.yaml @@ -160,9 +160,13 @@ antiAffinityTopologyKey: "kubernetes.io/hostname" antiAffinity: "hard" # This is the node affinity settings as defined in -# https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#node-affinity-beta-feature +# https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity nodeAffinity: {} +# This is inter-pod affinity settings as defined in +# https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#inter-pod-affinity-and-anti-affinity +podAffinity: {} + # The default is to deploy all pods serially. By setting this to parallel all pods are started at # the same time when bootstrapping the cluster podManagementPolicy: "Parallel"