python icon indicating copy to clipboard operation
python copied to clipboard

feat: Make resource lookup case-insensitive to match Kubernetes API behavior

Open Kevinz857 opened this issue 7 months ago • 2 comments

Make Resource Lookup Case-Insensitive to Match Kubernetes API Behavior

What type of PR is this?

/kind feature /kind bug

What this PR does / why we need it

This PR implements case-insensitive resource lookup in the dynamic client to match the actual behavior of the Kubernetes API. Currently, when using the dynamic client to look up resources, the search is case-sensitive, which causes issues when users attempt to look up resources with different casing than what's defined in the API server.

The Kubernetes API itself is case-insensitive when it comes to resource kinds. For example, both kubectl get pod and kubectl get Pod work correctly. This PR makes the Python client's behavior consistent with the API server's behavior.

Key changes

  • Added a _find_resource_case_insensitive method to the Discoverer class
  • Modified the search methods in both LazyDiscoverer and EagerDiscoverer classes to:
    • First try exact case matching (original behavior)
    • If no match is found and a kind is specified, attempt case-insensitive lookup
    • On failure, refresh the cache and retry both strategies
  • Added test cases to verify case-insensitive lookup functionality

Special notes for your reviewer

This change is backward compatible with existing code as it maintains the same behavior for exact case matches. It only adds the additional capability to find resources when the case doesn't exactly match.

Does this PR introduce a user-facing change?

Make resource lookup case-insensitive in the dynamic client to match Kubernetes API behavior

Which issue(s) this PR fixes:

Fixes #2402

Kevinz857 avatar May 31 '25 10:05 Kevinz857

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Kevinz857 Once this PR has been reviewed and has the lgtm label, please assign roycaihw for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment Approvers can cancel approval by writing /approve cancel in a comment

k8s-ci-robot avatar May 31 '25 10:05 k8s-ci-robot

/assign @fabianvf

roycaihw avatar Jun 04 '25 20:06 roycaihw

The Kubernetes API itself is case-insensitive when it comes to resource kinds. For example, both kubectl get pod and kubectl get Pod work correctly. This PR makes the Python client's behavior consistent with the API server's behavior.

I think the case-insensitive behavior comes from kubectl. Kubernetes API server is case sensitive. One can verify that by running kubectl with --v=9 to check the actual API request.

IIRC other clients like client-go are also case-sensitive.

/priority awaiting-more-evidence

roycaihw avatar Jun 24 '25 20:06 roycaihw

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Sep 22 '25 20:09 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Oct 22 '25 21:10 k8s-triage-robot