fix(actions): target the correct API group when two kinds collide - #566
Conversation
With two CRDs sharing a Kind across groups (foo.com and bar.com), actions on an instance of one hit the other: Error from server (NotFound): foo.com "my-instance" not found Two causes. Every kubectl invocation passed the bare plural (kubectl describe mykinds my-instance). A bare plural is ambiguous across groups, and kubectl resolves it to whichever group discovery returns first. Address resources as "resource.group" instead, keeping the bare form for core types, via a single kubectlResourceArg helper used by describe, edit, force delete, finalizer patch, bulk patch and bulk delete. The group is always at hand -- the ResourceTypeEntry the action launched from carries it. Owner-reference navigation parsed the owner's apiVersion and then discarded it, resolving through FindResourceTypeByKind, which is documented first-match-wins across groups. Thread the apiVersion into navigateToOwner and resolve through FindResourceTypeByKindAndGroup, falling back to the Kind-only lookup when the caller has no apiVersion or names a group this cluster never discovered -- a best-effort jump beats a dead end. Two Kind-only lookups are left alone: the security-finding jump, whose "namespace/Kind/name" key carries no group, and the orphan jump, whose detector only emits core kinds that cannot collide. Fixes #562
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (12)
Summary by CodeRabbit
WalkthroughThe change adds API-group-aware kubectl resource argument formatting and applies it to edit, describe, patch, delete, and bulk force-delete commands. Owner navigation now resolves resource types using the owner reference’s API version, handles core resources, and falls back to kind-only matching when needed. Navigation callers and related tests now pass the API version explicitly. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
Fixes #562.
With two CRDs sharing a Kind across groups (
foo.comandbar.com), actions on an instance of one hit the other:Two distinct causes.
1. kubectl invocations passed the bare plural
kubectl describe mykinds my-instanceis ambiguous the moment two groups define the same Kind — kubectl resolves it to whichever group discovery returns first.New
kubectlResourceArg(rt)returnsresource.groupwhen the type has an API group, and the bare plural for core types. The group is always at hand: theResourceTypeEntrythe action launched from carries it.commands_exec.gocommands_exec_misc.gocommands_bulk.go2. Owner navigation parsed the group, then dropped it
handleExplorerActionKeyJumpOwnerreadsapiVersion||kind||nameoff the owner-reference column and callednavigateToOwner(kind, name), which resolved throughmodel.FindResourceTypeByKind— documented first-match-wins across groups.navigateToOwnernow takes the apiVersion and resolves throughFindResourceTypeByKindAndGroup, falling back to the Kind-only lookup when the caller has no apiVersion (built-inPod/Nodejumps) or names a group this cluster never discovered — a best-effort jump beats a dead end.Left alone, deliberately
Two Kind-only lookups have no group available without changing the data feeding them:
jumpToFindingResource— the security-finding__resource_key__column isnamespace/Kind/name; qualifying it means changing the producer's key format.jumpToOrphan— the orphan detector only emits core kinds (Pod, Secret, ConfigMap, Service), which cannot collide.Worth a follow-up if the reporter sees the bug outside actions and owner jumps.
Test plan
internal/app/kubectl_args_test.go— 7 cases including the same-Kind-different-group pair producing different targetsinternal/app/navigate_owner_group_test.go— 5 cases: both groups resolve correctly, core-group owner, and both fallbacksgo test -race ./...— all packages passgolangci-lint run ./...— 0 issues@duizabojul — if you can, testing this branch against your two CRDs would confirm the fix covers the places you hit it.