-
Notifications
You must be signed in to change notification settings - Fork 8
refactor: update namespace sync configuration to use label selector #1408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Changed `targetNamespaceLabelKey` to `targetNamespaceLabelSelector` in `values.yaml` for clarity. - Updated deployment template to reflect the new label selector usage. - Modified main application logic to validate and parse the label selector. - Removed deprecated `IsTargetNamespace` function in favor of a more flexible label selector approach. - Adjusted related tests and documentation accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the namespace sync configuration to use a more flexible label selector approach instead of a simple label key check. The change allows for more sophisticated namespace targeting using Kubernetes label selectors (e.g., environment=production or team in (platform,infrastructure)). Additionally, it adds context cancellation checks in loops to prevent potential goroutine leaks when operations are cancelled.
Key changes:
- Replaced
targetNamespaceLabelKeywithtargetNamespaceLabelSelectorthroughout the codebase - Added context cancellation checks in
walkReferencesandReconcileloops - Removed the deprecated
NamespaceHasLabelKeyfunction and its tests - Updated configuration files and command-line flags to support the new label selector format
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/controllers/namespacesync/suite_test.go | Updated test setup to parse and use label selector instead of label key |
| pkg/controllers/namespacesync/references.go | Added context cancellation check in loop to prevent goroutine leaks |
| pkg/controllers/namespacesync/label_test.go | Removed tests for deprecated NamespaceHasLabelKey function |
| pkg/controllers/namespacesync/label.go | Removed deprecated NamespaceHasLabelKey function |
| pkg/controllers/namespacesync/flags.go | Added new label selector flag and deprecated old label key flag |
| pkg/controllers/namespacesync/copy.go | Removed commented-out code for zeroing ManagedFields and OwnerReferences |
| pkg/controllers/namespacesync/controller.go | Refactored to use label selector with pre-allocated slices and added context checks |
| cmd/main.go | Added label selector parsing and validation logic |
| charts/cluster-api-runtime-extensions-nutanix/values.yaml | Updated configuration key from targetNamespaceLabelKey to targetNamespaceLabelSelector |
| charts/cluster-api-runtime-extensions-nutanix/values.schema.json | Updated schema to reflect new configuration key |
| charts/cluster-api-runtime-extensions-nutanix/templates/deployment.yaml | Updated deployment template to use new label selector flag |
| charts/cluster-api-runtime-extensions-nutanix/README.md | Updated documentation to reflect new configuration parameter |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| | namespaceSync.enabled | bool | `true` | | | ||
| | namespaceSync.sourceNamespace | string | `""` | | | ||
| | namespaceSync.targetNamespaceLabelKey | string | `"caren.nutanix.com/namespace-sync"` | | | ||
| | namespaceSync.targetNamespaceLabelSelector | string | `"caren.nutanix.com/namespace-sync"` | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example needs to change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's actually the default and it's still fine, it's a label expression which means label exists, matching the existing behaviour.
cff17a1 to
468bb51
Compare
dlipovetsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvement. Thanks!
What problem does this PR solve?:
Refactoring to simplify the label selector logic. This allows for preallocation of slices.
targetNamespaceLabelKeytotargetNamespaceLabelSelectorinvalues.yamlfor clarity.IsTargetNamespacefunction in favor of a more flexible label selector approach.Also correctly handle context timeouts in copy functions in order to ensure there are no goroutine leaks.
Which issue(s) this PR fixes:
Fixes #
How Has This Been Tested?:
Special notes for your reviewer: