tintoy / dotnet-kube-client

A Kubernetes API client for .NET Standard / .NET Core
MIT License
192 stars 33 forks source link

Delete Namespace response json deserialization exception #58

Closed vascofernandes closed 5 years ago

vascofernandes commented 5 years ago

I am trying to delete a namespace using

StatusV1 delStatus = await client.NamespacesV1().Delete(nsName);

The api call actually works and k8s does what it needs to do. It is the deserialization of the response that fails. Some specifically the Status property.

Here is the JSON response from k8s:

{"kind":"Namespace","apiVersion":"v1","metadata":{"name":"xxxxxxxxxx","selfLink":"/api/v1/namespaces/xxxxxxxxxx","uid":"0499e242-1a87-11e9-9f35-000d3a44ebb6","resourceVersion":"1130958","creationTimestamp":"2019-01-17T18:38:01Z","deletionTimestamp":"2019-01-17T18:40:39Z","labels":{"name":"xxxxxxxxxx"},"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"v1\",\"kind\":\"Namespace\",\"metadata\":{\"annotations\":{},\"labels\":{\"name\":\"xxxxxxxxxx\"},\"name\":\"xxxxxxxxxx\"}}\n"}},"spec":{"finalizers":["kubernetes"]},"status":{"phase":"Terminating"}}

Notice at the very end "status":{"phase":"Terminating"}}

The current model StatusV1has type string in the property Status: StatusV1.cs#L47

Thanks.

tintoy commented 5 years ago

Hi - thanks for reporting this, I’m going to take a quick look at the OpenAPI document and see what it says we should expect there. What version of K8s are you using?

tintoy commented 5 years ago

Ok, this is a little odd - according to the K8s docs, StatusV1.Status is always supposed to be a string (Success or Failure):

https://kubernetes.io/docs/reference/federation/v1/definitions/#_v1_status

Let me play around with an actual instance of the K8s API and see what I get...

tintoy commented 5 years ago

Oh, right, never mind - I just realised (need my morning coffee!), this relates to #55.

vascofernandes commented 5 years ago

I will check on the version.

tintoy commented 5 years ago

No worries - I'm about to add a fix for this (we recently updated the other resource clients to handle this, but I must have somehow missed the v1/Namespace client).

The problem was that some successful delete operations can return either a StatusV1 or a model representing the resource state before it was deleted (in this case a NamespaceV1, which has the correct properties for deserialisation). Only way to tell is to check the kind and apiVersion in the response body. Which we do now, for certain operations.

tintoy commented 5 years ago

See https://github.com/tintoy/dotnet-kube-client/commit/9d11ac1e7f3f376f810797e2e3d26deaf787ec02 for details of what was fixed. I'll push out a new version shortly.

vascofernandes commented 5 years ago

Just for completeness :)

$ kubectl version

Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:17:39Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"windows/amd64"}

Server Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.5", GitCommit:"753b2dbc622f5cc417845f0ff8a77f539a4213ea", GitTreeState:"clean", BuildDate:"2018-11-26T14:31:35Z", GoVersion:"go1.10.3", Compiler:"gc", Platform:"linux/amd64"}

And thanks for the new version.

tintoy commented 5 years ago

You're welcome :)

I have published v2.2.4 (but it may take a while for NuGet to index the packages).

tintoy commented 5 years ago

(if you need packages sooner that NuGet can index them, they are also published to this MyGet feed: https://www.myget.org/F/dotnet-kube-client/api/v3/index.json)

vascofernandes commented 5 years ago

Tested and confirmed to be working fine.

tintoy commented 5 years ago

Thanks!