dotnet-kube-client icon indicating copy to clipboard operation
dotnet-kube-client copied to clipboard

Cannot find resource API for kind for Istio CRD

Open linjmeyer opened this issue 4 years ago • 6 comments

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 avatar Sep 09 '21 15:09 linjmeyer

Possibly related #114

linjmeyer avatar Sep 09 '21 15:09 linjmeyer

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 avatar Sep 09 '21 22:09 tintoy

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 avatar Sep 09 '21 22:09 tintoy

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 avatar Sep 09 '21 23:09 tintoy

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 🙂

tintoy avatar Sep 09 '21 23:09 tintoy

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.

linjmeyer avatar Sep 10 '21 13:09 linjmeyer