Skip to content

Conversation

klinch0
Copy link
Contributor

@klinch0 klinch0 commented Aug 11, 2025

What this PR does

Release note

- fix etcd topologySpreadConstraints

Summary by CodeRabbit

  • New Features

    • Added optional cluster-level configuration to override topology spread constraints for etcd pods, enabling custom scheduling rules. Defaults remain unchanged when not configured.
  • Chores

    • Bumped etcd chart version to 2.9.1 for release tracking.
    • Updated versions mapping to include 2.9.1 and pinned the previous 2.9.0 entry to a specific commit for reproducibility.

Signed-off-by: kklinch0 <kklinch0@gmail.com>
@klinch0 klinch0 requested review from kvaps and lllamnyp as code owners August 11, 2025 08:30
Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

Walkthrough

Version bump of the etcd Helm chart to 2.9.1, introduction of configurable topologySpreadConstraints in the etcd StatefulSet via an optional ConfigMap, and updates to versions_map to pin 2.9.0 to a commit and add 2.9.1 at HEAD.

Changes

Cohort / File(s) Summary
Helm chart version bump
packages/extra/etcd/Chart.yaml
Update chart version from 2.9.0 to 2.9.1.
Etcd scheduling template logic
packages/extra/etcd/templates/etcd-cluster.yaml
Add conditional rendering of topologySpreadConstraints by reading ConfigMap cozy-system/cozystack-scheduling key globalAppTopologySpreadConstraints; fall back to existing hard-coded constraints when absent/empty.
Version map updates
packages/extra/versions_map
Pin etcd 2.9.0 to commit 8ddbe32 and add etcd 2.9.1 at HEAD.

Sequence Diagram(s)

sequenceDiagram
    participant User as Helm install/upgrade
    participant Helm as Etcd chart template
    participant K8s as Kubernetes API
    Note over Helm: Render etcd-cluster.yaml
    Helm->>K8s: lookup ConfigMap cozy-system/cozystack-scheduling
    alt ConfigMap has key globalAppTopologySpreadConstraints (non-empty)
        Helm->>Helm: Parse YAML constraints
        Helm-->>User: Render with provided topologySpreadConstraints
    else
        Helm-->>User: Render with hard-coded topologySpreadConstraints
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • lllamnyp
  • kvaps

Poem

A bunny bounds through charts so spry,
From 2.9.0 to .1 we hop on by.
Spread wide the pods, by map’s decree—
Or default paths, as safe as can be.
Versions pinned, the warren’s set—
Thump-thump! Our cluster’s best one yet. 🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix-fix-etcd-topologySpreadConstraints

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @klinch0, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

I've implemented a fix for etcd's topologySpreadConstraints by making them configurable. This change allows the etcd cluster to dynamically fetch its topology spread constraints from a central ConfigMap, providing greater flexibility in deployment configurations. If no custom constraints are defined, it falls back to the default behavior.

Highlights

  • Dynamic Topology Spread Constraints: I've updated the etcd cluster deployment to dynamically retrieve topology spread constraints from the cozystack-scheduling ConfigMap. This enables centralized management of pod distribution policies for etcd.
  • Fallback Mechanism: If the specified ConfigMap or the globalAppTopologySpreadConstraints key is not found, the etcd deployment will default to its original, hardcoded topology spread constraints to ensure continued functionality.
  • Version Update: I've incremented the etcd chart version to 2.9.1 and updated the versions_map to reflect this change, along with the associated commit hash.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the etcd chart to allow for configurable topologySpreadConstraints from a global ConfigMap, falling back to a default if not provided. The chart version is also bumped. My review includes a suggestion to make the Helm template logic for fetching the constraints more concise and robust.

Comment on lines +52 to +56
{{- $configMap := lookup "v1" "ConfigMap" "cozy-system" "cozystack-scheduling" }}
{{- $rawConstraints := "" }}
{{- if $configMap }}
{{- $rawConstraints = get $configMap.data "globalAppTopologySpreadConstraints" }}
{{- end }}

Choose a reason for hiding this comment

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

medium

The logic to fetch globalAppTopologySpreadConstraints from the ConfigMap can be made more concise and idiomatic by using the with action. This avoids declaring a temporary variable for the ConfigMap and makes the template cleaner. Using default "" also adds robustness in case the key is not found or the data map is nil.

    {{- $rawConstraints := "" }}
    {{- with lookup "v1" "ConfigMap" "cozy-system" "cozystack-scheduling" }}
      {{- $rawConstraints = get .data "globalAppTopologySpreadConstraints" | default "" }}
    {{- end }}

Copy link
Member

@kvaps kvaps left a comment

Choose a reason for hiding this comment

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

lgtm

@kvaps kvaps added the backport Should change be backported on previus release label Aug 11, 2025
Copy link
Contributor

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/extra/etcd/templates/etcd-cluster.yaml (1)

52-56: Be cautious with lookup: determinism and RBAC. Consider gating or documenting.

Using lookup against cozy-system/cozystack-scheduling introduces environment-dependent rendering:

  • helm template (no cluster access) will take the fallback path; helm install/upgrade (with cluster access) might render differently.
  • If the executing identity lacks get on configmaps in cozy-system, rendering may fail (depending on Helm version/behavior).

Options:

  • Gate behind a chart value (e.g., .Values.enableGlobalSchedulingConfig) or document the RBAC requirement and rendering variance.
  • Keep as-is if this is an intentional global override mechanism in your deployment model.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e091fa5 and 92f206c.

📒 Files selected for processing (3)
  • packages/extra/etcd/Chart.yaml (1 hunks)
  • packages/extra/etcd/templates/etcd-cluster.yaml (1 hunks)
  • packages/extra/versions_map (1 hunks)
🔇 Additional comments (3)
packages/extra/versions_map (1)

16-17: versions_map entries verified and consistent

All verification steps have passed without issue:

  • Commit 8ddbe32e exists.
  • packages/extra/etcd/Chart.yaml at that commit is version 2.9.0.
  • Current packages/extra/etcd/Chart.yaml is version 2.9.1.
  • packages/extra/versions_map includes the etcd 2.9.1 HEAD entry at lines 16–17.

No further action required.

packages/extra/etcd/Chart.yaml (1)

6-6: Version bump to 2.9.1 LGTM.

packages/extra/etcd/templates/etcd-cluster.yaml (1)

60-66: Default fallback retained; verify the label selector matches actual pod labels.

The fallback constraint selects on app.kubernetes.io/instance: etcd. Ensure etcd pods carry this label (operator-managed labels sometimes differ). If they don’t, the constraint won’t be applied.

Comment on lines +57 to +59
{{- if $rawConstraints }}
{{- $rawConstraints | fromYaml | toYaml | nindent 6 }}
{{- else }}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Handle empty/whitespace values and list-vs-map inputs to avoid emitting 'null' or malformed YAML.

If the ConfigMap key exists but is empty/whitespace, fromYaml may yield nil and toYaml can emit null, breaking the manifest. Also, if the provided YAML is only a list (not including the topologySpreadConstraints: key), it will be emitted at the wrong level.

Proposed robust handling:

  • Trim whitespace before testing truthiness.
  • Parse once; if it's a map with topologySpreadConstraints, emit it as-is; otherwise wrap the parsed content under topologySpreadConstraints:.

Apply:

-    {{- $configMap := lookup "v1" "ConfigMap" "cozy-system" "cozystack-scheduling" }}
-    {{- $rawConstraints := "" }}
-    {{- if $configMap }}
-      {{- $rawConstraints = get $configMap.data "globalAppTopologySpreadConstraints" }}
-    {{- end }}
-    {{- if $rawConstraints }}
-      {{- $rawConstraints | fromYaml | toYaml | nindent 6 }}
-    {{- else }}
+    {{- $configMap := lookup "v1" "ConfigMap" "cozy-system" "cozystack-scheduling" }}
+    {{- $rawConstraints := "" }}
+    {{- if $configMap }}
+      {{- $rawConstraints = get $configMap.data "globalAppTopologySpreadConstraints" }}
+    {{- end }}
+    {{- $rawTrim := trim $rawConstraints }}
+    {{- if $rawTrim }}
+      {{- $parsed := fromYaml $rawTrim }}
+      {{- if and (kindIs "map" $parsed) (hasKey $parsed "topologySpreadConstraints") }}
+{{ $parsed | toYaml | nindent 6 }}
+      {{- else }}
+      topologySpreadConstraints:
+{{ $parsed | toYaml | nindent 8 }}
+      {{- end }}
+    {{- else }}
       topologySpreadConstraints:
       - maxSkew: 1
         topologyKey: "kubernetes.io/hostname"
         whenUnsatisfiable: ScheduleAnyway
         labelSelector:
           matchLabels:
             app.kubernetes.io/instance: etcd
-    {{- end }}
+    {{- end }}

Also applies to: 67-67

🤖 Prompt for AI Agents
In packages/extra/etcd/templates/etcd-cluster.yaml around lines 57-59 (and
likewise at line 67), the template currently pipes $rawConstraints directly
through fromYaml/toYaml which can emit "null" for empty/whitespace values and
misplace list-only inputs; trim whitespace first, bail out if the trimmed value
is empty, then parse once into a variable, test if the parsed value is a map
that already contains the topologySpreadConstraints key and emit it as-is,
otherwise wrap the parsed value under topologySpreadConstraints: before
rendering so lists become the value of that key.

@klinch0 klinch0 merged commit 39fb4ec into main Aug 11, 2025
17 of 20 checks passed
@klinch0 klinch0 deleted the bugfix-fix-etcd-topologySpreadConstraints branch August 11, 2025 09:21
Copy link

Successfully created backport PR for release-0.34:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Should change be backported on previus release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants