davidB / kubectl-view-allocations

kubectl plugin to list allocations (cpu, memory, gpu,... X utilization, requested, limit, allocatable,...)

Home Page:https://crates.io/crates/kubectl-view-allocations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Honor KUBECONFIG

ktarplee opened this issue · comments

It appears that the environment variable KUBECONFIG is not honored. In fact I have both KUBECONFIG set and ~/.kube/config exists and that seems to break it. I had to unset KUBECONFIG for this awesome tool to work. KUBECONFIG should take precedence so the behavior match kubectl, I believe.

$ kubectl view-allocations
[2020-04-22T14:35:21Z ERROR kubectl_view_allocations] failed 
    cli: CliOpts { namespace: None, show_zero: false, resource_name: [], group_by: [resource, node, pod] }
    error: failed to load kubectl config
    
    Caused by:
        0: failed to load kubeconfig
        1: Error loading kube config: No such file or directory (os error 2)
✔ ~/code/devsecops/ace-hub-api [master|✔] (⎈ |meerkat:kyle)
$ unset KUBECONFIG
✔ ~/code/devsecops/ace-hub-api [master|✔] (⎈ |meerkat:pachyderm)
$ kubectl view-allocations
 Resource                                                         Requested  %Requested      Limit  %Limit  Allocatable  Free 
  cpu                                                                19170m         68%     57960m    207%           28     0 
  ├─ meerkat1                                                         1100m         28%      6800m    170%            4     0 

Of course kubectl works fine with my KUBECONFIG set. It is set to multiple files, colon delimited.

kubectl-view-allocations is version 0.7.0

This fails on 0.7.2 as well.

I am also having issues without having KUBECONFIG set. Without KUBECONFIG set this worked on 0.7.0 but it no longer works on 0.7.2

I build master b9b15b9 and it gives me a different error (same config file).

2020-05-22T12:35:20Z ERROR kubectl_view_allocations] failed 
    cli: CliOpts { namespace: None, show_zero: false, resource_name: [], group_by: [resource, node, pod] }
    error: failed to collect info from nodes
    
    Caused by:
        0: Failed to list nodes via k8s api
        1: ApiError: "404 page not found\n": Failed to parse error data (ErrorResponse { status: "404 Not Found", message: "\"404 page not found\\n\"", reason: "Failed to parse error data", code: 404 })

How do I see the URL being used to make the request? Is there a way to increase logging?

Using a debugger I was able to track this issue down to an issue in "kube". My cluster uri includes more than the hostname (i.e. https://hostname/foo/bar) because I am using rancher.

let uri_str = self.cluster_url.join(pandq.as_str())?;

pandq is "/api/v1/nodes?". The problem is that the resultant uri_str is "https://hostname/api/v1/nodes?" and not what it should be, namely "https://hostname/foo/bar/api/v1/nodes?"

I created an issue in "kube" kube-rs/kube#244

Thanks for tracking the issue and reporting the root cause.
Sorry for being quiet.

This now fixed upstream in kube. You need to update the dependency to 0.35.0

Thanks, I'll do a release after work.

0.7.3 released

Thanks for your contribution, feel free to reopen if the fix doesn't work

It worked. Thanks.