Skip to content

fix: support resource proxy API group discovery#1001

Open
immanuwell wants to merge 1 commit into
argoproj-labs:mainfrom
immanuwell:fix/resource-proxy-group-discovery
Open

fix: support resource proxy API group discovery#1001
immanuwell wants to merge 1 commit into
argoproj-labs:mainfrom
immanuwell:fix/resource-proxy-group-discovery

Conversation

@immanuwell

@immanuwell immanuwell commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

What does this PR do / why we need it:
/apis/<group> is a valid Kubernetes discovery endpoint, but the resource proxy only matched /apis/<group>/<version>.

So discovery was kinda half-working. /apis/apps got rejected by the proxy before it ever reached the agent. This patch adds a dedicated matcher for group-only discovery and returns the matching APIGroup metadata from the agent.

Which issue(s) this PR fixes:
Related to #961

How to test changes / Special notes to the reviewer:
Repro for the old behavior:
/apis/apps => false
/apis/apps/v1 => true

Run:
go test ./principal -run 'TestResource(RequestRegexp|GroupRequestRegexp)' -count=1
go test ./agent -run Test_getAvailableAPIs -count=1
go test ./agent ./principal -count=1 -timeout=10m

Checklist

  • Documentation update is required by this PR (and has been updated) OR no documentation update is required.

Summary by CodeRabbit

  • New Features
    • Improved API group metadata retrieval to support lookups when only a group name is provided, including preferred version details.
    • Added support for handling Kubernetes API group discovery requests (e.g., /apis/<group>) during request routing.
  • Bug Fixes
    • Returns an error when a requested API group does not exist and no version is specified.
  • Tests
    • Added unit tests covering group-only metadata retrieval, missing-group error behavior, and API group discovery request matching.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ffb4af3b-e120-4528-be14-efb55a369777

📥 Commits

Reviewing files that changed from the base of the PR and between 02498bd and 8651f7c.

📒 Files selected for processing (5)
  • agent/resource.go
  • agent/resource_test.go
  • principal/resource.go
  • principal/resource_regex_test.go
  • principal/server.go
🚧 Files skipped from review as they are similar to previous changes (5)
  • principal/resource_regex_test.go
  • principal/resource.go
  • agent/resource.go
  • agent/resource_test.go
  • principal/server.go

📝 Walkthrough

Walkthrough

Adds support for Kubernetes API group discovery requests that specify a group but no version (/apis/<group>). The principal gains a new regex constant and a ResourceProxy request matcher routing these paths to processResourceRequest. The agent's getAvailableAPIs is updated to locate and return the matching APIGroup entry from ServerGroups(), or error when not found.

Changes

API Group Discovery Support

Layer / File(s) Summary
Principal regex and server routing for /apis/{group}
principal/resource.go, principal/server.go, principal/resource_regex_test.go
Adds resourceGroupRequestRegexp to match /apis/{group} paths with a named group capture. Wires a new ResourceProxy matcher using that regex to s.processResourceRequest in NewServer. A table-driven test verifies match/no-match behavior and the captured group value.
Agent getAvailableAPIs group-only handling and tests
agent/resource.go, agent/resource_test.go
getAvailableAPIs now locates the requested APIGroup in ServerGroups() when group != "" and version == "", serializes it as unstructured data for the response, and returns an error if the group is not found. Two new test cases cover the success path and the not-found error path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A group without version once caused quite a fuss,
Now the regex hops in and catches the bus!
ServerGroups() is queried, the answer returned,
A nil on not-found — a lesson well-learned.
The rabbit adds tests, ears up with delight,
/apis/apps now routes perfectly right! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: support resource proxy API group discovery' clearly and concisely summarizes the main change: adding support for API group discovery in the resource proxy.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Signed-off-by: immanuwell <pchpr.00@list.ru>
@immanuwell immanuwell force-pushed the fix/resource-proxy-group-discovery branch from 02498bd to 8651f7c Compare June 17, 2026 07:01
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.22222% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.04%. Comparing base (4a2c614) to head (8651f7c).

Files with missing lines Patch % Lines
principal/server.go 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1001      +/-   ##
==========================================
+ Coverage   48.02%   48.04%   +0.02%     
==========================================
  Files         123      123              
  Lines       18590    18607      +17     
==========================================
+ Hits         8928     8940      +12     
- Misses       8854     8859       +5     
  Partials      808      808              
Flag Coverage Δ
unit-tests 48.04% <72.22%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants