kubernetes-client / csharp

Officially supported dotnet Kubernetes Client library
Apache License 2.0
1.1k stars 295 forks source link

KubernetesClient.Aot args IList<string> serialization error #1570

Open SGStino opened 4 months ago

SGStino commented 4 months ago

Describe the bug If a kubernetes client config contains string lists (for example, at users[*].user.exec.args), the yaml serializer throws that it can't deserialize the node into IList.

No node deserializer was able to deserialize the node into type System.Collections.Generic.IList`1[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e

Kubernetes C# SDK Client Version 14.0.2

Server Kubernetes Version N\A

Dotnet Runtime Version net8

To Reproduce Create a config that contains a user that needs to "exec" with arguments, for example kube oidc login (see KubeConfig)

Expected behavior Being able to deserialize the config, including the args list.

KubeConfig

...
users:
- name: oidc-prod
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1beta1
      args:
      - oidc-login
      - get-token
      - --oidc-issuer-url=https://identity
      - --oidc-client-id=k8s
      - --oidc-client-secret=topsecret
      command: kubectl 
      interactiveMode: IfAvailable
      provideClusterInfo: false
...

Where do you run your app with Kubernetes SDK (please complete the following information): Reproducable in RoslynPad or dotnet console application:

#r "nuget: KubernetesClient.Aot, 14.0.2"
using k8s;
using k8s.Models;
var clientConfig = KubernetesClientConfiguration.BuildConfigFromConfigFile();

Additional context in the JsonSerializationContext for AOT source generation you'd have to include [JsonSerializable(typeof(IList<string>))], my guess would be that there is something similar for YamlDotNet?

tg123 commented 4 months ago

seems so, would you like to send a pr to fix it? or i will pick it this weekend

SGStino commented 4 months ago

We could pick it up, but, at first glance I don't really see where that would be done in YamlDotNet. There doesn't seem to be a serialization context like in System.Text.Json? Any suggestion as to where to look? Haven't done any AOT with Yaml so far yet.

SGStino commented 4 months ago

It seems that all the YamlSerializeableAttributes aren't required on the StaticContext and that it still works for most of the types.

But adding [YamlSerializeableAttribute(typeof(IList<string>))] makes the Source generator generate invalid code and it won't compile anymore. only [YamlSerializeableAttribute(typeof(string[])] generates code that compiles, but that would require updating the kubernetes client models, which wouldn't be desirable...

It might be related to https://github.com/aaubry/YamlDotNet/issues/740#issuecomment-1360163696

And if i'm reading this: https://github.com/aaubry/YamlDotNet/issues/884 it might fix itself in a few days.

k8s-triage-robot commented 1 month ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 5 days ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten