feat: add --as/--as-group/--as-uid impersonation flags#114
Conversation
Signed-off-by: Mike Ditton <mike.ditton@vshn.net>
Signed-off-by: Mike Ditton <mike.ditton@vshn.net>
Signed-off-by: Mike Ditton <mike.ditton@vshn.net>
Signed-off-by: Mike Ditton <mike.ditton@vshn.net>
Signed-off-by: Mike Ditton <mike.ditton@vshn.net>
Signed-off-by: Mike Ditton <mike.ditton@vshn.net>
Signed-off-by: Mike Ditton <mike.ditton@vshn.net>
|
Warning Review limit reached
More reviews will be available in 37 minutes and 53 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the 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 include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWait — I see I accidentally introduced a fabricated range id. Let me correct the artifact. WalkthroughAdds a shared ChangesKubernetes Impersonation Flag Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error)
✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@cmd/crossplane/trace/trace_test.go`:
- Around line 108-126: The impersonation parse tests across multiple files do
not follow the repository's table-driven test convention. Convert all four test
functions to table-driven structure:
cmd/crossplane/trace/trace_test.go#L108-L126 TestImpersonationFlagsParse should
use table cases with reason, args, and want fields for different flag
combinations; cmd/crossplane/top/top_test.go#L20-L35 TestImpersonationFlagsParse
should be refactored similarly but use diff-based assertions (cmp.Diff) instead
of manual error checks; cmd/crossplane/version/version_test.go#L25-L43 should
adopt table-driven structure with args and want fields for parse test cases;
cmd/crossplane/xpkg/impersonation_test.go#L25-L57 should fold the separate
install and update test logic into individual table-driven test cases (either as
a single table or two separate table-driven tests) with explicit reason fields
and expected impersonation field values. In all cases, use the standard pattern:
define a struct with test case fields, iterate over test cases, parse flags with
kong.New and Parse, and assert results using cmp.Diff for consistency with
repository coding guidelines.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 691564f3-cff2-4a70-b07d-10209e1e553a
📒 Files selected for processing (14)
cmd/crossplane/common/kube/impersonation.gocmd/crossplane/common/kube/impersonation_test.gocmd/crossplane/completion/completion.gocmd/crossplane/completion/completion_test.gocmd/crossplane/top/top.gocmd/crossplane/top/top_test.gocmd/crossplane/trace/trace.gocmd/crossplane/trace/trace_test.gocmd/crossplane/version/fetch.gocmd/crossplane/version/version.gocmd/crossplane/version/version_test.gocmd/crossplane/xpkg/impersonation_test.gocmd/crossplane/xpkg/install.gocmd/crossplane/xpkg/update.go
Signed-off-by: Mike Ditton <mike.ditton@vshn.net>
Description of your changes
Adds the kubectl-compatible impersonation flags as, as-group, and as-uid to every CLI command that talks to a cluster. This lets you run a command as a different user, group, or service account without switching your kubeconfig context.
The flags are defined once in a shared ImpersonationFlags struct and embedded into each command. After a command builds its client config, it applies the flags, which sets the impersonation fields on the request. This works for every command regardless of how it loads its config.
Commands covered: resource trace, cluster top, version, xpkg install, xpkg update, and the shell-completion predictors.
The behavior matches kubectl: the flag names and help text are the same, as-group is repeatable, there are no short forms, and validation is left to the API server.
Fixes #110
I have:
./nix.sh flake checkto ensure this PR is ready for review.Linked a PR or a docs tracking issue to document this change.Addedbackport release-x.ylabels to auto-backport this PR.Need help with this checklist? See the cheat sheet.