Skip to content

VersionOperationsExtensions.GetCodeAsync throws an exception in AOT scenarios #1633

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

Open
hach-que opened this issue May 19, 2025 · 0 comments
Assignees

Comments

@hach-que
Copy link

Describe the bug
VersionOperationsExtensions.GetCodeAsync throws an exception in AOT scenarios.

Kubernetes C# SDK Client Version
16.0.2

Server Kubernetes Version
1.26.1

Dotnet Runtime Version
net9

To Reproduce
Install KubernetesClient.Aot, and then try to query the version information from Kubernetes:

var config = KubernetesClientConfiguration.BuildConfigFromConfigFile(configFile);

var kubernetes = new Kubernetes(config);

for (var i = 0; i < maximumWaitSeconds && !cancellationToken.IsCancellationRequested; i++)
{
    try
    {
        var code = await kubernetes.Version.GetCodeAsync(cancellationToken);
        _logger.LogInformation($"Connected to API server, Kubernetes is running version: {code.Major}.{code.Minor}");
        return kubernetes;
    }
    catch (HttpRequestException ex)
    {
        _logger.LogWarning($"Failed to connect to Kubernetes API server; it might still be starting up: {ex}");
        if (i < maximumWaitSeconds - 1)
        {
            await Task.Delay(1000, cancellationToken);
        }
    }
    cancellationToken.ThrowIfCancellationRequested();
}
cancellationToken.ThrowIfCancellationRequested();

This results in the following exception:

System.ArgumentNullException: Value cannot be null. (Parameter 'jsonTypeInfo')
    at System.Text.Json.ThrowHelper.ThrowArgumentNullException(String)
    at System.Text.Json.JsonSerializer.Deserialize(Stream, JsonTypeInfo)
    at k8s.KubernetesJson.Deserialize[TValue](Stream, JsonSerializerOptions )
    at k8s.Kubernetes.CreateResultAsync[T](HttpRequestMessage, HttpResponseMessage, Nullable`1, CancellationToken)
    at k8s.AbstractKubernetes.IVersionOperations_GetCodeWithHttpMessagesAsync[T](IReadOnlyDictionary`2, CancellationToken)
    at k8s.AbstractKubernetes.k8s.IVersionOperations.GetCodeWithHttpMessagesAsync(IReadOnlyDictionary`2, CancellationToken)
    at k8s.VersionOperationsExtensions.GetCodeAsync(IVersionOperations, CancellationToken )
    at Redpoint.KubernetesManager.Services.DefaultKubernetesClientFactory.ConnectToClusterAsync(String, Int32, CancellationToken)
    at Redpoint.KubernetesManager.Components.ControllerOnly.KubernetesClientComponent.OnStartedAsync(IContext context, IAssociatedData data, CancellationToken cancellationToken)
    at Redpoint.KubernetesManager.Signalling.Executor.<>c__DisplayClass12_1.<<RaiseSignalAsync>b__1>d.MoveNext()

Expected behavior
AOT should work.

@tg123 tg123 self-assigned this May 22, 2025
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

No branches or pull requests

2 participants