Skip to content

fix: [AAP-81880] support topology spread constraints (and affinity) for the EDA kind - #365

Merged
kaiokmo merged 1 commit into
ansible:mainfrom
snagoor:AAP-81880
Sep 23, 2026
Merged

kaiokmo merged 1 commit into
ansible:mainfrom
snagoor:AAP-81880

Conversation

@snagoor

@snagoor snagoor commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Problem

topology_spread_constraints set on an EDA CR never make it into the generated Deployments.
The reconcile fails with an HTTP 422:

spec.template.spec.topologySpreadConstraints[0].maxSkew: Invalid value: 0: must be greater than zero
spec.template.spec.topologySpreadConstraints[0].topologyKey: Required value: can not be empty

Cause

The EDA entry in watches.yaml was missing snakeCaseParameters: False (the EDABackup and
EDARestore entries already have it). Without it, ansible-operator snake_cases the CR spec
recursively, so maxSkewmax_skew, topologyKeytopology_key, and so on. Those keys get
rendered into the Deployment, the API server prunes them as unknown fields, and the required fields
are left unset.

The Jinja templates are fine — they were already fixed in #275.

Fix

Add snakeCaseParameters: False to the EDA watch entry. Every EDA spec field the roles consume is
already snake_case, so the conversion isn't needed; the only camelCase fields in the CRD are native
Kubernetes structures that must stay camelCase.

This also fixes affinity (same problem) and strategy.rollingUpdate, which was silently falling
back to its 25% default instead of using the configured values.

Testing

Added a molecule check that patches the CR with a constraint and asserts the API Deployment renders
it with camelCase keys and the CR's values.

Note: watches.yaml is baked into the operator image, so this needs an image rebuild, not just a CR
reapply.

Assisted-by: Claude Opus 5 noreply@anthropic.com

Summary by CodeRabbit

  • New Features

    • Added support for configuring topology spread constraints for EDA API deployment pods.
    • API pods can now be distributed across nodes according to Kubernetes scheduling settings, including hostname-based spreading and scheduling preferences.
  • Bug Fixes

    • Preserved Kubernetes-native camelCase fields in topology spread constraints, preventing configuration values from being altered or discarded when applied.

@coderabbitai

coderabbitai Bot commented Sep 16, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: a28c6114-9545-42cb-90bb-45da70be4a39

📥 Commits

Reviewing files that changed from the base of the PR and between ffd471d and 8abb892.

📒 Files selected for processing (1)
  • watches.yaml

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The EDA watch now preserves embedded Kubernetes field names. A Molecule test verifies that API topology spread constraints render correctly in the API Deployment.

Changes

EDA topology spread propagation

Layer / File(s) Summary
Preserve and validate Kubernetes field names
watches.yaml, molecule/default/tasks/eda_test.yml
The EDA watch disables recursive snake_case conversion for embedded Kubernetes fields such as maxSkew and topologyKey. The test patches the EDA resource, waits for the API Deployment, and verifies the rendered constraint and camelCase keys.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 8abb8

No merge-blocking issue was identified for this focused field-preservation change.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: support for topology spread constraints and affinity in the EDA kind.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.


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

@kaiokmo kaiokmo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @snagoor, can you please rebase your branch on top of main? We had a CI issue that needed fixing. Thanks!

@snagoor

snagoor commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Hi @snagoor, can you please rebase your branch on top of main? We had a CI issue that needed fixing. Thanks!

Thank you @kaiokmo for the review. Now its rebased and pushed.

@ttuffin ttuffin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks for the PR

@kaiokmo kaiokmo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@snagoor I have just one small observation: since the main intent of this PR/commit became adding the topology spread constraints feature, could you please amend the commit so it reflects that in the title and make it meaningful for this purpose? The fix is something that needed to be done regardless so it can be explained in the commit body, but the main contribution here is the topology spread constraints, so I think the title could be updated.

Thanks in advance!

…for the EDA kind

topology_spread_constraints set on an EDA CR never made it into the
generated Deployments. The reconcile failed with an HTTP 422:

  spec.template.spec.topologySpreadConstraints[0].maxSkew:
    Invalid value: 0: must be greater than zero
  spec.template.spec.topologySpreadConstraints[0].topologyKey:
    Required value: can not be empty

Root cause: the EDA entry in watches.yaml was missing
snakeCaseParameters: False (EDABackup and EDARestore already set it).
Without it, ansible-operator snake_cases the CR spec recursively, so
maxSkew -> max_skew and topologyKey -> topology_key. Those keys were
rendered into the Deployment, the API server pruned them as unknown
fields, and the required fields were left unset.

Every EDA spec field the roles consume is already snake_case, so the
conversion is not needed; the only camelCase fields in the CRD are
native Kubernetes structures that must stay camelCase.

This also fixes affinity, which had the same problem, and
strategy.rollingUpdate, which was silently falling back to its 25%
default instead of using the configured values.

Add a molecule check that patches the CR with a constraint and asserts
the API Deployment renders it with camelCase keys and the CR's values.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@snagoor snagoor changed the title fix: [AAP-81880] disable snake_case parameter conversion for the EDA kind fix: [AAP-81880] support topology spread constraints (and affinity) for the EDA kind Sep 23, 2026
@snagoor

snagoor commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

@snagoor I have just one small observation: since the main intent of this PR/commit became adding the topology spread constraints feature, could you please amend the commit so it reflects that in the title and make it meaningful for this purpose? The fix is something that needed to be done regardless so it can be explained in the commit body, but the main contribution here is the topology spread constraints, so I think the title could be updated.

Thanks in advance!

Updated as requested.

@snagoor
snagoor requested a review from kaiokmo September 23, 2026 15:02

@kaiokmo kaiokmo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thank you!

@kaiokmo
kaiokmo merged commit 2ed3732 into ansible:main Sep 23, 2026
9 checks passed
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