From c437b0ad150e299ea5c30edac1b0e0a042198cbd Mon Sep 17 00:00:00 2001 From: Tim Campbell Date: Wed, 10 Jul 2024 16:26:02 +0200 Subject: [PATCH] Allow customization of rollout strategies for deployments (#142) --- Chart.yaml | 2 +- templates/deployment-sidekiq.yaml | 17 +++++++++++++-- templates/deployment-streaming.yaml | 8 +++----- templates/deployment-web.yaml | 8 +++----- values.yaml | 32 +++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/Chart.yaml b/Chart.yaml index 57768b3..8bb36ad 100644 --- a/Chart.yaml +++ b/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: 5.1.3 +version: 5.2.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/templates/deployment-sidekiq.yaml b/templates/deployment-sidekiq.yaml index 1870cf4..9eec596 100644 --- a/templates/deployment-sidekiq.yaml +++ b/templates/deployment-sidekiq.yaml @@ -18,8 +18,9 @@ spec: {{- if (gt (int .replicas) 1) }} {{ fail "The scheduler queue should never have more than 1 replicas" }} {{- end }} - strategy: - type: Recreate + {{- end }} + {{- if $context.Values.mastodon.sidekiq.updateStrategy }} + strategy: {{- toYaml $context.Values.mastodon.sidekiq.updateStrategy | nindent 4 }} {{- end }} replicas: {{ .replicas }} {{- if (ne (toString $context.Values.mastodon.revisionHistoryLimit) "") }} @@ -200,6 +201,18 @@ spec: {{- with $context.Values.volumeMounts }} {{- toYaml . | nindent 12 }} {{- end }} + {{- if $context.Values.mastodon.sidekiq.readinessProbe.enabled }} + readinessProbe: + failureThreshold: {{ default 10 $context.Values.mastodon.sidekiq.readinessProbe.failureThreshold }} + exec: + command: + - cat + - {{ required "A valid sidekiq readiness path is required." $context.Values.mastodon.sidekiq.readinessProbe.path }} + initialDelaySeconds: {{ default 10 $context.Values.mastodon.sidekiq.readinessProbe.initialDelaySeconds }} + periodSeconds: {{ default 2 $context.Values.mastodon.sidekiq.readinessProbe.periodSeconds }} + successThreshold: {{ default 1 $context.Values.mastodon.sidekiq.readinessProbe.successThreshold }} + timeoutSeconds: {{ default 1 $context.Values.mastodon.sidekiq.readinessProbe.timeoutSeconds }} + {{- end }} resources: {{- toYaml (default (default $context.Values.resources $context.Values.mastodon.sidekiq.resources) .resources) | nindent 12 }} {{- include "mastodon.statsdExporterContainer" $ | indent 8 }} diff --git a/templates/deployment-streaming.yaml b/templates/deployment-streaming.yaml index 3165fa2..89bd06a 100644 --- a/templates/deployment-streaming.yaml +++ b/templates/deployment-streaming.yaml @@ -13,11 +13,9 @@ spec: {{- if (ne (toString .Values.mastodon.revisionHistoryLimit) "") }} revisionHistoryLimit: {{ .Values.mastodon.revisionHistoryLimit }} {{- end }} - strategy: - type: RollingUpdate - rollingUpdate: - maxSurge: 10% - maxUnavailable: 25% + {{- if .Values.mastodon.web.updateStrategy }} + strategy: {{- toYaml .Values.mastodon.web.updateStrategy | nindent 4 }} + {{- end }} selector: matchLabels: {{- include "mastodon.selectorLabels" . | nindent 6 }} diff --git a/templates/deployment-web.yaml b/templates/deployment-web.yaml index 70d1c29..2956a21 100644 --- a/templates/deployment-web.yaml +++ b/templates/deployment-web.yaml @@ -13,11 +13,9 @@ spec: {{- if (ne (toString .Values.mastodon.revisionHistoryLimit) "") }} revisionHistoryLimit: {{ .Values.mastodon.revisionHistoryLimit }} {{- end }} - strategy: - type: RollingUpdate - rollingUpdate: - maxSurge: 10% - maxUnavailable: 25% + {{- if .Values.mastodon.web.updateStrategy }} + strategy: {{- toYaml .Values.mastodon.web.updateStrategy | nindent 4 }} + {{- end }} selector: matchLabels: {{- include "mastodon.selectorLabels" . | nindent 6 }} diff --git a/values.yaml b/values.yaml index 073fd2e..d9782fd 100644 --- a/values.yaml +++ b/values.yaml @@ -138,6 +138,24 @@ mastodon: resources: {} # -- Affinity for all Sidekiq Deployments unless overwritten, overwrites .Values.affinity affinity: {} + # Rollout strategy to use when updating pods. + # Recreate will help reduce the number of retried jobs when updating when + # the code introduces a new job as the pods are all replaced immediately. + # RollingUpdate can help with larger clusters if job retries aren't an + # issue, as it will reduce strain by replacing pods more slowly. It is + # strongly recommended to enable the readinessProbe when using RollingUpdate. + # ref: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy + updateStrategy: + type: Recreate + # Readiness probe configuration + # NOTE: Readiness probe will only work on versions of Mastodon built after 2024-07-10. + readinessProbe: + enabled: false + path: /opt/mastodon/tmp/sidekiq_process_has_started_and_will_begin_processing_jobs + initialDelaySeconds: 10 + periodSeconds: 2 + successThreshold: 1 + timeoutSeconds: 1 # -- Topology spread constraints for Sidekiq Pods, overwrites .Values.topologySpreadConstraints topologySpreadConstraints: {} # limits: @@ -227,6 +245,13 @@ mastodon: replicas: 1 # -- Affinity for Streaming Pods, overwrites .Values.affinity affinity: {} + # Rollout strategy to use when updating pods + # ref: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy + updateStrategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 10% + maxUnavailable: 25% # -- Topology spread constraints for Streaming Pods, overwrites .Values.topologySpreadConstraints topologySpreadConstraints: {} # -- Pod Security Context for Streaming Pods, overwrites .Values.podSecurityContext @@ -266,6 +291,13 @@ mastodon: replicas: 1 # -- Affinity for Web Pods, overwrites .Values.affinity affinity: {} + # Rollout strategy to use when updating pods + # ref: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy + updateStrategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 10% + maxUnavailable: 25% # -- Topology spread constraints for Web Pods, overwrites .Values.topologySpreadConstraints topologySpreadConstraints: {} # -- Pod Security Context for Web Pods, overwrites .Values.podSecurityContext