Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KubernetesJson.Serialize fails due to null JsonSerializerInfo for V1Patch #1587

Open
hwoodiwiss opened this issue Sep 17, 2024 · 3 comments · May be fixed by #1588
Open

KubernetesJson.Serialize fails due to null JsonSerializerInfo for V1Patch #1587

hwoodiwiss opened this issue Sep 17, 2024 · 3 comments · May be fixed by #1588

Comments

@hwoodiwiss
Copy link

hwoodiwiss commented Sep 17, 2024

Describe the bug
It looks like SourceGenerationContext lacks JSON serialization metadata for the V1Patch type, which causes patch requests to fail in AOT scenarios.

Kubernetes C# SDK Client Version
15.0.1

Server Kubernetes Version
1.30.0

Dotnet Runtime Version
net9.0, though this is likely reproducible across AOT compatible TFM's

To Reproduce
Attempt to patch some k8s config using one of the Patch... methods on the Kubernetes client that takes V1Patch while using the Kubernetes.Aot package.

Expected behavior
Configuration to update successfully.

Where do you run your app with Kubernetes SDK (please complete the following information):

  • OS: Windows
  • Environment: Local (Desktop, ARM Laptop)
  • Cloud: No, local cluster

Additional context

I've fixed this in a local version of the package by just adding a second JsonSerializerContext just for V1Patch, and in KubernetesJson.Serialize checking both contexts for type info (commit):

var info = SourceGenerationContext.Default.GetTypeInfo(value.GetType()) ?? LocalSgContext.Default.GetTypeInfo(value.GetType());

I appreciate this is a suboptimal solution. Unfortunately I get build errors adding V1Patch to SourceGenerationContext.

@tg123
Copy link
Member

tg123 commented Sep 18, 2024

this is a known issue, Patch is not supported in AOT at the moment :(

@hwoodiwiss
Copy link
Author

hwoodiwiss commented Sep 18, 2024

I've only seen the use case so far where the body of the V1Patch object is already a JSON string. In that case, I think it would be viable to special case it and skip serialization altogether, and just return the body as string, that would enable some level of support in AOT scenarios.

It would be good to get some level of patch support into the AOT version of the library.

If that sounds reasonable, I would be happy to contribute.

@hwoodiwiss hwoodiwiss linked a pull request Sep 18, 2024 that will close this issue
@hwoodiwiss
Copy link
Author

I've raised #1588, I've tested this and it works in the AOT project I'm working on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants