Skip to content

add PDB and topologySpreadConstraints for multi replica deployments#35

Open
likesavabutworse wants to merge 3 commits intokafbat:mainfrom
likesavabutworse:main
Open

add PDB and topologySpreadConstraints for multi replica deployments#35
likesavabutworse wants to merge 3 commits intokafbat:mainfrom
likesavabutworse:main

Conversation

@likesavabutworse
Copy link
Copy Markdown

@likesavabutworse likesavabutworse commented Jan 21, 2025

Adds optional PodDisruptionBudget and topologySpreadConstraints. Both are disabled by default and can be enabled and configured when using deployments with more than 1 replica

Summary by CodeRabbit

  • New Features

    • Add configurable Pod Disruption Budget to control pod availability during disruptions.
    • Add configurable Topology Spread Constraints to improve pod distribution across zones.
  • Chores

    • Update chart defaults for environment mappings and add new scheduling/disruption value entries.
    • Bump chart version.

@likesavabutworse likesavabutworse requested a review from a team as a code owner January 21, 2025 23:19
Comment thread charts/kafka-ui/templates/deployment.yaml
@jcpunk
Copy link
Copy Markdown
Contributor

jcpunk commented Jan 7, 2026

It might be worthwhile to add the trailing newlines to the end of the files.

@Haarolean
Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 26, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eacbe61a-e7ca-4b12-9a3f-71f788f1026c

📥 Commits

Reviewing files that changed from the base of the PR and between 05b4094 and f25d652.

📒 Files selected for processing (3)
  • charts/kafka-ui/Chart.yaml
  • charts/kafka-ui/templates/deployment.yaml
  • charts/kafka-ui/values.yaml
✅ Files skipped from review due to trivial changes (1)
  • charts/kafka-ui/Chart.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • charts/kafka-ui/templates/deployment.yaml
  • charts/kafka-ui/values.yaml

📝 Walkthrough

Walkthrough

Adds topologySpreadConstraints and an optional PodDisruptionBudget to the Kafka UI Helm chart, updates default values for scheduling/disruption controls and env mappings, and bumps the chart version.

Changes

Cohort / File(s) Summary
Deployment template
charts/kafka-ui/templates/deployment.yaml
Inserted conditional spec.template.spec.topologySpreadConstraints rendering when .Values.topologySpreadConstraints.enabled is true; includes maxSkew, minDomains, topologyKey, whenUnsatisfiable, and labelSelector.matchLabels from include "kafka-ui.selectorLabels" .. Adjusted template whitespace/trailing newline.
Pod Disruption Budget (new)
charts/kafka-ui/templates/pod-disruption-budget.yaml
Added new template that conditionally creates a policy/v1 PodDisruptionBudget when .Values.podDisruptionBudget.enabled is true, injecting .Values.podDisruptionBudget.spec and using selector.matchLabels from include "kafka-ui.selectorLabels" ..
Chart values
charts/kafka-ui/values.yaml
Added podDisruptionBudget and topologySpreadConstraints value objects with defaults (enabled flags and configuration keys). Adjusted envs.secretMappings / envs.configMappings structure and minor whitespace.
Chart metadata
charts/kafka-ui/Chart.yaml
Bumped chart version from 1.6.2 to 1.6.3.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nibble templates and values with care,
Spreading pods like carrots across zones fair,
Budgets for wobble—keeps chaos at bay,
A rabbit approves this chart today! 🐇

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main additions: PodDisruptionBudget (PDB) and topologySpreadConstraints for multi-replica deployments, which aligns with the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@Haarolean
Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (5)
charts/kafka-ui/values.yaml (2)

281-286: Consider documenting minDomains impact on single-zone clusters.

With minDomains: 2 and whenUnsatisfiable: DoNotSchedule, enabling topology spread constraints on a single-zone cluster will cause pod scheduling failures. Users might enable this feature without realizing their cluster doesn't meet the minimum domain requirement.

Consider either:

  1. Defaulting minDomains to 1 (safer for varied cluster topologies), or
  2. Adding a more prominent warning in the comment
📝 Suggested documentation improvement
 # Topology Spread Constraints: https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/
+# WARNING: minDomains: 2 requires at least 2 availability zones. Pods will fail to schedule on single-zone clusters.
 topologySpreadConstraints:
   enabled: false
   maxSkew: 1
   topologyKey: topology.kubernetes.io/zone
-  minDomains: 2
+  minDomains: 2  # Set to 1 for single-zone clusters
   whenUnsatisfiable: DoNotSchedule # Must be DoNotSchedule if minDomains > 1
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kafka-ui/values.yaml` around lines 281 - 286, The
topologySpreadConstraints block currently sets minDomains: 2 and
whenUnsatisfiable: DoNotSchedule which will prevent pods from scheduling in
single-zone clusters; update the chart by either lowering
topologySpreadConstraints.minDomains to 1 (safer default) or add a prominent
comment/warning next to topologySpreadConstraints.minDomains and
whenUnsatisfiable explaining that enabling topologySpreadConstraints with
minDomains > 1 requires multi-zone clusters and will cause scheduling failures
on single-zone clusters so operators must adjust these values accordingly.

286-286: Add trailing newline at end of file.

The file is missing a trailing newline, which was noted in the PR comments.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kafka-ui/values.yaml` at line 286, The file is missing a trailing
newline at EOF; add a single newline character after the last line containing
"whenUnsatisfiable: DoNotSchedule # Must be DoNotSchedule if minDomains > 1" so
the file ends with a newline to satisfy POSIX/newline conventions and the
repository's linter/CI checks.
charts/kafka-ui/templates/deployment.yaml (1)

195-206: Topology spread constraints implementation looks correct.

The implementation properly:

  • Uses the shared kafka-ui.selectorLabels helper for consistency with the Deployment selector and PDB
  • Places matchLabelKeys at the correct level (sibling to labelSelector, not nested within it)
  • Uses pod-template-hash in matchLabelKeys to ensure spread is evaluated per-revision during rolling updates

One minor issue: the file is missing a trailing newline at the end, and line 206 has trailing whitespace after {{- end }}.

📝 Proposed fix for trailing whitespace and newline
           matchLabelKeys:
               - pod-template-hash              
-      {{- end }}    
+      {{- end }}
+

,

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kafka-ui/templates/deployment.yaml` around lines 195 - 206, Remove the
trailing whitespace after the closing template tag and ensure the file ends with
a single newline: update the deployment.yaml area around the
topologySpreadConstraints block (the section using
.Values.topologySpreadConstraints and the include "kafka-ui.selectorLabels") so
that the final "{{- end }}" has no trailing spaces and add a final newline
character at EOF.
charts/kafka-ui/templates/pod-disruption-budget.yaml (2)

11-11: Add trailing newline at end of file.

The file is missing a trailing newline, which is a POSIX convention and was noted in the PR comments.

📝 Proposed fix
       {{- include "kafka-ui.selectorLabels" . | nindent 6 }}
-{{- end -}}
+{{- end -}}
+
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kafka-ui/templates/pod-disruption-budget.yaml` at line 11, The file
ends with the Helm template token "{{- end -}}" but lacks a POSIX trailing
newline; update the template (the file containing the "{{- end -}}" token) to
add a single newline character at the end of the file so it ends with '\n' (LF).

6-10: Potential selector conflict if user specifies selector in spec.

The template renders .Values.podDisruptionBudget.spec via toYaml on line 7, then hardcodes the selector on lines 8-10. If a user accidentally adds a selector field within their podDisruptionBudget.spec values, the resulting YAML will have duplicate selector keys, leading to undefined behavior or the hardcoded selector being ignored.

Consider either:

  1. Documenting that selector should not be provided in spec, or
  2. Restructuring to only allow minAvailable/maxUnavailable fields explicitly:
♻️ Suggested restructure (optional)
 spec:
-  {{- toYaml .Values.podDisruptionBudget.spec | nindent 2 }}
+  {{- with .Values.podDisruptionBudget.minAvailable }}
+  minAvailable: {{ . }}
+  {{- end }}
+  {{- with .Values.podDisruptionBudget.maxUnavailable }}
+  maxUnavailable: {{ . }}
+  {{- end }}
   selector:
     matchLabels:
       {{- include "kafka-ui.selectorLabels" . | nindent 6 }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kafka-ui/templates/pod-disruption-budget.yaml` around lines 6 - 10,
The template may emit a duplicate selector because it renders
.Values.podDisruptionBudget.spec via toYaml and then unconditionally writes a
selector using include "kafka-ui.selectorLabels"; update the template so the
rendered spec cannot include a selector: either render only allowed fields (e.g.
explicitly output minAvailable and maxUnavailable from
.Values.podDisruptionBudget.spec) or strip/omit the selector key before toYaml
(so .Values.podDisruptionBudget.spec is rendered without a selector), then keep
the hardcoded selector using include "kafka-ui.selectorLabels" to avoid key
collisions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@charts/kafka-ui/templates/deployment.yaml`:
- Around line 195-206: Remove the trailing whitespace after the closing template
tag and ensure the file ends with a single newline: update the deployment.yaml
area around the topologySpreadConstraints block (the section using
.Values.topologySpreadConstraints and the include "kafka-ui.selectorLabels") so
that the final "{{- end }}" has no trailing spaces and add a final newline
character at EOF.

In `@charts/kafka-ui/templates/pod-disruption-budget.yaml`:
- Line 11: The file ends with the Helm template token "{{- end -}}" but lacks a
POSIX trailing newline; update the template (the file containing the "{{- end
-}}" token) to add a single newline character at the end of the file so it ends
with '\n' (LF).
- Around line 6-10: The template may emit a duplicate selector because it
renders .Values.podDisruptionBudget.spec via toYaml and then unconditionally
writes a selector using include "kafka-ui.selectorLabels"; update the template
so the rendered spec cannot include a selector: either render only allowed
fields (e.g. explicitly output minAvailable and maxUnavailable from
.Values.podDisruptionBudget.spec) or strip/omit the selector key before toYaml
(so .Values.podDisruptionBudget.spec is rendered without a selector), then keep
the hardcoded selector using include "kafka-ui.selectorLabels" to avoid key
collisions.

In `@charts/kafka-ui/values.yaml`:
- Around line 281-286: The topologySpreadConstraints block currently sets
minDomains: 2 and whenUnsatisfiable: DoNotSchedule which will prevent pods from
scheduling in single-zone clusters; update the chart by either lowering
topologySpreadConstraints.minDomains to 1 (safer default) or add a prominent
comment/warning next to topologySpreadConstraints.minDomains and
whenUnsatisfiable explaining that enabling topologySpreadConstraints with
minDomains > 1 requires multi-zone clusters and will cause scheduling failures
on single-zone clusters so operators must adjust these values accordingly.
- Line 286: The file is missing a trailing newline at EOF; add a single newline
character after the last line containing "whenUnsatisfiable: DoNotSchedule #
Must be DoNotSchedule if minDomains > 1" so the file ends with a newline to
satisfy POSIX/newline conventions and the repository's linter/CI checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e2396991-24b2-4f32-a6c4-1150b756caa3

📥 Commits

Reviewing files that changed from the base of the PR and between cb3a0b1 and 05b4094.

📒 Files selected for processing (3)
  • charts/kafka-ui/templates/deployment.yaml
  • charts/kafka-ui/templates/pod-disruption-budget.yaml
  • charts/kafka-ui/values.yaml

@Haarolean
Copy link
Copy Markdown
Member

@likesavabutworse linter's failing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants