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

feat: switch JsonConverters to public for Source Generators #1311

Closed

Conversation

IvanJosipovic
Copy link
Contributor

Fixes #1309

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 31, 2023
@tg123
Copy link
Member

tg123 commented May 31, 2023

will the pr include Source Generators?

@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@c822a94). Click here to learn what that means.
The diff coverage is n/a.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff            @@
##             master    #1311   +/-   ##
=========================================
  Coverage          ?   69.90%           
=========================================
  Files             ?       95           
  Lines             ?     2701           
  Branches          ?        0           
=========================================
  Hits              ?     1888           
  Misses            ?      813           
  Partials          ?        0           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@IvanJosipovic
Copy link
Contributor Author

will the pr include Source Generators?

I can look to add the Source Generator, the code will need to be added to the Model generation code of this code base so that its dynamic.

There is also a fallback to the Reflection based Serializer if the Source Gen doesn't exist:

KubernetesJson.AddJsonOptions(x => x.TypeInfoResolver = JsonTypeInfoResolver.Combine(SourceGenerationContext.Default, JsonSerializerOptions.Default.TypeInfoResolver));

Here is what my Source Generator looks like at the moment

using System.Text.Json;
using System.Text.Json.Serialization;

namespace KubeUI.Core.Client.Serialization
{
    [JsonSerializable(typeof(V1Node))]
    [JsonSerializable(typeof(KubernetesList<V1Node>))]
    [JsonSerializable(typeof(Watcher<V1Node>.WatchEvent))]

    [JsonSerializable(typeof(V1Namespace))]
    [JsonSerializable(typeof(KubernetesList<V1Namespace>))]
    [JsonSerializable(typeof(Watcher<V1Namespace>.WatchEvent))]

    [JsonSerializable(typeof(Corev1Event))]
    [JsonSerializable(typeof(KubernetesList<Corev1Event>))]
    [JsonSerializable(typeof(Watcher<Corev1Event>.WatchEvent))]

    [JsonSerializable(typeof(V1Pod))]
    [JsonSerializable(typeof(KubernetesList<V1Pod>))]
    [JsonSerializable(typeof(Watcher<V1Pod>.WatchEvent))]

    [JsonSerializable(typeof(V1Deployment))]
    [JsonSerializable(typeof(KubernetesList<V1Deployment>))]
    [JsonSerializable(typeof(Watcher<V1Deployment>.WatchEvent))]

    [JsonSerializable(typeof(V1DaemonSet))]
    [JsonSerializable(typeof(KubernetesList<V1DaemonSet>))]
    [JsonSerializable(typeof(Watcher<V1DaemonSet>.WatchEvent))]

    [JsonSerializable(typeof(V1StatefulSet))]
    [JsonSerializable(typeof(KubernetesList<V1StatefulSet>))]
    [JsonSerializable(typeof(Watcher<V1StatefulSet>.WatchEvent))]

    [JsonSerializable(typeof(V1ReplicaSet))]
    [JsonSerializable(typeof(KubernetesList<V1ReplicaSet>))]
    [JsonSerializable(typeof(Watcher<V1ReplicaSet>.WatchEvent))]

    [JsonSerializable(typeof(V1ReplicationController))]
    [JsonSerializable(typeof(KubernetesList<V1ReplicationController>))]
    [JsonSerializable(typeof(Watcher<V1ReplicationController>.WatchEvent))]

    [JsonSerializable(typeof(V1Job))]
    [JsonSerializable(typeof(KubernetesList<V1Job>))]
    [JsonSerializable(typeof(Watcher<V1Job>.WatchEvent))]

    [JsonSerializable(typeof(V1CronJob))]
    [JsonSerializable(typeof(KubernetesList<V1CronJob>))]
    [JsonSerializable(typeof(Watcher<V1CronJob>.WatchEvent))]

    [JsonSerializable(typeof(V1ConfigMap))]
    [JsonSerializable(typeof(KubernetesList<V1ConfigMap>))]
    [JsonSerializable(typeof(Watcher<V1ConfigMap>.WatchEvent))]

    [JsonSerializable(typeof(V1Secret))]
    [JsonSerializable(typeof(KubernetesList<V1Secret>))]
    [JsonSerializable(typeof(Watcher<V1Secret>.WatchEvent))]

    [JsonSerializable(typeof(V1ResourceQuota))]
    [JsonSerializable(typeof(KubernetesList<V1ResourceQuota>))]
    [JsonSerializable(typeof(Watcher<V1ResourceQuota>.WatchEvent))]

    [JsonSerializable(typeof(V1LimitRange))]
    [JsonSerializable(typeof(KubernetesList<V1LimitRange>))]
    [JsonSerializable(typeof(Watcher<V1LimitRange>.WatchEvent))]

    [JsonSerializable(typeof(V1HorizontalPodAutoscaler))]
    [JsonSerializable(typeof(KubernetesList<V1HorizontalPodAutoscaler>))]
    [JsonSerializable(typeof(Watcher<V1HorizontalPodAutoscaler>.WatchEvent))]

    [JsonSerializable(typeof(V1PodDisruptionBudget))]
    [JsonSerializable(typeof(KubernetesList<V1PodDisruptionBudget>))]
    [JsonSerializable(typeof(Watcher<V1PodDisruptionBudget>.WatchEvent))]

    [JsonSerializable(typeof(V1PriorityClass))]
    [JsonSerializable(typeof(KubernetesList<V1PriorityClass>))]
    [JsonSerializable(typeof(Watcher<V1PriorityClass>.WatchEvent))]

    [JsonSerializable(typeof(V1RuntimeClass))]
    [JsonSerializable(typeof(KubernetesList<V1RuntimeClass>))]
    [JsonSerializable(typeof(Watcher<V1RuntimeClass>.WatchEvent))]

    [JsonSerializable(typeof(V1Lease))]
    [JsonSerializable(typeof(KubernetesList<V1Lease>))]
    [JsonSerializable(typeof(Watcher<V1Lease>.WatchEvent))]

    [JsonSerializable(typeof(V1APIService))]
    [JsonSerializable(typeof(KubernetesList<V1APIService>))]
    [JsonSerializable(typeof(Watcher<V1APIService>.WatchEvent))]

    [JsonSerializable(typeof(V1Service))]
    [JsonSerializable(typeof(KubernetesList<V1Service>))]
    [JsonSerializable(typeof(Watcher<V1Service>.WatchEvent))]

    [JsonSerializable(typeof(V1Endpoints))]
    [JsonSerializable(typeof(KubernetesList<V1Endpoints>))]
    [JsonSerializable(typeof(Watcher<V1Endpoints>.WatchEvent))]

    [JsonSerializable(typeof(V1EndpointSlice))]
    [JsonSerializable(typeof(KubernetesList<V1EndpointSlice>))]
    [JsonSerializable(typeof(Watcher<V1EndpointSlice>.WatchEvent))]

    [JsonSerializable(typeof(V1Ingress))]
    [JsonSerializable(typeof(KubernetesList<V1Ingress>))]
    [JsonSerializable(typeof(Watcher<V1Ingress>.WatchEvent))]

    [JsonSerializable(typeof(V1IngressClass))]
    [JsonSerializable(typeof(KubernetesList<V1IngressClass>))]
    [JsonSerializable(typeof(Watcher<V1IngressClass>.WatchEvent))]

    [JsonSerializable(typeof(V1NetworkPolicy))]
    [JsonSerializable(typeof(KubernetesList<V1NetworkPolicy>))]
    [JsonSerializable(typeof(Watcher<V1NetworkPolicy>.WatchEvent))]

    [JsonSerializable(typeof(V1MutatingWebhookConfiguration))]
    [JsonSerializable(typeof(KubernetesList<V1MutatingWebhookConfiguration>))]
    [JsonSerializable(typeof(Watcher<V1MutatingWebhookConfiguration>.WatchEvent))]

    [JsonSerializable(typeof(V1ValidatingWebhookConfiguration))]
    [JsonSerializable(typeof(KubernetesList<V1ValidatingWebhookConfiguration>))]
    [JsonSerializable(typeof(Watcher<V1ValidatingWebhookConfiguration>.WatchEvent))]

    [JsonSerializable(typeof(V1PersistentVolumeClaim))]
    [JsonSerializable(typeof(KubernetesList<V1PersistentVolumeClaim>))]
    [JsonSerializable(typeof(Watcher<V1PersistentVolumeClaim>.WatchEvent))]

    [JsonSerializable(typeof(V1PersistentVolume))]
    [JsonSerializable(typeof(KubernetesList<V1PersistentVolume>))]
    [JsonSerializable(typeof(Watcher<V1PersistentVolume>.WatchEvent))]

    [JsonSerializable(typeof(V1StorageClass))]
    [JsonSerializable(typeof(KubernetesList<V1StorageClass>))]
    [JsonSerializable(typeof(Watcher<V1StorageClass>.WatchEvent))]

    [JsonSerializable(typeof(V1ServiceAccount))]
    [JsonSerializable(typeof(KubernetesList<V1ServiceAccount>))]
    [JsonSerializable(typeof(Watcher<V1ServiceAccount>.WatchEvent))]

    [JsonSerializable(typeof(V1ClusterRole))]
    [JsonSerializable(typeof(KubernetesList<V1ClusterRole>))]
    [JsonSerializable(typeof(Watcher<V1ClusterRole>.WatchEvent))]

    [JsonSerializable(typeof(V1Role))]
    [JsonSerializable(typeof(KubernetesList<V1Role>))]
    [JsonSerializable(typeof(Watcher<V1Role>.WatchEvent))]

    [JsonSerializable(typeof(V1ClusterRoleBinding))]
    [JsonSerializable(typeof(KubernetesList<V1ClusterRoleBinding>))]
    [JsonSerializable(typeof(Watcher<V1ClusterRoleBinding>.WatchEvent))]

    [JsonSerializable(typeof(V1RoleBinding))]
    [JsonSerializable(typeof(KubernetesList<V1RoleBinding>))]
    [JsonSerializable(typeof(Watcher<V1RoleBinding>.WatchEvent))]

    [JsonSerializable(typeof(V1CustomResourceDefinition))]
    [JsonSerializable(typeof(KubernetesList<V1CustomResourceDefinition>))]
    [JsonSerializable(typeof(Watcher<V1CustomResourceDefinition>.WatchEvent))]

    [JsonSerializable(typeof(V1APIGroupList))]
    [JsonSerializable(typeof(KubernetesList<V1APIGroupList>))]
    [JsonSerializable(typeof(Watcher<V1APIGroupList>.WatchEvent))]

    [JsonSerializable(typeof(V1LimitRange))]
    [JsonSerializable(typeof(KubernetesList<V1LimitRange>))]
    [JsonSerializable(typeof(Watcher<V1LimitRange>.WatchEvent))]

    [JsonSerializable(typeof(V1WatchEvent))]
    [JsonSerializable(typeof(KubernetesObject))]
    [JsonSerializable(typeof(Watcher<KubernetesObject>.WatchEvent))]

    [JsonSerializable(typeof(JsonElement))]
    internal partial class SourceGenerationContext : JsonSerializerContext
    {
    }
}

@guillaume-chervet
Copy link

guillaume-chervet commented Sep 27, 2023

Any news on this PullRequest ? :p

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 13, 2023
@guillaume-chervet
Copy link

guillaume-chervet commented Nov 27, 2023

hi @IvanJosipovic ,

may you rebase your PullRequest for a merge ?
I really need this :p It will help me a lot ^^

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 28, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: IvanJosipovic
Once this PR has been reviewed and has the lgtm label, please assign brendandburns for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@guillaume-chervet
Copy link

Does this PullRequest ready to review @brendandburns ?

@tg123
Copy link
Member

tg123 commented Nov 29, 2023

Does this PullRequest ready to review @brendandburns ?

