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

Commit

Permalink
[logstash] feat: add podAffinity settings (#1257) (#1275)
Browse files Browse the repository at this point in the history
Co-authored-by: t.decaux <t.decaux@qwant.com>

Co-authored-by: Thomas Decaux <ebuildy@gmail.com>
Co-authored-by: t.decaux <t.decaux@qwant.com>
  • Loading branch information
3 people authored Jul 6, 2021
1 parent 57113dd commit f9640d7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
4 changes: 3 additions & 1 deletion logstash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | `{}` |
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions logstash/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -204,7 +208,7 @@ spec:
{{- range $path, $config := .Values.logstashPattern }}
- name: logstashpattern
mountPath: {{ $logstashPatternDir }}{{ $path }}
subPath: {{ $path }}
subPath: {{ $path }}
{{- end -}}
{{- end -}}
{{- if .Values.extraVolumeMounts }}
Expand Down
22 changes: 22 additions & 0 deletions logstash/tests/logstash_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion logstash/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f9640d7

Please sign in to comment.