tintoy / dotnet-kube-client

A Kubernetes API client for .NET Standard / .NET Core
MIT License
192 stars 33 forks source link

Cannot find resource API for kind for Istio CRD #138

Open linjmeyer opened 3 years ago

linjmeyer commented 3 years ago

Hi there, I use this client and have had really good luck with it, so thanks for providing this!

I tried to extend an internal tool to grab Istio DestinationRule resources but I am getting this error: KubeClient.KubeClientException: Cannot find resource API for kind 'DestinationRule', apiVersion 'networking.istio.io/v1beta1'

I'm fairly sure the code and API/kind is correct:

private readonly string ResourceKind = "DestinationRule";
private readonly string ResourceApi = "networking.istio.io/v1beta1";
var resourceList = await _kube.Dynamic().List(ResourceKind, ResourceApi);

An example object shows the API and Kind are correct:

apiVersion: networking.istio.io/v1beta1
kind: DestinationRule

This same code works for HPAs using HorizontalPodAutoscaler and autoscaling/v1 but happy to adjust if I am doing anything wrong here.

Thanks!

linjmeyer commented 3 years ago

Possibly related #114

tintoy commented 3 years ago

Hi :)

It's been a while since I looked through the dynamic resource client, but from what I remember it doesn't dynamically query the cluster's list of available resource types unless you explicitly ask it to (as this can add an unexpected degree of startup cost depending on how much configuration data is returned by the API and so default behaviour is to pre-populate it from type annotations on well-known resource models).

DynamicResourceClient has an ApiMetadata property which contains information about all known resource APIs, and you can tell it to load all resource type definitions from from the cluster using something like:

await _kubeApiClient.Dynamic().ApiMetadata.Load(_kubeApiClient, clearExisting: true);

(there should probably be an extension method on IDynamicResourceClient to do this)

tintoy commented 3 years ago

You can also define API models with annotations if you prefer and use them to populate the API metadata, using:

Assembly modelAssembly = typeof(MyModel).Assembly;

_kubeApiClient.Dynamic().ApiMetadata.LoadFromMetadata(modelAssembly, clearExisting: false);
tintoy commented 3 years ago

Ah, sorry, just had a closer look and the issue may be that the API version (v1beta1) is being used in preference to the API group-version (networking.isio.io/v1beta1). I'll see what I can do about that.

tintoy commented 3 years ago

Ok, I have a pull request open that will hopefully fix your problem, but I need to run it by a couple of our existing consumers / contributors to get their take on this 🙂

linjmeyer commented 3 years ago

Awesome thanks! Appreciate the quick turn around time on that, and the tip for the custom models is great too. Right now I just need the labels from the CRD resources but I'll likely need to extend that in the future.