kubernetes-client icon indicating copy to clipboard operation
kubernetes-client copied to clipboard

Add mock handling for implicit generic support

Open shawkins opened this issue 3 years ago • 4 comments

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

shawkins avatar Mar 10 '22 13:03 shawkins

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.

shawkins avatar Mar 11 '22 13:03 shawkins

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!

stale[bot] avatar Jun 26 '22 06:06 stale[bot]

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:

  1. :heavy_check_mark: Mock server supports Custom Resources (CR)
  2. :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)
  3. :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
  4. :question: Mock server should fail when handling CRs or custom APIs which have not been previously installed

manusa avatar Jul 22 '22 07:07 manusa

  1. 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).
  2. Limited support exists in KubernetesServer, but not KuberenetesMockServer - you can pass a list of CustomResourceDefinitionContext.
  3. In crud mode it currently does not fail.

shawkins avatar Jul 22 '22 11:07 shawkins