Enable AOT compatibility for Yarp.Kubernetes.Controller#3010
Enable AOT compatibility for Yarp.Kubernetes.Controller#3010
Conversation
Agent-Logs-Url: https://github.com/dotnet/yarp/sessions/b1d776b4-b2b5-4a50-b364-4aec6b74df35 Co-authored-by: eerhardt <8291187+eerhardt@users.noreply.github.com>
- Use JsonStringEnumConverter<MessageType> (generic) in Message.cs for source generator compatibility - Create KubernetesJsonSerializerContext with JsonSerializerContext for AOT-safe JSON serialization - Update DispatchConfigProvider, DispatchActionResult, Receiver to use source-generated JsonSerializer methods - Update Reconciler to use source-generated serialization for logging - Update KubernetesReverseProxyServiceCollectionExtensions to use ConfigurationBinder source generator-compatible Bind call Agent-Logs-Url: https://github.com/dotnet/yarp/sessions/b1d776b4-b2b5-4a50-b364-4aec6b74df35 Co-authored-by: eerhardt <8291187+eerhardt@users.noreply.github.com>
|
@copilot - also add an AOT compatibility test like described in https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/#analyzing-.net-libraries See https://github.com/dotnet/extensions/tree/main/test/Libraries/Microsoft.Extensions.AotCompatibility.TestApp for an example |
- Add IsAotCompatible=true to Yarp.Kubernetes.Controller.csproj to enable build-time trim/AOT analysis - Create testassets/Kubernetes.AotCompatibility.TestApp exercising the three main usage scenarios: combined (AddKubernetesReverseProxy), monitor (AddKubernetesIngressMonitor + AddKubernetesDispatchController), and receiver (Configure<ReceiverOptions> + Receiver + LoadFromMessages) - Add test app to YARP.slnx solution Agent-Logs-Url: https://github.com/dotnet/yarp/sessions/24caf1e2-cfc2-4e24-ae5b-76759b3c709c Co-authored-by: eerhardt <8291187+eerhardt@users.noreply.github.com>
Done in dd0c957. Added two things:
Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>$(ReleaseTFMs)</TargetFrameworks> |
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\src\Kubernetes.Controller\Yarp.Kubernetes.Controller.csproj" /> |
There was a problem hiding this comment.
@copilot - this should reference all the projects that are AOT compatible in teh repo.
Also, it needs TrimmerRootAssembly for each one. see https://github.com/dotnet/extensions/blob/b3f2f408fe70f0d8e1f8fb2385bcfc8e9e81158d/test/Libraries/Microsoft.Extensions.AotCompatibility.TestApp/Microsoft.Extensions.AotCompatibility.TestApp.csproj for an example
There was a problem hiding this comment.
Done in b5bf7f6. The csproj now references all three AOT-compatible YARP assemblies with TrimmerRootAssembly for each, and Program.cs adds scenarios for AddReverseProxy().LoadFromConfig(...) and AddTelemetryListeners().
…d TrimmerRootAssembly - Change TargetFrameworks to net10.0 (single TFM as requested) - Add project references for all three AOT-compatible YARP assemblies: Yarp.Kubernetes.Controller, Yarp.ReverseProxy, Yarp.Telemetry.Consumption - Add TrimmerRootAssembly items for each assembly to ensure trimmer roots them - Extend Program.cs with ReverseProxy and TelemetryConsumption usage scenarios Agent-Logs-Url: https://github.com/dotnet/yarp/sessions/9f2472df-913f-4feb-82f7-9e5b65f7d1c3 Co-authored-by: eerhardt <8291187+eerhardt@users.noreply.github.com>
Yarp.Kubernetes.Controlleremits IL2026/IL3050 warnings due to reflection-based JSON serialization and configuration binding, blocking use in Native AOT/trimmed applications.Changes
JSON Source Generator (
System.Text.Json)KubernetesJsonSerializerContext—JsonSerializerContextwith[JsonSerializable]forMessage,List<RouteConfig>, andList<ClusterConfig>; transitive types are handled automaticallyMessage.cs— switched[JsonConverter(typeof(JsonStringEnumConverter))]to the genericJsonStringEnumConverter<MessageType>(introduced in .NET 8, required for source-gen compatibility)DispatchConfigProvider,DispatchActionResult,Receiver,Reconciler— allJsonSerializer.*calls now pass the generatedJsonTypeInfo<T>fromKubernetesJsonSerializerContext.Default:ConfigurationBinder Source Generator
KubernetesReverseProxyServiceCollectionExtensions— replacedservices.Configure<YarpOptions>(config.GetSection("Yarp"))with an explicitBindcall so theMicrosoft.Extensions.Configuration.Bindersource generator can intercept and emit AOT-safe binding code:AOT Compatibility Test
<IsAotCompatible>true</IsAotCompatible>added toYarp.Kubernetes.Controller.csproj— enables build-time Roslyn trim/AOT static analysis on the library, surfacing any future violations as build errors.New
testassets/Kubernetes.AotCompatibility.TestApp— aPublishAot=trueconsole app targetingnet10.0(following the dotnet/extensions pattern) that references all three AOT-compatible YARP assemblies withTrimmerRootAssemblyfor each:Yarp.Kubernetes.Controller: Combined (AddKubernetesReverseProxy+UseKubernetesReverseProxyCertificateSelector), Monitor (AddKubernetesIngressMonitor+AddKubernetesDispatchController), and Receiver (Configure<ReceiverOptions>+Receiver+LoadFromMessages) scenariosYarp.ReverseProxy: Standalone reverse proxy scenario (AddReverseProxy().LoadFromConfig(...))Yarp.Telemetry.Consumption: Telemetry listener scenario (AddTelemetryListeners())Publishing this app with AOT will flag any trim/AOT regressions introduced in the future across all AOT-compatible YARP libraries.