Description
I'm trying to write a simple program to create a namespace. Following the sample code in the README, I have the following:
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
var client = new Kubernetes(config);
var ns = new V1Namespace { Metadata = new V1ObjectMeta { Name = "test" } };
var result = client.CreateNamespace(ns);
Console.WriteLine(result);
Using 2.0.34, this works as expected against Kubernetes 1.18.8 (AKS).
Using 3.0.*, it fails with the following exception:
Unhandled exception. Microsoft.Rest.HttpOperationException: Operation returned an invalid status code 'UnsupportedMediaType'
at k8s.Kubernetes.CreateNamespaceWithHttpMessagesAsync(V1Namespace body, String dryRun, String fieldManager, String pretty, Dictionary`2 customHeaders, CancellationToken cancellationToken)
at k8s.KubernetesExtensions.CreateNamespaceAsync(IKubernetes operations, V1Namespace body, String dryRun, String fieldManager, String pretty, CancellationToken cancellationToken)
at k8s.KubernetesExtensions.CreateNamespace(IKubernetes operations, V1Namespace body, String dryRun, String fieldManager, String pretty)
at KubeTest.Program.Main(String[] args) in /home/tabbott/tmp/KubeTest/Program.cs:line 14
The response body is:
{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"the body of the request was in an unknown format - accepted media types include: application/json, application/yaml, application/vnd.kubernetes.protobuf","reason":"UnsupportedMediaType","code":415}
Digging deeper, I found that the request is being sent with the header Content-Type: */*
, which comes from CreateNamespaceWithHttpMessagesAsync
in src/KubernetesClient/generated/Kubernetes.cs:2445
_httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("*/*");
and results in a 415 UnsupportedMediaType
response from the server.
With 2.0.34, the header is correctly set to Content-Type: application/json; charset=utf-8
.
Read operations such as ListNamespace
and ReadNamespace
work fine, but the problem also manifests with other operations with a request body such as DeleteNamespace
.