Skip to content

Fix CRD processing to use served version instead of first version#508

Merged
yonahd merged 8 commits intomainfrom
copilot/fix-failed-to-process-crds
Oct 16, 2025
Merged

Fix CRD processing to use served version instead of first version#508
yonahd merged 8 commits intomainfrom
copilot/fix-failed-to-process-crds

Conversation

Copy link
Contributor

Copilot AI commented Oct 13, 2025

Problem

The kor crd command was failing with the error "the server could not find the requested resource" on systems with certain CRD configurations, particularly when CRDs have multiple versions where the first version is not served.

user@k3s:~# kor crd
Failed to process crds: the server could not find the requested resource

Root Cause

The code in processCrds() was incorrectly using crd.Spec.Versions[0].Name to determine which API version to query for CRD instances. This caused two issues:

  1. Wrong version selection: The first version in the array might have Served: false, meaning it's not available via the API server
  2. Overly strict error handling: Any error when querying instances would cause the entire command to fail

For example, a CRD might be defined as:

versions:
  - name: v1alpha1
    served: false    # Not available!
  - name: v1
    served: true     # This should be used

Solution

This PR fixes the issue by:

  1. Finding the first served version: Iterates through crd.Spec.Versions to find a version where Served: true
  2. Skipping CRDs with no served versions: If no served version is found, the CRD is skipped rather than causing a failure
  3. Graceful error handling: If querying a CRD fails (e.g., API server doesn't recognize it), skip it instead of failing the entire command

Changes

  • Modified processCrds() in pkg/kor/crds.go to properly select served versions
  • Added TestProcessCrds() in pkg/kor/crds_test.go to verify the fix with multiple test scenarios

Testing

The new test validates:

  • CRDs where the first version is not served (uses the first served version instead)
  • CRDs with no served versions (properly skipped)
  • CRDs with a served version (processed normally)

All existing tests continue to pass.

Fixes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>Failed to process crds</issue_title>
<issue_description>Describe the bug
Its very easy to describe:

user@k3s:~# kor crd
Failed to process crds: the server could not find the requested resource
kor version: v0.6.4

To Reproduce
Steps to reproduce the behavior:
kor crd

Expected behavior
I should get unused crds

OS version, architecture and kor version
Linux_arm64
Raspi
Kor version: 0.6.4
k3s 1.33.4

Additional context
k get crd is working:

user@k3s:~# k get crd
NAME                                                                   CREATED AT
accesscontrolpolicies.hub.traefik.io                                   2025-05-12T08:59:43Z
addons.k3s.cattle.io                                                   2024-09-25T15:52:30Z
aiservices.hub.traefik.io                                              2025-05-12T08:59:43Z
...

Don't no why that's not working...</issue_description>

<agent_instructions>The kor crds command finds names of crds that there are no crds of that type </agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #503


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@codecov-commenter
Copy link

codecov-commenter commented Oct 13, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 73.91304% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.55%. Comparing base (42443ec) to head (0c2d645).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
pkg/kor/crds.go 73.91% 4 Missing and 2 partials ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #508      +/-   ##
==========================================
+ Coverage   44.02%   44.55%   +0.52%     
==========================================
  Files          67       67              
  Lines        4502     4514      +12     
==========================================
+ Hits         1982     2011      +29     
+ Misses       2248     2222      -26     
- Partials      272      281       +9     

☔ View full report in Codecov by Sentry.
📢 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.

Co-authored-by: yonahd <47282577+yonahd@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix failure to process CRDs in kor Fix CRD processing to use served version instead of first version Oct 13, 2025
Copilot AI requested a review from yonahd October 13, 2025 07:03
@yonahd yonahd marked this pull request as ready for review October 13, 2025 13:42
@yonahd yonahd merged commit 113f46f into main Oct 16, 2025
1 check passed
@yonahd yonahd deleted the copilot/fix-failed-to-process-crds branch October 16, 2025 20:27
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.

Failed to process crds

3 participants