kubernetes-client
kubernetes-client copied to clipboard
Add mock handling for implicit generic support
Is your task related to a problem? Please describe
When using the built-in mock server the metadata will be missing for a generic resource.
Describe the solution you'd like
There should be a way either against the client or the mock server to register a ResourceDefinitionContext for testing purposes.
Currently when you use the entry point client.genericKubernetesResources(context) - that context is not cached / saved, it is only used locally for that operation.
Describe alternatives you've considered
No response
Additional context
No response
Based upon https://github.com/fabric8io/kubernetes-client/discussions/3941#discussioncomment-2339277 a quick implementation would be something like KubernetesMockServer.defineType(ResourceDefinitionContext) - and it would automatically setup the needed expectations.
Based upon https://github.com/fabric8io/kubernetes-client/discussions/3941#discussioncomment-2339347 you could also consider a more crud based approach to the api resources.
Or there is existing CRD aware logic in the mock server - that is already inferring the plurals so we could actually extend this to return the full api endpoint metadata as well.
This is also making me think we should just remove the proposed EnableKubernetesMockClient.unsupported - and instead let that be driven off of methods on the KubernetesMockClient.
This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!
I've missed this issue. Last month I spent some time refactoring the Mock Server CRUD mode and I was thinking that we were missing something related to what's requested here.
Please check the following list of properties for the CRUD mode to see if we're aligned and can we establish some sort of spec to implement the missing features:
- :heavy_check_mark: Mock server supports Custom Resources (CR)
- :question: Custom Resource Definitions (CRD) can be "installed" and allow the usage of custom APIs just like any other resource (IIRC this should be implemented too)
- :heavy_multiplication_x: Mock Server can be preset with a set of custom resources or custom APIs
- The workaround is to add create/install the CRDs in a setup/before method
- :question: Mock server should fail when handling CRs or custom APIs which have not been previously installed
- Limited support exists. See the handling in KubernetesAttributesExtractor. Currently the crd information is only used to determine if the resource has a status sub-resource and to determine the plural from the resource (I can't remember why that's needed).
- Limited support exists in KubernetesServer, but not KuberenetesMockServer - you can pass a list of CustomResourceDefinitionContext.
- In crud mode it currently does not fail.