i am working in another pr of aot

@guillaume-chervet
Copy link

Any news about this PR?
It is blocking trimming.

2023-12-06 17:56:19 Unhandled exception. System.AggregateException: One or more errors occurred. (Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.)
2023-12-06 17:56:19  ---> System.InvalidOperationException: Reflection-based serialization has been disabled for this application. Either use the source generator APIs or explicitly configure the 'JsonSerializerOptions.TypeInfoResolver' property.
2023-12-06 17:56:19    at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_JsonSerializerIsReflectionDisabled()
2023-12-06 17:56:19    at System.Text.Json.JsonSerializerOptions.ConfigureForJsonSerializer()
2023-12-06 17:56:19    at System.Text.Json.JsonSerializerOptions.MakeReadOnly(Boolean)
2023-12-06 17:56:19    at System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions, Type)
2023-12-06 17:56:19    at System.Text.Json.JsonSerializer.GetTypeInfo[T](JsonSerializerOptions)
2023-12-06 17:56:19    at System.Text.Json.JsonSerializer.Deserialize[TValue](Stream , JsonSerializerOptions )
2023-12-06 17:56:19    at k8s.KubernetesJson.Deserialize[TValue](Stream json, JsonSerializerOptions jsonSerializerOptions)
2023-12-06 17:56:19    at k8s.Kubernetes.CreateResultAsync[T](HttpRequestMessage httpRequest, HttpResponseMessage httpResponse, Nullable`1 watch, CancellationToken cancellationToken)
2023-12-06 17:56:19    at k8s.AbstractKubernetes.ICoreV1Operations_ListNamespacedPodWithHttpMessagesAsync[T](String namespaceParameter, Nullable`1 allowWatchBookmarks, String continueParameter, String fieldSelector, String labelSelector, Nullable`1 limit, String resourceVersion, String resourceVersionMatch, Nullable`1 sendInitialEvents, Nullable`1 timeoutSeconds, Nullable`1 watch, Nullable`1 pretty, IReadOnlyDictionary`2 customHeaders, CancellationToken cancellationToken)
2023-12-06 17:56:19    at k8s.AbstractKubernetes.k8s.ICoreV1Operations.ListNamespacedPodWithHttpMessagesAsync(String namespaceParameter, Nullable`1 allowWatchBookmarks, String continueParameter, String fieldSelector, String labelSelector, Nullable`1 limit, String resourceVersion, String resourceVersionMatch, Nullable`1 sendInitialEvents, Nullable`1 timeoutSeconds, Nullable`1 watch, Nullable`1 pretty, IReadOnlyDictionary`2 customHeaders, CancellationToken cancellationToken)
2023-12-06 17:56:19    at k8s.CoreV1OperationsExtensions.ListNamespacedPodAsync(ICoreV1Operations operations, String namespaceParameter, Nullable`1 allowWatchBookmarks, String continueParameter, String fieldSelector, String labelSelector, Nullable`1 limit, String resourceVersion, String resourceVersionMatch, Nullable`1 sendInitialEvents, Nullable`1 timeoutSeconds, Nullable`1 watch, Nullable`1 pretty, CancellationToken cancellationToken)
2023-12-06 17:56:19    at SlimFaas.Kubernetes.KubernetesService.ListFunctionsAsync(String kubeNamespace)
2023-12-06 17:56:19    at SlimFaas.ReplicasService.SyncDeploymentsAsync(String kubeNamespace)
2023-12-06 17:56:19    --- End of inner exception stack trace ---
2023-12-06 17:56:19    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean)
2023-12-06 17:56:19    at System.Threading.Tasks.Task.Wait(Int32, CancellationToken)
2023-12-06 17:56:19    at System.Threading.Tasks.Task.Wait()
2023-12-06 17:56:19    at Program.<Main>$(String[] args)
2023-12-06 17:56:19 Starting in namespace slimfaas-demo

@tg123
Copy link
Member

tg123 commented Jan 14, 2024

close as of #1498

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using System.Text.Json Source Generator
5 participants