From 3d8654b65b7f04918169dd461a50ce1e247298c3 Mon Sep 17 00:00:00 2001 From: James Andrew Date: Wed, 6 Mar 2024 10:36:55 +0000 Subject: [PATCH 1/2] [prometheus-pushgateway] Add config for hard/soft podAntiAffinity Signed-off-by: James Andrew --- charts/prometheus-pushgateway/Chart.yaml | 2 +- .../templates/_helpers.tpl | 23 +++++++++++++++++-- charts/prometheus-pushgateway/values.yaml | 12 ++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/charts/prometheus-pushgateway/Chart.yaml b/charts/prometheus-pushgateway/Chart.yaml index a0e2af2f58f7..1b9633c6f5a7 100644 --- a/charts/prometheus-pushgateway/Chart.yaml +++ b/charts/prometheus-pushgateway/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 appVersion: "v1.7.0" description: A Helm chart for prometheus pushgateway name: prometheus-pushgateway -version: 2.7.1 +version: 2.8.0 home: https://github.com/prometheus/pushgateway sources: - https://github.com/prometheus/pushgateway diff --git a/charts/prometheus-pushgateway/templates/_helpers.tpl b/charts/prometheus-pushgateway/templates/_helpers.tpl index 73eefcb1c18d..af9bad350e62 100644 --- a/charts/prometheus-pushgateway/templates/_helpers.tpl +++ b/charts/prometheus-pushgateway/templates/_helpers.tpl @@ -182,10 +182,29 @@ nodeSelector: tolerations: {{- toYaml . | nindent 2 }} {{- end }} -{{- with .Values.affinity }} +{{- if or .Values.podAntiAffinity .Values.affinity }} affinity: - {{- toYaml . | nindent 2 }} {{- end }} + {{- with .Values.affinity }} + {{- toYaml . | nindent 2 }} + {{- end }} + {{- if eq .Values.podAntiAffinity "hard" }} + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - topologyKey: {{ .Values.podAntiAffinityTopologyKey }} + labelSelector: + matchExpressions: + - {key: app.kubernetes.io/name, operator: In, values: [{{ include "prometheus-pushgateway.name" . }}]} + {{- else if eq .Values.podAntiAffinity "soft" }} + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + topologyKey: {{ .Values.podAntiAffinityTopologyKey }} + labelSelector: + matchExpressions: + - {key: app.kubernetes.io/name, operator: In, values: [{{ include "prometheus-pushgateway.name" . }}]} + {{- end }} {{- with .Values.topologySpreadConstraints }} topologySpreadConstraints: {{- toYaml . | nindent 2 }} diff --git a/charts/prometheus-pushgateway/values.yaml b/charts/prometheus-pushgateway/values.yaml index 344b22d64131..9bf3bd3e917d 100644 --- a/charts/prometheus-pushgateway/values.yaml +++ b/charts/prometheus-pushgateway/values.yaml @@ -213,6 +213,18 @@ containerSecurityContext: {} ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity affinity: {} +## Pod anti-affinity can prevent the scheduler from placing push-gateway replicas on the same node. +## The default value "soft" means that the scheduler should *prefer* to not schedule two replica pods onto the same node but no guarantee is provided. +## The value "hard" means that the scheduler is *required* to not schedule two replica pods onto the same node. +## The value "" will disable pod anti-affinity so that no anti-affinity rules will be configured. +## +podAntiAffinity: "" + +## If anti-affinity is enabled sets the topologyKey to use for anti-affinity. +## This can be changed to, for example, failure-domain.beta.kubernetes.io/zone +## +podAntiAffinityTopologyKey: kubernetes.io/hostname + ## Topology spread constraints for pods ## Ref: https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/ topologySpreadConstraints: [] From e0cfebb3db57a0b808b8f8601c942f0b8a132688 Mon Sep 17 00:00:00 2001 From: James Andrew Date: Thu, 7 Mar 2024 17:06:04 +0000 Subject: [PATCH 2/2] [prometheus-pushgateway] Fix podAntiAffinity config comments Signed-off-by: James Andrew --- charts/prometheus-pushgateway/values.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/charts/prometheus-pushgateway/values.yaml b/charts/prometheus-pushgateway/values.yaml index 9bf3bd3e917d..1f67939dbe40 100644 --- a/charts/prometheus-pushgateway/values.yaml +++ b/charts/prometheus-pushgateway/values.yaml @@ -213,10 +213,10 @@ containerSecurityContext: {} ## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity affinity: {} -## Pod anti-affinity can prevent the scheduler from placing push-gateway replicas on the same node. -## The default value "soft" means that the scheduler should *prefer* to not schedule two replica pods onto the same node but no guarantee is provided. +## Pod anti-affinity can prevent the scheduler from placing pushgateway replicas on the same node. +## The value "soft" means that the scheduler should *prefer* to not schedule two replica pods onto the same node but no guarantee is provided. ## The value "hard" means that the scheduler is *required* to not schedule two replica pods onto the same node. -## The value "" will disable pod anti-affinity so that no anti-affinity rules will be configured. +## The default value "" will disable pod anti-affinity so that no anti-affinity rules will be configured (unless set in `affinity`). ## podAntiAffinity: ""