kubernetes-client / csharp

Officially supported dotnet Kubernetes Client library
Apache License 2.0
1.09k stars 294 forks source link

.NET 8 and AOT compatibility #1395

Closed guillaume-chervet closed 8 months ago

guillaume-chervet commented 1 year ago

Describe the bug

Than you for your work ont this library about kubernetes :)

We would like to activate .NET 8 AOT on SlimFaas which is also an open source project. Compilation work, but execution crash on that line : https://github.com/AxaFrance/SlimFaas/blob/5c5a1f39ae3b0e6bee8a8cdf27ec85f95607b404/src/SlimFaas/Kubernetes/KubernetesService.cs#L66

--- End of stack trace from previous location ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xbe
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x4e
at k8s.AbstractKubernetes.<IAppsV1Operations_ListNamespacedDeploymentWithHttpMessagesAsync>d__606`1.MoveNext() + 0x664

...

System.InvalidOperationException: JsonSerializerOptions instance must specify a TypeInfoResolver setting before being marked as read-only.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonSerializerOptionsNoTypeInfoResolverSpecified() + 0x27
at System.Text.Json.JsonSerializerOptions.ConfigureForJsonSerializer() + 0x20
at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions, Type) + 0x2d
at System.Text.Json.JsonSerializer.GetTypeInfo[T](JsonSerializerOptions) + 0x2b
at System.Text.Json.JsonSerializer.Deserialize[TValue](Stream, JsonSerializerOptions) + 0x1f
at k8s.Kubernetes.<CreateResultAsync>d__46`1.MoveNext() + 0x249

The SlimFaas PullRequest : https://github.com/AxaFrance/SlimFaas/pull/23

Kubernetes C# SDK Client Version

 <PackageReference Include="KubernetesClient" Version="12.0.16" />

Dotnet Runtime Version 8.0.100-preview.7.23376.3

To Reproduce Build an AOT program which use this function : https://github.com/AxaFrance/SlimFaas/blob/5c5a1f39ae3b0e6bee8a8cdf27ec85f95607b404/src/SlimFaas/Kubernetes/KubernetesService.cs#L66

Expected behavior Does not crash once compile with AOT

### Tasks
- [ ] https://github.com/kubernetes-client/csharp/pull/1417
IvanJosipovic commented 1 year ago

This looks to be related to #1311

tg123 commented 1 year ago

AOT will be supported for sure

guillaume-chervet commented 1 year ago

Can't wait for it 😜 it would be awesome!

tg123 commented 1 year ago

PR is also welcomed,

m3nax commented 10 months ago

related #1463

tg123 commented 9 months ago

hi @guillaume-chervet here is a draft version of aot too many warnings and many things need to be fixed but first working code

https://github.com/tg123/csharp/tree/aotfinal/examples/aot

dotnet publish -r win-x64 -c Debug

~20M binary

your input is welcomed, i am still working on cleaning things up

guillaume-chervet commented 9 months ago

Hi @tg123 thank you very much! Is it possible to publish alpha version? I need at least a working trimming mode. AOT will be the next step.

tg123 commented 9 months ago

seems too many lib to cleanu, i am thinking add a Kubenetesclient.AOT for aot only

why do you want trim only? btw

guillaume-chervet commented 9 months ago

AOT will be very fine, but Trimming for à first step will be Nice. This discution is interresting https://github.com/dotnet/dotNext/discussions/200#discussioncomment-7439454

guillaume-chervet commented 9 months ago

Hi @tg123 are your still working on this?

I really need to activate trimming and better will be AOT for Slimfaas : https://github.com/AxaFrance/SlimFaas

I may be will have more time if you need some help.

tg123 commented 9 months ago

yup please allow more time on this

guillaume-chervet commented 8 months ago

hi @tg123 ,

Thank you s much for your work. Is it possible to publish a beta of KubernetesClient.Aot ?

in order to be able to test it :)

guillaume-chervet commented 8 months ago

I have tested it @tg123 ,

List deployments and statefulset works well. For the moment I Have activated Trimming mode (I will test AOT after having a working trimmin mode).

When try to scale down for example It crash.

2024-02-02 09:22:36 fail: SlimFaas.ScaleReplicasWorker[0]
2024-02-02 09:22:36       Global Error in ScaleReplicasWorker
2024-02-02 09:22:36       System.ArgumentNullException: Value cannot be null. (Parameter 'jsonTypeInfo')
2024-02-02 09:22:36          at System.Text.Json.ThrowHelper.ThrowArgumentNullException(String)
2024-02-02 09:22:36          at k8s.Kubernetes.SendRequest[T](String, HttpMethod, IReadOnlyDictionary`2, T, CancellationToken)
2024-02-02 09:22:36          at k8s.AbstractKubernetes.IAppsV1Operations_PatchNamespacedDeploymentScaleWithHttpMessagesAsync[T](V1Patch, String, String, String, String, String, Nullable`1, Nullable`1, IReadOnlyDictionary`2, CancellationToken)
2024-02-02 09:22:36          at k8s.AbstractKubernetes.k8s.IAppsV1Operations.PatchNamespacedDeploymentScaleWithHttpMessagesAsync(V1Patch, String, String, String, String, String, Nullable`1, Nullable`1, IReadOnlyDictionary`2, CancellationToken)
2024-02-02 09:22:36          at k8s.AppsV1OperationsExtensions.PatchNamespacedDeploymentScaleAsync(IAppsV1Operations, V1Patch, String, String, String , String , String , Nullable`1 , Nullable`1 , CancellationToken )
2024-02-02 09:22:36          at SlimFaas.Kubernetes.KubernetesService.ScaleAsync(ReplicaRequest request)
2024-02-02 09:22:36          at SlimFaas.ReplicasService.CheckScaleAsync(String kubeNamespace)
2024-02-02 09:22:36          at SlimFaas.ScaleReplicasWorker.ExecuteAsync(CancellationToken stoppingToken)

The code : image

Do you hav e an idea @tg123 ?

tg123 commented 8 months ago

patch is not supported in aot yet

guillaume-chervet commented 8 months ago

Hi @tg123 ,

Do you think it will be very soon ? My Image shrink a lot just with Timming. I Can't wait to see used ram in production in trimming mode or AOT :) image

https://github.com/AxaFrance/SlimFaas

tg123 commented 8 months ago

i am working on watch but let me see if i can make patch aot first

guillaume-chervet commented 8 months ago

@tg123 Thank you, patch aot first would be awesome :)