openebs / openebsctl

`openebsctl` is a kubectl plugin to manage OpenEBS storage components.
Apache License 2.0
29 stars 21 forks source link

Use kubeconfig passed through cli or from environment KUBECONFIG variable #117

Closed nareshdesh closed 3 years ago

nareshdesh commented 3 years ago

If kubeconfig file is passed as command line option or if set in environment variable, openebsctl is still referring to the default config path i.e ~/.kube/config

It should refer to the cli option or the env variable KUBECONFIG , before referring to the default config file for accessing the k8 cluster

Following was the issue observed With environment variable set:

[root@localhost do]# export KUBECONFIG=$PWD/kubeconfig
[root@localhost do]# kubectl get node
NAME                   STATUS   ROLES    AGE    VERSION
pool-pe58fno14-89ta0   Ready    <none>   179m   v1.21.3
pool-pe58fno14-89tad   Ready    <none>   3h     v1.21.3
pool-pe58fno14-89tav   Ready    <none>   179m   v1.21.3
[root@localhost do]# kubectl openebs get bd
Error while getting block device: Get "https://35.224.186.93/apis/openebs.io/v1alpha1/blockdevices": dial tcp 35.224.186.93:443: i/o timeout
[root@localhost do]# export KUBECONFIG=/root/mayadata/do/kubeconfig
[root@localhost do]# kubectl openebs get bd
Error while getting block device: Get "https://35.224.186.93/apis/openebs.io/v1alpha1/blockdevices": dial tcp 35.224.186.93:443: i/o timeout
[root@localhost do]# echo $KUBECONFIG
/root/mayadata/do/kubeconfig
[root@localhost do]# ls $KUBECONFIG
/root/mayadata/do/kubeconfig

With command line option passed:

kubectl openebs get bd --kubeconfig=./kubeconfig
Error while getting block device: Get "https://35.224.186.93/apis/openebs.io/v1alpha1/blockdevices": dial tcp 35.224.186.93:443: i/o timeout
[root@localhost do]# kubectl  get bd -n openebs --kubeconfig=./kubeconfig
NAME                                           NODENAME               SIZE           CLAIMSTATE   STATUS   AGE
blockdevice-8d74ae095ad87e461541bd7c3f88ef0a   pool-pe58fno14-89tav   107373116928   Unclaimed    Active   15m
blockdevice-a93320e715e3b3e34362dad3a46e2497   pool-pe58fno14-89ta0   107373116928   Unclaimed    Active   15m
blockdevice-b70e08c5acd216a9fc524907d2493ffe   pool-pe58fno14-89tav   483328         Unclaimed    Active   15m
blockdevice-e36dae74636edae1e8b63a2a8ca6cd26   pool-pe58fno14-89tad   107373116928   Unclaimed    Active   15m
blockdevice-f4522bb459144611ed898b0fde19b143   pool-pe58fno14-89tad   483328         Unclaimed    Active   15m

It worked only after copying the config file to the default location

[root@localhost do]# cp ~/.kube/config  ~/.kube/config.bkp
[root@localhost do]# cp kubeconfig  ~/.kube/config
cp: overwrite '/root/.kube/config'? y
[root@localhost do]# kubectl openebs get bd
NAME                                             PATH        SIZE     CLAIMSTATE   STATUS     FSTYPE    MOUNTPOINT
pool-pe58fno14-89ta0
├─blockdevice-8ab74802a8660795b0a8b4f3c6c117b7   /dev/vdb    472KiB   Unclaimed    Inactive   iso9660
├─blockdevice-9aeb3048976d722b999c448e35352e93   /dev/vdb    472KiB   Unclaimed    Active     iso9660
└─blockdevice-a93320e715e3b3e34362dad3a46e2497   /dev/sda1   100GiB   Claimed      Active

pool-pe58fno14-89tav
├─blockdevice-8d74ae095ad87e461541bd7c3f88ef0a   /dev/sda1   100GiB   Claimed      Active
├─blockdevice-b70e08c5acd216a9fc524907d2493ffe   /dev/vdb    472KiB   Unclaimed    Inactive   iso9660
└─blockdevice-d702b5422005ebc658b308190e4f9e08   /dev/vdb    472KiB   Unclaimed    Active     iso9660

pool-pe58fno14-89tad
├─blockdevice-8e4f257d884b8026801490a76c802ec4   /dev/vdb    472KiB   Unclaimed    Active     iso9660
├─blockdevice-e36dae74636edae1e8b63a2a8ca6cd26   /dev/sda1   100GiB   Claimed      Active
└─blockdevice-f4522bb459144611ed898b0fde19b143   /dev/vdb    472KiB   Unclaimed    Inactive   iso9660
Abhishek-kumar09 commented 3 years ago

Yes, the current CLI options doesn't support kubeconfig flag, I think it is highly required. Can I work on this issue?