Skip to content

Added TopologyKey to noobaa CRD for multizone support#1653

Merged
dannyzaken merged 1 commit intonoobaa:masterfrom
dannyzaken:danny-fixes
Jul 15, 2025
Merged

Added TopologyKey to noobaa CRD for multizone support#1653
dannyzaken merged 1 commit intonoobaa:masterfrom
dannyzaken:danny-fixes

Conversation

@dannyzaken
Copy link
Member

@dannyzaken dannyzaken commented Jul 9, 2025

Explain the changes

  • Changed affinity under Noobaa spec to a new struct AffinitySpec,
    containing the same fields as corev1.Affinity
  • Added TopologyKey to AffinitySpec. This can be used for example to set topology.kubernetes.io/zone as the topology domain
  • If a topologyKey is used and is different from the default kubernetes.io/hostname TopologyKey, adding another TopologySpreadConstraint with the additional key.
  • Passing the TopologyKey to the DB cluster CR under affinity. This will be set to the podAntiAffinity of the DB pods.

Issues: Fixed #xxx / Gap #xxx

  1. https://issues.redhat.com/browse/DFBUGS-2826

Testing Instructions:

  • Doc added/updated
  • Tests added

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added support for specifying a custom topology key to control pod distribution for endpoints and database pods. This allows for more flexible placement across topology domains such as host or zone.
  • Enhancements

    • Improved handling of pod scheduling constraints by honoring the custom topology key when set, in addition to the default behavior.
    • Updated pod affinity and topology spread logic to better support multiple topology constraints and feature gates for pod placement.

@coderabbitai
Copy link

coderabbitai bot commented Jul 9, 2025

Warning

Rate limit exceeded

@dannyzaken has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 16 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c6a1352 and 2ff0273.

📒 Files selected for processing (9)
  • deploy/crds/noobaa.io_noobaas.yaml (1 hunks)
  • pkg/apis/noobaa/v1alpha1/noobaa_types.go (3 hunks)
  • pkg/apis/noobaa/v1alpha1/zz_generated.deepcopy.go (15 hunks)
  • pkg/backingstore/reconciler.go (1 hunks)
  • pkg/bundle/deploy.go (2 hunks)
  • pkg/system/db_reconciler.go (2 hunks)
  • pkg/system/phase2_creating.go (2 hunks)
  • pkg/system/phase4_configuring.go (3 hunks)
  • pkg/system/reconciler.go (1 hunks)

Walkthrough

A new optional TopologyKey field was added to the NooBaaSpec struct to control pod distribution across topology domains. Supporting logic was introduced in the deployment, database, and backing store reconciler code to use this field for configuring topology spread constraints and affinity. Change detection was updated to include this field. The affinity configuration was refactored to use a new AffinitySpec struct encapsulating Kubernetes affinity types.

Changes

File(s) Change Summary
pkg/apis/noobaa/v1alpha1/noobaa_types.go Changed Affinity field in NooBaaSpec from *corev1.Affinity to *AffinitySpec struct; added TopologyKey field and affinity subfields.
pkg/apis/noobaa/v1alpha1/zz_generated.deepcopy.go Added deepcopy methods for new AffinitySpec type; updated import aliases and references to affinity types.
pkg/system/reconciler.go Added GetAffinity() method returning a corev1.Affinity built from AffinitySpec.
pkg/system/phase2_creating.go Replaced direct affinity assignment with GetAffinity() call in pod specs for DB and core app deployments.
pkg/system/phase4_configuring.go Updated endpoint deployment to use GetAffinity(); conditionally added extra TopologySpreadConstraint if TopologyKey is set and differs from default.
pkg/system/db_reconciler.go Handled new TopologyKey field in cluster spec reconciliation and change detection.
pkg/backingstore/reconciler.go Changed affinity assignment to explicitly copy subfields from AffinitySpec to new corev1.Affinity struct.
deploy/crds/noobaa.io_noobaas.yaml Added optional topologyKey string property under spec.affinity in NooBaa CRD schema.
pkg/bundle/deploy.go Updated SHA256 checksum for CRD YAML; added topologyKey field in CRD schema under podAntiAffinity affinity spec.
pkg/options/options.go Updated constant ContainerImageTag to a newer tag version.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant NooBaa Controller
    participant Kubernetes API

    User->>NooBaa Controller: Set/Update NooBaa.Spec.TopologyKey
    NooBaa Controller->>NooBaa Controller: Reconcile NooBaa resource
    NooBaa Controller->>NooBaa Controller: Build Affinity via GetAffinity()
    NooBaa Controller->>Kubernetes API: Update Deployment/Cluster Spec with Affinity and TopologyKey
    alt TopologyKey is set and differs from default
        NooBaa Controller->>Kubernetes API: Add extra TopologySpreadConstraint with TopologyKey
    else TopologyKey is unset or default
        NooBaa Controller->>Kubernetes API: Use default TopologySpreadConstraint
    end
    Kubernetes API-->>NooBaa Controller: Apply changes to pods
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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

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.

