Repository navigation
fix(karmadactl): print the same policy name as promote creates for cluster-scoped resources - #8097
BahaaMattar wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified in the change aligning printed and created policy names.
No open issues 🎉
What changed in this PR
Fixes #8096 by making karmadactl promote -o yaml|json print the same ClusterPropagationPolicy name that promotion creates, regardless of the kubeconfig context’s namespace.
Changes:
- Centralizes policy naming in a shared helper while preserving explicit
--policy-nameoverrides. - Uses an empty namespace when generating cluster-scoped policy names; namespaced policy names remain unchanged.
- Adds regression coverage comparing printed and created policy names for both resource scopes.
| File | Description |
|---|---|
pkg/karmadactl/promote/promote.go |
Shares naming logic across policy printing and creation, fixing cluster-scoped output. |
pkg/karmadactl/promote/promote_test.go |
Tests that printed and created policy names match for cluster-scoped and namespaced resources. |
Review effort: Balanced
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8097 +/- ##
==========================================
+ Coverage 42.46% 42.49% +0.02%
==========================================
Files 880 880
Lines 55483 55474 -9
==========================================
+ Hits 23563 23571 +8
+ Misses 30157 30140 -17
Partials 1763 1763
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…uster-scoped resources For a cluster-scoped resource, `promote -o yaml|json` generated the name of the ClusterPropagationPolicy from the namespace of the kubeconfig context, while promoting the resource for real generates it without a namespace. So the printed policy had a different name from the one that is created. Generate the policy name in one place, which doesn't take the namespace into account for a ClusterPropagationPolicy. Signed-off-by: Bahaa Mattar <bahaa.kmattar@gmail.com>
312a842 to
ebf8825
Compare
What type of PR is this?
/kind bug
What this PR does / why we need it:
karmadactl promote -o yaml|jsonprints the promoted resource and the PropagationPolicy (or ClusterPropagationPolicy) that promote would create. For a cluster-scoped resource the printed policy was named from the namespace of the kubeconfig context (names.GeneratePolicyName(o.Namespace, ...)), but promoting the resource for real creates the ClusterPropagationPolicy withnames.GeneratePolicyName("", ...). So the printed policy had a different name from the one that is created (and its name depended on the context's namespace).This PR adds one
policyName(namespace)helper (the--policy-namevalue, or the generated name) and uses it inprintObjectAndPolicy,createPropagationPolicyandcreateClusterPropagationPolicy. A ClusterPropagationPolicy is named without a namespace in all three places; namespaced resources keep their current names.TestPrintedPolicyNameMatchesCreatedPolicyprints the policy and creates it for a cluster-scoped and a namespaced resource and compares the names.Which issue(s) this PR fixes:
Fixes #8096
Special notes for your reviewer:
go test ./pkg/karmadactl/promote/...andgolangci-lint run ./pkg/karmadactl/promote/...pass. The new cluster-scoped case fails without the change:the printed policy is named "demo-clusterrole-5dc8bc456d", but promoting the resource creates the policy "demo-clusterrole-54499c54c". The namespaced case passes before and after.Behavior change: the generated name of a ClusterPropagationPolicy printed by
-o yaml|jsonchanges (it now matches what promote creates). The name of the policy that promote creates does not change.Does this PR introduce a user-facing change?: