Skip to content

fix(actions): target the correct API group when two kinds collide - #566

Merged
janosmiko merged 2 commits into
mainfrom
fix/562-api-group-collision
Jul 27, 2026
Merged

fix(actions): target the correct API group when two kinds collide#566
janosmiko merged 2 commits into
mainfrom
fix/562-api-group-collision

Conversation

@janosmiko

Copy link
Copy Markdown
Owner

Fixes #562.

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 distinct causes.

1. kubectl invocations passed the bare plural

kubectl describe mykinds my-instance is ambiguous the moment two groups define the same Kind — kubectl resolves it to whichever group discovery returns first.

New kubectlResourceArg(rt) returns resource.group when the type has an API group, and the bare plural for core types. The group is always at hand: the ResourceTypeEntry the action launched from carries it.

Call site File
describe, edit commands_exec.go
force delete, finalizer patch commands_exec_misc.go
bulk finalizer patch, bulk force delete commands_bulk.go

2. Owner navigation parsed the group, then dropped it

handleExplorerActionKeyJumpOwner reads apiVersion||kind||name off the owner-reference column and called navigateToOwner(kind, name), which resolved through model.FindResourceTypeByKind — documented first-match-wins across groups.

navigateToOwner now takes the apiVersion and resolves through FindResourceTypeByKindAndGroup, falling back to the Kind-only lookup when the caller has no apiVersion (built-in Pod / Node jumps) 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 is namespace/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 targets
  • internal/app/navigate_owner_group_test.go — 5 cases: both groups resolve correctly, core-group owner, and both fallbacks
  • go test -race ./... — all packages pass
  • golangci-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.

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
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5e934db9-a7b8-4dcb-8b30-37277cf70bc8

📥 Commits

Reviewing files that changed from the base of the PR and between c8c4eea and fc0a7fe.

📒 Files selected for processing (12)
  • internal/app/commands_bulk.go
  • internal/app/commands_exec.go
  • internal/app/commands_exec_misc.go
  • internal/app/jump_history_test.go
  • internal/app/kubectl_args.go
  • internal/app/kubectl_args_test.go
  • internal/app/navigate_owner_group_test.go
  • internal/app/update_actions_helm_misc.go
  • internal/app/update_keys_actions.go
  • internal/app/update_navigation.go
  • internal/app/update_navigation_test.go
  • internal/app/update_overlays_logs.go

Summary by CodeRabbit

  • Bug Fixes

    • Improved navigation to owner resources when multiple resource types share the same kind, using API version and group information for more accurate results.
    • Improved Kubernetes resource targeting for editing, describing, patching, and force-deleting grouped resources.
    • Preserved fallback behavior when API version information is unavailable or cannot be resolved.
  • Tests

    • Added coverage for grouped resource disambiguation, owner navigation, and Kubernetes command targeting.

Walkthrough

The 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 72.73% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary fix for API-group collisions in actions.
Description check ✅ Passed The description covers the bug, the fix, related issue, and testing, though it doesn’t use every template section verbatim.
Linked Issues check ✅ Passed The changes address #562 by qualifying kubectl resource args and preserving apiVersion for owner navigation.
Out of Scope Changes check ✅ Passed The diff stays focused on group disambiguation and related tests, with no unrelated feature work.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@janosmiko
janosmiko merged commit 5eddf5f into main Jul 27, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: same kind for different group conflict

1 participant