feat: Make resource lookup case-insensitive to match Kubernetes API behavior #2407
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andkubectl get Pod
work correctly. This PR makes the Python client's behavior consistent with the API server's behavior.Key changes
_find_resource_case_insensitive
method to theDiscoverer
classsearch
methods in bothLazyDiscoverer
andEagerDiscoverer
classes to: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?
Which issue(s) this PR fixes:
Fixes #2402