Skip to content

Adding affinity parameter in deployments#307

Merged
rooftopcellist merged 1 commit into
ansible:mainfrom
aldato:adaunis-affinity
Jul 7, 2026
Merged

Adding affinity parameter in deployments#307
rooftopcellist merged 1 commit into
ansible:mainfrom
aldato:adaunis-affinity

Conversation

@aldato

@aldato aldato commented Nov 14, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR adds the capability of managing the affinity of the different component deployments being used by EDA.

Changes

  • Added the necessary changes in the EDA CDR
  • Added the defaults for affinity
  • Added the required conditionals in the Jinja2 templates

Tests

I tested it using simple podAntiAffinity rules within the EDA CR under spec.event_stream with the following and it worked just fine (against the task pod of controller):

    task_affinity:
      podAntiAffinity:
        requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchExpressions:
            - key: app.kubernetes.io/name
              operator: In
              values:
              - automation-controller-task
          topologyKey: kubernetes.io/hostname

Summary by CodeRabbit

  • Bug Fixes
    • Added support for optional scheduling affinity settings across EDA deployments, including API, workers, event stream, and UI.
    • Corrected template rendering so scheduling rules are applied independently and consistently when set.
    • Ensured default configuration now includes an empty affinity section for all relevant deployment blocks.

@sonarqubecloud

Copy link
Copy Markdown

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

Thanks for adding affinity support across the EDA components — clean implementation that follows the right patterns. Two items to address before this is ready.

Comment thread roles/eda/templates/eda-scheduler.deployment.yaml.j2 Outdated
Comment thread roles/eda/defaults/main.yml
@coderabbitai

coderabbitai Bot commented Jul 3, 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: Enterprise

Run ID: 4bd1d2e5-f9b9-49d4-9010-395378ea4b53

📥 Commits

Reviewing files that changed from the base of the PR and between b6ba73d and 377b865.

📒 Files selected for processing (7)
  • config/crd/bases/eda.ansible.com_edas.yaml
  • roles/eda/defaults/main.yml
  • roles/eda/templates/eda-activation-worker.deployment.yaml.j2
  • roles/eda/templates/eda-api.deployment.yaml.j2
  • roles/eda/templates/eda-default-worker.deployment.yaml.j2
  • roles/eda/templates/eda-event-stream.deployment.yaml.j2
  • roles/eda/templates/eda-ui.deployment.yaml.j2
🚧 Files skipped from review as they are similar to previous changes (6)
  • roles/eda/templates/eda-activation-worker.deployment.yaml.j2
  • roles/eda/templates/eda-event-stream.deployment.yaml.j2
  • roles/eda/templates/eda-default-worker.deployment.yaml.j2
  • roles/eda/templates/eda-api.deployment.yaml.j2
  • roles/eda/templates/eda-ui.deployment.yaml.j2
  • roles/eda/defaults/main.yml

📝 Walkthrough

Walkthrough

This PR adds an empty affinity: {} default to five EDA deployment blocks in defaults/main.yml and fixes Jinja2 templates across API, default-worker, activation-worker, event-stream, and UI deployment templates by closing the topologySpreadConstraints conditional and adding a conditional affinity section rendered via to_nice_yaml.

Changes

Affinity support across EDA deployments

Layer / File(s) Summary
Default affinity values
roles/eda/defaults/main.yml
Adds an empty affinity: {} entry to the API, default-worker, activation-worker, event-stream, and UI deployment defaults blocks.
API deployment template affinity rendering
roles/eda/templates/eda-api.deployment.yaml.j2
Closes the topologySpreadConstraints conditional and adds a conditional affinity block rendered via to_nice_yaml when defined and non-empty.
Worker deployment templates affinity rendering
roles/eda/templates/eda-default-worker.deployment.yaml.j2, roles/eda/templates/eda-activation-worker.deployment.yaml.j2, roles/eda/templates/eda-event-stream.deployment.yaml.j2
Closes the topologySpreadConstraints conditional and adds conditional affinity rendering for default-worker, activation-worker, and event-stream deployments.
UI deployment template affinity rendering
roles/eda/templates/eda-ui.deployment.yaml.j2
Closes the topologySpreadConstraints conditional and adds a conditional affinity block for the UI deployment.

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

Related PRs: None found.

Suggested labels: enhancement, templates

Suggested reviewers: None specified.

🐰 A rabbit hops through templates neat,
Closing tags that once repeat,
Affinity now finds its place,
Empty braces with quiet grace,
Deployments spread with gentle feet.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding affinity support to the deployments.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
config/samples/eda_v1alpha1_eda.yaml (1)

28-37: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Nice addition addressing prior feedback; label selector value is only valid when deployment_type is eda.

The example hardcodes values: [eda-default-worker], but the rendered component label is {{ deployment_type }}-default-worker (per eda-default-worker.deployment.yaml.j2). Since this is commented-out sample text it won't break anything, just worth a caveat comment for non-default deployment_type deployments.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@config/samples/eda_v1alpha1_eda.yaml` around lines 28 - 37, The sample
anti-affinity example in eda_v1alpha1_eda.yaml hardcodes the worker label value
for the default deployment type, so add a caveat in the commented example that
the app.kubernetes.io/component value corresponds to the rendered {{
deployment_type }}-default-worker label from
eda-default-worker.deployment.yaml.j2 and only matches directly when
deployment_type is eda. Keep the existing sample structure, but clarify in the
comment that non-default deployment_type installations must adjust the selector
value accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@config/samples/eda_v1alpha1_eda.yaml`:
- Around line 28-37: The sample anti-affinity example in eda_v1alpha1_eda.yaml
hardcodes the worker label value for the default deployment type, so add a
caveat in the commented example that the app.kubernetes.io/component value
corresponds to the rendered {{ deployment_type }}-default-worker label from
eda-default-worker.deployment.yaml.j2 and only matches directly when
deployment_type is eda. Keep the existing sample structure, but clarify in the
comment that non-default deployment_type installations must adjust the selector
value accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: dce53cc3-f3f2-49a2-af39-0cddaf278dbe

📥 Commits

Reviewing files that changed from the base of the PR and between 9a630ef and b6ba73d.

📒 Files selected for processing (8)
  • config/crd/bases/eda.ansible.com_edas.yaml
  • config/samples/eda_v1alpha1_eda.yaml
  • roles/eda/defaults/main.yml
  • roles/eda/templates/eda-activation-worker.deployment.yaml.j2
  • roles/eda/templates/eda-api.deployment.yaml.j2
  • roles/eda/templates/eda-default-worker.deployment.yaml.j2
  • roles/eda/templates/eda-event-stream.deployment.yaml.j2
  • roles/eda/templates/eda-ui.deployment.yaml.j2

@rooftopcellist
rooftopcellist enabled auto-merge (squash) July 6, 2026 19:07
auto-merge was automatically disabled July 7, 2026 11:17

Head branch was pushed to by a user without write access

@aldato
aldato force-pushed the adaunis-affinity branch from b6ba73d to 377b865 Compare July 7, 2026 11:17
@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

@aldato
aldato requested a review from rooftopcellist July 7, 2026 11:19
@rooftopcellist
rooftopcellist merged commit 460e160 into ansible:main Jul 7, 2026
12 of 13 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