Skip to content
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

DeleteNamespacedService throws JsonException #824

Closed
ryankmcintyre opened this issue Apr 4, 2022 · 6 comments
Closed

DeleteNamespacedService throws JsonException #824

ryankmcintyre opened this issue Apr 4, 2022 · 6 comments

Comments

@ryankmcintyre
Copy link

When calling DeleteNamespacedService (or DeleteNamespacedServiceAsync), result is:

System.Text.Json.JsonException: The JSON value could not be converted to k8s.Models.V1ServiceStatus. Path: $.status | LineNumber: 0 | BytePositionInLine: 67.

Although, the service is successfully deleted from the cluster.

Here's the code I'm using:

    public async void Delete()
    {
        var config = KubernetesClientConfiguration.BuildDefaultConfig();
        var client = new Kubernetes(config);

        await client.DeleteNamespacedServiceAsync(graphQLServiceName, namespaceName);
    }

Full exception stack:

{System.Text.Json.JsonException: The JSON value could not be converted to k8s.Models.V1ServiceStatus. Path: $.status | LineNumber: 0 | BytePositionInLine: 67.
   at System.Text.Json.ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(Type propertyType)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
   at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadCore[TValue](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadCore[TValue](JsonReaderState& readerState, Boolean isFinalBlock, ReadOnlySpan`1 buffer, JsonSerializerOptions options, ReadStack& state, JsonConverter converterBase)
   at System.Text.Json.JsonSerializer.ContinueDeserialize[TValue](ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack, JsonConverter converter, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.ReadAll[TValue](Stream utf8Json, JsonTypeInfo jsonTypeInfo)
   at System.Text.Json.JsonSerializer.ReadAllUsingOptions[TValue](Stream utf8Json, Type returnType, JsonSerializerOptions options)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](Stream utf8Json, JsonSerializerOptions options)
   at k8s.KubernetesJson.Deserialize[TValue](Stream json)
   at k8s.Kubernetes.CreateResultAsync[T](HttpRequestMessage httpRequest, HttpResponseMessage httpResponse, Nullable`1 watch, CancellationToken cancellationToken)
   at k8s.Kubernetes.DeleteNamespacedServiceWithHttpMessagesAsync(String name, String namespaceParameter, V1DeleteOptions body, String dryRun, Nullable`1 gracePeriodSeconds, Nullable`1 orphanDependents, String propagationPolicy, Nullable`1 pretty, IDictionary`2 customHeaders, CancellationToken cancellationToken)
   at k8s.KubernetesExtensions.DeleteNamespacedServiceAsync(IKubernetes operations, String name, String namespaceParameter, V1DeleteOptions body, String dryRun, Nullable`1 gracePeriodSeconds, Nullable`1 orphanDependents, String propagationPolicy, Nullable`1 pretty, CancellationToken cancellationToken)
   at TestKubeClient.Controllers.GraphQLDeploymentController.Delete() in /home/blah/blah/blah/api/Controllers/GraphQLDeploymentController.cs:line 56}
@tg123
Copy link
Member

tg123 commented Apr 4, 2022

may i know your server and client version

likely caused by swagger changed

@ryankmcintyre
Copy link
Author

Client: 1.22.5
Server: 1.21.9

@tg123
Copy link
Member

tg123 commented Apr 4, 2022

then it is a bug, I am looking into it

@tg123
Copy link
Member

tg123 commented Apr 5, 2022

this is due to swagger change and be behavior is expected

1.21 and 1.22 DeleteService returns v1.Status (6.0 client sdk)
while in 1.23, DeleteService returns v1.Service (7.0+ client sdk)

search deleteCoreV1NamespacedService

https://raw.githubusercontent.com/kubernetes/kubernetes/v1.21.9/api/openapi-spec/swagger.json
vs
https://raw.githubusercontent.com/kubernetes/kubernetes/v1.23.0/api/openapi-spec/swagger.json

anyway, the backward compatibility seems a big headache. will test build multiple api def in future version.

@ryankmcintyre
Copy link
Author

I saw that. Which seems odd to me, to have a delete method return an object of the type being deleted. Most of the other delete methods return a status, which seems more natural to me.

Since the delete still succeeds, I'll just catch the error and move on. Hopefully this becomes more consistent in the future.

@tg123
Copy link
Member

tg123 commented Apr 6, 2022

close as it is by design

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