From 56e36d266cfce9cfc3c5f2983e013f9f880a973f Mon Sep 17 00:00:00 2001 From: Tim Campbell Date: Wed, 9 Apr 2025 09:41:34 +0200 Subject: [PATCH] Resource-specific nodeSelector (#176) Co-authored-by: Yann Defretin --- CHANGELOG.md | 4 ++ Chart.yaml | 2 +- templates/cronjob-media-remove.yaml | 4 ++ templates/deployment-sidekiq.yaml | 4 +- templates/deployment-streaming.yaml | 4 +- templates/deployment-web.yaml | 4 +- templates/job-assets-copy.yaml | 5 +++ templates/job-create-admin.yaml | 4 ++ templates/job-db-migrate.yaml | 4 ++ templates/job-db-pre-migrate.yaml | 4 ++ templates/job-db-prepare.yaml | 4 ++ values.yaml | 60 +++++++++++++++++++++++++++-- 12 files changed, 92 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01091af..f7a02b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 6.3.0 + +- Added `nodeSelector` fields for every resource type for better fine-grain tuning of where resources end up. + # 6.2.4 - Fixed an issue where redis secrets specified in values or the helm CLI wouldn't be used by the db-prepare job on install. diff --git a/Chart.yaml b/Chart.yaml index 37a898f..33382cf 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: 6.2.4 +version: 6.3.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/cronjob-media-remove.yaml b/templates/cronjob-media-remove.yaml index 5dbd578..a4c4510 100644 --- a/templates/cronjob-media-remove.yaml +++ b/templates/cronjob-media-remove.yaml @@ -107,4 +107,8 @@ spec: - name: system mountPath: /opt/mastodon/public/system {{- end }} + {{- with coalesce .Values.mastodon.cron.removeMedia.nodeSelector .Values.nodeSelector }} + nodeSelector: + {{- . | toYaml | nindent 12 }} + {{- end }} {{- end }} diff --git a/templates/deployment-sidekiq.yaml b/templates/deployment-sidekiq.yaml index 74f6472..30ae0a5 100644 --- a/templates/deployment-sidekiq.yaml +++ b/templates/deployment-sidekiq.yaml @@ -258,9 +258,9 @@ spec: resources: {{- toYaml (default (default $context.Values.resources $context.Values.mastodon.sidekiq.resources) .resources) | nindent 12 }} {{- include "mastodon.statsdExporterContainer" $ | indent 8 }} - {{- with $context.Values.nodeSelector }} + {{- with coalesce .nodeSelector $context.Values.mastodon.sidekiq.nodeSelector $context.Values.nodeSelector }} nodeSelector: - {{- toYaml . | nindent 8 }} + {{- . | toYaml | nindent 8 }} {{- end }} {{- with $context.Values.tolerations }} tolerations: diff --git a/templates/deployment-streaming.yaml b/templates/deployment-streaming.yaml index 6715195..b0752a4 100644 --- a/templates/deployment-streaming.yaml +++ b/templates/deployment-streaming.yaml @@ -164,9 +164,9 @@ spec: resources: {{- toYaml . | nindent 12 }} {{- end }} - {{- with .Values.nodeSelector }} + {{- with coalesce .Values.mastodon.streaming.nodeSelector .Values.nodeSelector }} nodeSelector: - {{- toYaml . | nindent 8 }} + {{- . | toYaml | nindent 8 }} {{- end }} {{- with (default .Values.affinity .Values.mastodon.streaming.affinity) }} affinity: diff --git a/templates/deployment-web.yaml b/templates/deployment-web.yaml index c62af1a..1031edf 100644 --- a/templates/deployment-web.yaml +++ b/templates/deployment-web.yaml @@ -272,9 +272,9 @@ spec: containerPort: {{ .Values.mastodon.metrics.prometheus.port }} {{- end }} {{- include "mastodon.statsdExporterContainer" $ | indent 8 }} - {{- with .Values.nodeSelector }} + {{- with coalesce .Values.mastodon.web.nodeSelector .Values.nodeSelector }} nodeSelector: - {{- toYaml . | nindent 8 }} + {{- . | toYaml | nindent 8 }} {{- end }} {{- with (default .Values.affinity .Values.mastodon.web.affinity) }} affinity: diff --git a/templates/job-assets-copy.yaml b/templates/job-assets-copy.yaml index 2ac51fa..496e599 100644 --- a/templates/job-assets-copy.yaml +++ b/templates/job-assets-copy.yaml @@ -89,4 +89,9 @@ spec: volumes: - name: assets emptyDir: {} + {{- with coalesce .Values.mastodon.hooks.s3Upload.nodeSelector .Values.nodeSelector }} + nodeSelector: + {{- . | toYaml | nindent 8 }} + {{- end }} + {{- end -}} diff --git a/templates/job-create-admin.yaml b/templates/job-create-admin.yaml index d1a4355..f54a696 100644 --- a/templates/job-create-admin.yaml +++ b/templates/job-create-admin.yaml @@ -95,4 +95,8 @@ spec: - name: system mountPath: /opt/mastodon/public/system {{- end }} + {{- with coalesce .Values.mastodon.createAdmin.nodeSelector .Values.nodeSelector }} + nodeSelector: + {{- . | toYaml | nindent 8 }} + {{- end }} {{- end }} diff --git a/templates/job-db-migrate.yaml b/templates/job-db-migrate.yaml index 748420c..c33d58d 100644 --- a/templates/job-db-migrate.yaml +++ b/templates/job-db-migrate.yaml @@ -1,3 +1,7 @@ {{- if .Values.mastodon.hooks.dbMigrate.enabled }} {{- include "mastodon.dbMigrateJob" (merge (dict "preDeploy" false ) .) }} + {{- with coalesce .Values.mastodon.hooks.dbMigrate.nodeSelector .Values.nodeSelector }} + nodeSelector: + {{- . | toYaml | nindent 8 }} + {{- end }} {{- end }} diff --git a/templates/job-db-pre-migrate.yaml b/templates/job-db-pre-migrate.yaml index bae1717..09b4759 100644 --- a/templates/job-db-pre-migrate.yaml +++ b/templates/job-db-pre-migrate.yaml @@ -1,3 +1,7 @@ {{- if .Values.mastodon.hooks.dbMigrate.enabled }} {{- include "mastodon.dbMigrateJob" (merge (dict "preDeploy" true ) .) }} + {{- with coalesce .Values.mastodon.hooks.dbMigrate.nodeSelector .Values.nodeSelector }} + nodeSelector: + {{- . | toYaml | nindent 8 }} + {{- end }} {{- end }} diff --git a/templates/job-db-prepare.yaml b/templates/job-db-prepare.yaml index 0b6d8ba..98fba59 100644 --- a/templates/job-db-prepare.yaml +++ b/templates/job-db-prepare.yaml @@ -1,3 +1,7 @@ {{- if and .Values.mastodon.hooks.dbPrepare.enabled (not .Values.postgresql.enabled) }} {{- include "mastodon.dbMigrateJob" (merge (dict "prepare" true ) .) }} + {{- with coalesce .Values.mastodon.hooks.dbPrepare.nodeSelector .Values.nodeSelector }} + nodeSelector: + {{- . | toYaml | nindent 8 }} + {{- end }} {{- end }} diff --git a/values.yaml b/values.yaml index aecb48c..726148e 100644 --- a/values.yaml +++ b/values.yaml @@ -25,6 +25,8 @@ mastodon: username: not_gargron # @ignored email: not@example.com + # Node(s) on which we will deploy this job + nodeSelector: {} hooks: # Whether to perform DB schema creation on `helm install`. # Please note that this does not work when using the included database @@ -34,9 +36,13 @@ mastodon: # and `pre-upgrade`. dbPrepare: enabled: true + # Node(s) on which we will deploy this job + nodeSelector: {} # Whether to perform DB migrations on `helm upgrade`. dbMigrate: enabled: true + # Node(s) on which we will deploy this job + nodeSelector: {} # WARNING: deploySearch is potentially a very expensive job! # Only enable this once at a time, when you deploy elasticsearch or when @@ -89,9 +95,11 @@ mastodon: rclone: # Any additional environment variables to pass to rclone. env: {} + # Node(s) on which we will deploy this job + nodeSelector: {} # Custom labels to add to kubernetes resources #labels: - # -- deploy search to elastsicsearch. Requires .elasticsearch.enabled = true + cron: # -- run `tootctl media remove` every week removeMedia: @@ -99,6 +107,9 @@ mastodon: enabled: true # @ignored schedule: "0 0 * * 0" + # Node(s) on which we will deploy this job + nodeSelector: {} + # -- available locales: https://github.com/mastodon/mastodon/blob/main/config/application.rb#L71 locale: en local_domain: mastodon.local @@ -203,6 +214,9 @@ mastodon: resources: {} # -- Affinity for all Sidekiq Deployments unless overwritten, overwrites .Values.affinity affinity: {} + # Node(s) on which we will deploy sidekiq in general + # Any worker-specific configuration will override this setting. + nodeSelector: {} # -- Annotations to apply to the deployment object(s) for sidekiq. # -- These are applied in addition to deploymentAnnotations. annotations: {} @@ -259,8 +273,11 @@ mastodon: resources: {} # -- Affinity for this specific deployment, overwrites .Values.affinity and .Values.mastodon.sidekiq.affinity affinity: {} + # -- Node(s) on which we will deploy this sidekiq worker + nodeSelector: {} # -- Topology spread constraints for this specific deployment, overwrites .Values.topologySpreadConstraints and .Values.mastodon.sidekiq.topologySpreadConstraints topologySpreadConstraints: {} + # -- Sidekiq queues for Mastodon that are handled by this worker. See https://docs.joinmastodon.org/admin/scaling/#concurrency # See https://github.com/mperham/sidekiq/wiki/Advanced-Options#queues for how to weight queues as argument queues: @@ -332,6 +349,8 @@ mastodon: replicas: 1 # -- Affinity for Streaming Pods, overwrites .Values.affinity affinity: {} + # -- Node(s) on which we will deploy the streaming pods + nodeSelector: {} # -- Annotations to apply to the deployment object for streaming. # -- These are applied in addition to deploymentAnnotations. annotations: {} @@ -390,6 +409,8 @@ mastodon: replicas: 1 # -- Affinity for Web Pods, overwrites .Values.affinity affinity: {} + # -- Node(s) on which we will deploy the web pods + nodeSelector: {} # -- Annotations to apply to the deployment object for web. # -- These are applied in addition to deploymentAnnotations. annotations: {} @@ -428,8 +449,10 @@ mastodon: enable: false # minAvailable: 1 # maxUnavailable: 1 + # -- Puma-specific options. Below values are based on default behavior in # config/puma.rb when no custom values are provided. + minThreads: "5" maxThreads: "5" workers: "2" @@ -586,6 +609,18 @@ elasticsearch: # Name of an existing secret with a password key # existingSecret: + # -- Node(s) on which we will deploy the various elasticsearch pods + master: + nodeSelector: {} + data: + nodeSelector: {} + coordinating: + nodeSelector: {} + ingest: + nodeSelector: {} + metrics: + nodeSelector: {} + # Configuration for PostgreSQL. # When enabled, the bitnami helm chart is used for PostgreSQL deployment, and # all values here correspond to their values file. Please see the bitnami chart @@ -640,6 +675,15 @@ postgresql: password: existingSecret: + # -- Node(s) on which we will deploy the various database pods + primary: + nodeSelector: {} + readReplicas: + nodeSelector: {} + backup: + cronjob: + nodeSelector: {} + # Configuration for Redis. # When enabled, the bitnami helm chart used for Redis deployment, and all values # here correspond to their values file. Please see the bitnami chart @@ -692,6 +736,12 @@ redis: # with a key of redis-password set to the password you want existingSecret: "" + # -- Node(s) on which we will deploy the various redis pods + master: + nodeSelector: {} + replica: + nodeSelector: {} + # @ignored service: type: ClusterIP @@ -848,15 +898,17 @@ resources: # cpu: 100m # memory: 128Mi -# @ignored -nodeSelector: {} - # @ignored tolerations: [] # -- Affinity for all mastodon pods unless overwritten affinity: {} +# Node(s) on which we will deploy all resources. +# Any node selectors specified for individual resources will override this +# setting. +nodeSelector: {} + # -- Timezone for all mastodon pods unless overwritten timezone: UTC