From 724821b265f370032110c6e1b46a33a995adc452 Mon Sep 17 00:00:00 2001 From: Andrey Tatarinov Date: Tue, 27 Aug 2024 21:14:27 +0400 Subject: [PATCH] switch to spreadServiceAcrossNodes setting --- charts/simple-app/CHANGELOG.md | 4 ++++ charts/simple-app/Chart.yaml | 2 +- charts/simple-app/templates/deployment.yaml | 9 ++++++--- charts/simple-app/tests/simple_test.yaml | 19 +++++++++++++++++++ charts/simple-app/values.schema.json | 3 +++ charts/simple-app/values.yaml | 6 +++--- 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/charts/simple-app/CHANGELOG.md b/charts/simple-app/CHANGELOG.md index 3c8ab7b..c114e01 100644 --- a/charts/simple-app/CHANGELOG.md +++ b/charts/simple-app/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.13.0 + +* Add `spreadServiceAcrossNodes` setting + # 0.12.0, 0.12.1 * Add `monitoringCoreos` setting for prometheus-operator managed metrics diff --git a/charts/simple-app/Chart.yaml b/charts/simple-app/Chart.yaml index e226bc3..6737762 100644 --- a/charts/simple-app/Chart.yaml +++ b/charts/simple-app/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: "0.12.1" +version: "0.13.0" # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/simple-app/templates/deployment.yaml b/charts/simple-app/templates/deployment.yaml index 73859ab..dcc1368 100644 --- a/charts/simple-app/templates/deployment.yaml +++ b/charts/simple-app/templates/deployment.yaml @@ -131,10 +131,13 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} + {{- if .Values.spreadServiceAcrossNodes }} topologySpreadConstraints: - labelSelector: matchLabels: - app.kubernetes.io/instance: {{ .Release.Name }} - maxSkew: {{ .Values.skew }} + {{- include "simple-app.selectorLabels" . | nindent 12 }} + maxSkew: 1 topologyKey: "kubernetes.io/hostname" - whenUnsatisfiable: {{ .Values.skewPolicy }} \ No newline at end of file + nodeTaintsPolicy: Honor + whenUnsatisfiable: ScheduleAnyway + {{- end }} diff --git a/charts/simple-app/tests/simple_test.yaml b/charts/simple-app/tests/simple_test.yaml index dec399f..7aa0be9 100644 --- a/charts/simple-app/tests/simple_test.yaml +++ b/charts/simple-app/tests/simple_test.yaml @@ -308,3 +308,22 @@ tests: - equal: path: metadata.name value: simple + + - it: Spread service across nodes + template: deployment.yaml + set: + spreadServiceAcrossNodes: true + asserts: + - isKind: + of: Deployment + - equal: + path: spec.template.spec.topologySpreadConstraints + value: + - maxSkew: 1 + topologyKey: kubernetes.io/hostname + nodeTaintsPolicy: Honor + whenUnsatisfiable: ScheduleAnyway + labelSelector: + matchLabels: + app.kubernetes.io/instance: simple + app.kubernetes.io/name: simple-app diff --git a/charts/simple-app/values.schema.json b/charts/simple-app/values.schema.json index 7d39fbf..1aae96e 100644 --- a/charts/simple-app/values.schema.json +++ b/charts/simple-app/values.schema.json @@ -196,6 +196,9 @@ "affinity": { "type": "object" }, + "spreadServiceAcrossNodes": { + "type": "boolean" + }, "gke": { "type": "object", "properties": { diff --git a/charts/simple-app/values.yaml b/charts/simple-app/values.yaml index 76f996a..2f62c7c 100644 --- a/charts/simple-app/values.yaml +++ b/charts/simple-app/values.yaml @@ -4,9 +4,6 @@ # This is a YAML-formatted file. # Declare variables to be passed into your templates. -skew: 1 -skewPolicy: ScheduleAnyway - nameOverride: "" fullnameOverride: "" @@ -181,6 +178,9 @@ tolerations: [] affinity: {} +# If set, create topologySpreadConstraints to spread the pods across nodes +spreadServiceAcrossNodes: false + # Settings specific to GKE deployment gke: # If enabled and gateway.enabled is true, creates GCPBackendPolicy and