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
[KubernetesClient.Aot] .NET 8 AOT compatibility for Scale functions #1518
Comments
the patch banned for aot is because that patch is so dynamic i looked into it but did not have better idea |
Hi @tg123 is patch not just a string? Does it require json formatting? |
hi @tg123 , I look at the code but I did not find any PatchNamespaceFunction. Do you have a youtube or some notes to help to understand this repository? |
here is the reason why V1Patch is not easy to fit AOT
V1Patch.body is a type-less object which AOT does not like a workaround is to make V1Patch body string only but it breaks the compatibility with the non-aot sdk |
I am for adding a specific method for AOT. |
imho, dynamic will still play an important role in future .net projects. |
Thank you @tg123 , I do not know how to help you. It would be awesome to have a solution :) |
hi @tg123 , when do you think you will have some time ? How can I help you? |
thanks @guillaume-chervet if you can port https://github.com/kubernetes-client/csharp/blob/master/src/KubernetesClient/Models/V1Patch.cs and https://github.com/kubernetes-client/csharp/blob/master/src/KubernetesClient/Models/V1PatchJsonConverter.cs to AOT project, then patch will be good i am thinking to support string only, but the behavior changed from non-aot project |
Thank you @tg123 , i will try to look at. I am lacking of time too :( |
hi @tg123 , I do knot understand well the project. Another idea, is it possible to retrieve an HttpClient already configured to pass authentication header ? |
see here #1216 |
Thank you very much @tg123 . It works, I can activate Trimming now ! public async Task<ReplicaRequest?> ScaleAsync(ReplicaRequest request)
{
try
{
using k8s.Kubernetes client = new(_k8SConfig);
string patchString = $"{{\"spec\": {{\"replicas\": {request.Replicas}}}}}";
var httpContent = new StringContent(patchString, Encoding.UTF8, "application/merge-patch+json");
// we need to get the base uri, as it's not set on the HttpClient
switch (request.PodType)
{
case PodType.Deployment:
{
var url = string.Concat(client.BaseUri, $"apis/apps/v1/namespaces/{request.Namespace}/deployments/{request.Deployment}/scale" );
HttpRequestMessage httpRequest = new(HttpMethod.Patch,
new Uri(url));
httpRequest.Content = httpContent;
if ( client.Credentials != null )
{
await client.Credentials.ProcessHttpRequestAsync( httpRequest, CancellationToken.None );
}
var response = await client.HttpClient.SendAsync(httpRequest, HttpCompletionOption.ResponseHeadersRead);
if(response.StatusCode != HttpStatusCode.OK)
{
throw new HttpOperationException("Error while scaling deployment");
}
break;
}
case PodType.StatefulSet:
{
var url = string.Concat(client.BaseUri, $"apis/apps/v1/namespaces/{request.Namespace}/statefulsets/{request.Deployment}/scale" );
HttpRequestMessage httpRequest = new(HttpMethod.Patch,
new Uri(url));
httpRequest.Content = httpContent;
if ( client.Credentials != null )
{
await client.Credentials.ProcessHttpRequestAsync( httpRequest, CancellationToken.None );
}
var response = await client.HttpClient.SendAsync(httpRequest, HttpCompletionOption.ResponseHeadersRead );
if(response.StatusCode != HttpStatusCode.OK)
{
throw new HttpOperationException("Error while scaling deployment");
}
break;
}
default:
throw new ArgumentOutOfRangeException();
}
}
catch (HttpOperationException e)
{
_logger.LogError(e, "Error while scaling kubernetes deployment {RequestDeployment}", request.Deployment);
return request;
}
return request;
} |
I @tg123 ,
I'am using KubernetesClient.Aot --version 13.0.12
Thank you so much for your help !
Just an issue to trace it. It would be awesome to implement AOT compatibility with Scale (StatefulSet and Deployment) functions :)
The code :
The text was updated successfully, but these errors were encountered: