From 74538d58f2f6b3d40f72b8e8bf122e7feef4989c Mon Sep 17 00:00:00 2001 From: Eric Kerst <919353+k7o@users.noreply.github.com> Date: Wed, 6 Aug 2025 07:53:24 +0200 Subject: [PATCH] fix ExecCredentialResponse deserializion in aot (#1643) * Add ExecCredentialResponseContext for JSON serialization support * Added ExecStatus JsonPropertyNames --- .../KubeConfigModels/ExecCredentialResponse.cs | 4 ++++ .../KubeConfigModels/ExecCredentialResponseContext.cs | 7 +++++++ .../KubernetesClientConfiguration.ConfigFile.cs | 5 ++++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/KubernetesClient.Aot/KubeConfigModels/ExecCredentialResponseContext.cs diff --git a/src/KubernetesClient.Aot/KubeConfigModels/ExecCredentialResponse.cs b/src/KubernetesClient.Aot/KubeConfigModels/ExecCredentialResponse.cs index 5bac4af5e..d593ff4f6 100644 --- a/src/KubernetesClient.Aot/KubeConfigModels/ExecCredentialResponse.cs +++ b/src/KubernetesClient.Aot/KubeConfigModels/ExecCredentialResponse.cs @@ -8,9 +8,13 @@ public class ExecCredentialResponse public class ExecStatus { #nullable enable + [JsonPropertyName("expirationTimestamp")] public DateTime? ExpirationTimestamp { get; set; } + [JsonPropertyName("token")] public string? Token { get; set; } + [JsonPropertyName("clientCertificateData")] public string? ClientCertificateData { get; set; } + [JsonPropertyName("clientKeyData")] public string? ClientKeyData { get; set; } #nullable disable diff --git a/src/KubernetesClient.Aot/KubeConfigModels/ExecCredentialResponseContext.cs b/src/KubernetesClient.Aot/KubeConfigModels/ExecCredentialResponseContext.cs new file mode 100644 index 000000000..c7ffd8294 --- /dev/null +++ b/src/KubernetesClient.Aot/KubeConfigModels/ExecCredentialResponseContext.cs @@ -0,0 +1,7 @@ +namespace k8s.KubeConfigModels +{ + [JsonSerializable(typeof(ExecCredentialResponse))] + internal partial class ExecCredentialResponseContext : JsonSerializerContext + { + } +} diff --git a/src/KubernetesClient.Aot/KubernetesClientConfiguration.ConfigFile.cs b/src/KubernetesClient.Aot/KubernetesClientConfiguration.ConfigFile.cs index c1865687c..a2301b464 100644 --- a/src/KubernetesClient.Aot/KubernetesClientConfiguration.ConfigFile.cs +++ b/src/KubernetesClient.Aot/KubernetesClientConfiguration.ConfigFile.cs @@ -523,7 +523,10 @@ public static ExecCredentialResponse ExecuteExternalCommand(ExternalExecution co throw new KubeConfigException("external exec failed due to timeout"); } - var responseObject = KubernetesJson.Deserialize(process.StandardOutput.ReadToEnd()); + var responseObject = JsonSerializer.Deserialize( + process.StandardOutput.ReadToEnd(), + ExecCredentialResponseContext.Default.ExecCredentialResponse); + if (responseObject == null || responseObject.ApiVersion != config.ApiVersion) { throw new KubeConfigException(