fix: use fleet-/kube- prefix checks in fleet guard rail#1102
fix: use fleet-/kube- prefix checks in fleet guard rail#1102Arvindthiru merged 3 commits intoAzure:mainfrom
Conversation
Title(Describe updated until commit 3e0f15d)fix: use fleet-/kube- prefix checks in fleet guard rail User descriptionDescription of your changesCurrently the fleet guard rail prevents users from creating namespaces with fleet/kube prefix instead of fleet-/kube- prefix. This PR fixes that issue and I moved some code around to reuse code. Eg: fleettest, kubetest namespaces will be prevented from being created which is not ideal Fixes # I have:
How has this code been testedSpecial notes for your reviewerPR TypeEnhancement Description
Changes walkthrough 📝
|
PR Reviewer Guide 🔍(Review updated until commit 3e0f15d)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 6c32d3e
Previous suggestionsSuggestions up to commit 468009c
|
|
Persistent review updated to latest commit 6c32d3e |
There was a problem hiding this comment.
Pull Request Overview
This pull request refactors the fleet resource webhook and test logic to enforce the use of consistent fleet- and kube- prefixed namespace names while updating log messages accordingly.
- Updated test cases to validate allowed operations based on the new namespace prefix rules.
- Refactored webhook code to use utility functions (IsFleetMemberNamespace and IsReservedNamespace) for prefix checks.
- Updated constants and formatting in the common utilities to support fleet member namespace naming.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/webhook/fleetresourcehandler/fleetresourcehandler_webhook_test.go | Added and renamed test cases to verify behavior with updated namespace prefix logic. |
| pkg/webhook/fleetresourcehandler/fleetresourcehandler_webhook.go | Replaced direct prefix checks with utility functions and updated logging messages to use defined constants. |
| pkg/utils/common.go | Introduced a new constant for fleet member namespace and added a helper function for its check. |
Comments suppressed due to low confidence (2)
pkg/webhook/fleetresourcehandler/fleetresourcehandler_webhook.go:177
- [nitpick] Consider renaming the constant 'allowedMessageNonReservedNamespace' to something like 'allowedMessageForNonReservedNamespace' to better reflect its purpose, improving readability in the logs.
klog.V(3).InfoS(allowedMessageNonReservedNamespace,
pkg/webhook/fleetresourcehandler/fleetresourcehandler_webhook_test.go:976
- [nitpick] For consistency, consider reviewing and standardizing the phrasing used in test case descriptions across non-reserved namespace tests.
"allow any user to modify non-reserved namespace": {
There was a problem hiding this comment.
Pull Request Overview
This pull request fixes the prefix check logic for fleet and kube resources by replacing hard-coded string checks with helper functions and updating the corresponding log and admission messages. Key changes include:
- Adding new test cases for member cluster and namespace handling scenarios.
- Refactoring webhook logic to use centralized helper functions from pkg/utils/common.go for prefix checks.
- Updating log and admission response messages to use well-defined constants.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/webhook/fleetresourcehandler/fleetresourcehandler_webhook_test.go | Added test cases and updated expected admission responses using constants. |
| pkg/webhook/fleetresourcehandler/fleetresourcehandler_webhook.go | Replaced inline prefix checks with helper functions and updated log messages. |
| pkg/utils/common.go | Introduced a new helper function for detecting fleet member namespaces and updated prefix constants. |
Comments suppressed due to low confidence (2)
pkg/webhook/fleetresourcehandler/fleetresourcehandler_webhook_test.go:981
- [nitpick] Test cases use 'testUser' here while other tests use 'test-user'; consider standardizing the username format for consistency.
Username: "testUser",
pkg/webhook/fleetresourcehandler/fleetresourcehandler_webhook.go:161
- [nitpick] The log message constant 'allowedMessageFleetReservedNamespacedResource' is slightly verbose; consider simplifying or clarifying the message text for better readability.
klog.V(3).InfoS(allowedMessageFleetReservedNamespacedResource,
michaelawyu
left a comment
There was a problem hiding this comment.
A few minor comments, PTAL
|
Persistent review updated to latest commit 3e0f15d |
Description of your changes
Currently the fleet guard rail prevents users from creating namespaces with fleet/kube prefix instead of fleet-/kube- prefix.
This PR fixes that issue and I moved some code around to reuse code.
Eg: fleettest, kubetest namespaces will be prevented from being created which is not ideal
Fixes #
I have:
make reviewableto ensure this PR is ready for review.How has this code been tested
Special notes for your reviewer