tintoy / dotnet-kube-client

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

Persistent Volumes aren't namespace-scoped, Client calls fail with 404 #72

Closed jonstelly closed 5 years ago

jonstelly commented 5 years ago

Trying to list persistent volumes gets me a 404:

KubeClient.KubeApiException : Unable to list PersistentVolume (v1) resources (HTTP status NotFound).
NotFound: the server could not find the requested resource
---- HTTPlease.HttpRequestException`1[[KubeClient.Models.StatusV1, KubeClient, Version=2.2.8.0, Culture=neutral, PublicKeyToken=null]] : The request failed with unexpected status code 'NotFound'.
   at KubeClient.ResourceClients.KubeResourceClient.GetResourceList[TResourceList](HttpRequest request, CancellationToken cancellationToken)
   at KubeClient.ResourceClients.PersistentVolumeClientV1.List(String labelSelector, String kubeNamespace, CancellationToken cancellationToken)

I think the change starts with the below diff, but I'm not 100% sure. If this looks right then I guess we'd also need to remove the kubeNamespace parameter from the methods on PersistenVolumeClientV1? If I load http://localhost:8001/api/v1/ in a browser I can see a namespaced: true/false property and it's false for PersistentVolumes, so this seems right. Is there any more complexity to this change other than changing PersistentVolumeClient? If not I can submit a PR this evening or tomorrow.

...\gh\dotnet-kube-client [feature/pv-fix +0 ~1 -0 !]> git diff
diff --git a/src/KubeClient/ResourceClients/PersistentVolumeClientV1.cs b/src/KubeClient/ResourceClients/PersistentVolumeClientV1.cs
index 15c78c2..b4164db 100644
--- a/src/KubeClient/ResourceClients/PersistentVolumeClientV1.cs
+++ b/src/KubeClient/ResourceClients/PersistentVolumeClientV1.cs
@@ -173,12 +173,12 @@ namespace KubeClient.ResourceClients
             /// <summary>
             ///     A collection-level PersistentVolume (v1) request.
             /// </summary>
-            public static readonly HttpRequest Collection   = KubeRequest.Create("api/v1/namespaces/{Namespace}/persistentvolumes?labelSelector={LabelSelector?}&watch={Watch?}");
+            public static readonly HttpRequest Collection   = KubeRequest.Create("api/v1/persistentvolumes?labelSelector={LabelSelector?}&watch={Watch?}");

             /// <summary>
             ///     A get-by-name PersistentVolume (v1) request.
             /// </summary>
-            public static readonly HttpRequest ByName       = KubeRequest.Create("api/v1/namespaces/{Namespace}/persistentvolumes/{Name}");
+            public static readonly HttpRequest ByName       = KubeRequest.Create("api/v1/persistentvolumes/{Name}");
         }
     }
tintoy commented 5 years ago

Nope, that’d be all I think - thanks!

tintoy commented 5 years ago

Published in v2.2.10.

tintoy commented 5 years ago

When you have time can you try out the new release and let me know if it works for your use-case?

jonstelly commented 5 years ago

I just tested 2.2.10 and it works for PersistentVolumes and Nodes (the other pull request). I'm only calling List methods but all the data coming back looks good.

Thanks!