@dannyzaken dannyzaken removed the request for review from naveenpaul1 July 9, 2025 14:25
@dannyzaken dannyzaken marked this pull request as draft July 9, 2025 14:26
@dannyzaken dannyzaken requested a review from naveenpaul1 July 13, 2025 14:04
@pull-request-size pull-request-size bot added size/M and removed size/S labels Jul 13, 2025
@dannyzaken dannyzaken force-pushed the danny-fixes branch 2 times, most recently from 6453235 to a65e325 Compare July 13, 2025 14:39
@dannyzaken dannyzaken marked this pull request as ready for review July 13, 2025 14:40
Copy link

@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: 0

🧹 Nitpick comments (1)
pkg/bundle/deploy.go (1)

2414-2415: Consider adding validation and description to the topologyKey field.

The topologyKey field addition looks good and aligns with the PR objective for multizone support. However, consider enhancing the schema definition:

                  topologyKey:
+                   description: "TopologyKey used as the domain for TopologySpreadConstraint and affinity settings of NooBaa components. Examples include 'kubernetes.io/hostname' for host-level distribution or 'topology.kubernetes.io/zone' for zone-level distribution."
                    type: string
+                   pattern: "^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*(/[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$"

The pattern validation ensures the field follows Kubernetes label/annotation naming conventions for topology keys.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36698a5 and a65e325.

📒 Files selected for processing (9)
  • deploy/crds/noobaa.io_noobaas.yaml (1 hunks)
  • pkg/apis/noobaa/v1alpha1/noobaa_types.go (2 hunks)
  • pkg/apis/noobaa/v1alpha1/zz_generated.deepcopy.go (15 hunks)
  • pkg/backingstore/reconciler.go (1 hunks)
  • pkg/bundle/deploy.go (2 hunks)
  • pkg/system/db_reconciler.go (2 hunks)
  • pkg/system/phase2_creating.go (2 hunks)
  • pkg/system/phase4_configuring.go (3 hunks)
  • pkg/system/reconciler.go (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • pkg/system/phase2_creating.go
  • pkg/system/reconciler.go
  • deploy/crds/noobaa.io_noobaas.yaml
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/system/db_reconciler.go
  • pkg/system/phase4_configuring.go
🧰 Additional context used
🧠 Learnings (2)
pkg/backingstore/reconciler.go (1)
Learnt from: Neon-White
PR: noobaa/noobaa-operator#1636
File: pkg/backingstore/reconciler.go:718-724
Timestamp: 2025-06-25T15:28:44.080Z
Learning: In pkg/backingstore/reconciler.go, the switch refactor for S3Compatible.SignatureVersion and IBMCos.SignatureVersion maintains the same behavior as the original if-else if logic - when SignatureVersion is empty or unspecified, conn.AuthMethod is left unset. There was no default to V4 in the original code.
pkg/apis/noobaa/v1alpha1/zz_generated.deepcopy.go (1)
Learnt from: Neon-White
PR: noobaa/noobaa-operator#1636
File: pkg/backingstore/reconciler.go:718-724
Timestamp: 2025-06-25T15:28:44.080Z
Learning: In pkg/backingstore/reconciler.go, the switch refactor for S3Compatible.SignatureVersion and IBMCos.SignatureVersion maintains the same behavior as the original if-else if logic - when SignatureVersion is empty or unspecified, conn.AuthMethod is left unset. There was no default to V4 in the original code.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: run-operator-tests
  • GitHub Check: run-cli-tests
  • GitHub Check: run-core-config-map-tests
  • GitHub Check: cnpg-deployment-test
  • GitHub Check: run-hac-test
  • GitHub Check: run-admission-test
  • GitHub Check: run-kms-kmip-test
  • GitHub Check: run-kms-key-rotate-test
  • GitHub Check: run-kms-dev-test
  • GitHub Check: run-kms-tls-sa-test
  • GitHub Check: run-azure-vault-test
  • GitHub Check: run-kms-tls-token-test
🔇 Additional comments (6)
pkg/backingstore/reconciler.go (1)

1332-1336: LGTM: Correct adaptation to new AffinitySpec structure.

The change properly adapts to the new AffinitySpec structure by explicitly constructing a corev1.Affinity struct from the three standard Kubernetes affinity types. This maintains the same functionality while accommodating the addition of the TopologyKey field in the new affinity specification.

pkg/bundle/deploy.go (1)

1426-1426: LGTM: Checksum updated correctly.

The SHA256 checksum update reflects the changes made to the underlying CRD YAML content, specifically the addition of the topologyKey field to the affinity specification.

pkg/apis/noobaa/v1alpha1/noobaa_types.go (2)

160-160: Good design pattern for extending Kubernetes affinity configuration.

The change from *corev1.Affinity to *AffinitySpec follows a good extension pattern that maintains the original Kubernetes affinity semantics while adding custom functionality for topology support.


245-260: Well-structured AffinitySpec design for multizone support.

The new AffinitySpec struct effectively wraps the standard Kubernetes affinity types and adds the TopologyKey field for topology-aware scheduling. The field documentation clearly explains the purpose and usage.

Note: The protobuf tags on lines 249, 252, and 255 may not be necessary for this custom struct, but they maintain consistency with Kubernetes API conventions.

pkg/apis/noobaa/v1alpha1/zz_generated.deepcopy.go (2)

13-14: Import alias changes are consistent.

The import alias changes (corev1v1 and addition of conditionsv1) are applied consistently throughout the autogenerated file.


83-112: AffinitySpec deepcopy implementation is correct.

The autogenerated deepcopy methods for AffinitySpec properly handle:

  • Nil checks for each optional affinity field (lines 86, 91, 96)
  • Deep copying of nested Kubernetes affinity objects (lines 88-89, 93-94, 98-99)
  • The TopologyKey string field is correctly copied via the *out = *in assignment on line 85

Copy link
Contributor

@naveenpaul1 naveenpaul1 left a comment

Choose a reason for hiding this comment

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

LGTM

type: array
x-kubernetes-list-type: atomic
type: object
topologyKey:
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please update the doc doc/noobaa-crd.md.

Copy link
Member Author

@dannyzaken dannyzaken Jul 15, 2025

Choose a reason for hiding this comment

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

I will create a separate PR with changes to noobaa-crd.md, that also includes updates regarding the dbSpec

@dannyzaken
Copy link
Member Author

@naveenpaul1, I noticed now that we do not update the topologySpreadConstraints if it is already set. Since we want it to be updated if a topologyKey is supplied, I think we should always reconcile it unless the annotation is set, WDYT?

@dannyzaken dannyzaken force-pushed the danny-fixes branch 5 times, most recently from c6a1352 to fdf81e8 Compare July 15, 2025 16:40
- Changed `affinity` under Noobaa spec to a new struct `AffinitySpec`,
  containing the same fields as corev1.Affinity
- Added `TopologyKey` to AffinitySpec. This can be used for example to set `topology.kubernetes.io/zone` as the topology domain
- If a topologyKey is used and is different from the default `kubernetes.io/hostname` TopologyKey, adding another TopologySpreadConstraint with the additional key.
- Passing the TopologyKey to the DB cluster CR under affinity. This will be set to the podAntiAffinity of the DB pods.

Signed-off-by: Danny Zaken <dannyzaken@gmail.com>

updated core ContainerImageTag

Signed-off-by: Danny Zaken <dannyzaken@gmail.com>
@dannyzaken dannyzaken merged commit 7ed7521 into noobaa:master Jul 15, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants