vmware-archive / ktx

manage kubernetes cluster configs
Apache License 2.0
135 stars 24 forks source link

Directories getting picked up by ktx #7

Closed tylerauerbeck closed 6 years ago

tylerauerbeck commented 6 years ago

Was playing around with this using minikube as an example. The problem I'm seeing is that ktx will pick up everything underneath the .kube directory even if it isn't a config file. For example, when spinning up minikube, my .kube directory will look like:

 .kube
      cache (directory)
          ....other directories \ files
      config

I'm sure there's a good way around this -- but wasn't sure if this was expected behavior at this point.

chuckha commented 6 years ago

Yes, it sure does! That would be this naive line https://github.com/heptiolabs/ktx/blob/master/ktx-completion.sh#L20 that does an ls on the ~/.kube directory. Something like find ~/.kube -maxdepth 1 -type f would at least ignore directories in the ~/.kube directory, but wouldn't be able to detect only kubeconfig files.

It is expected and it would be great to get fixed.

Thanks for opening an issue

tylerauerbeck commented 6 years ago

@chuckha That makes sense. Just wasn't sure whether that was something that was intended or not. Would it be smarter to do a find from the~/.kube directory down and then have it execute a grep for something specific we know are in kubeconfig files? Something like find ~/.kube -type f -exec grep -il 'kind: Config' {} \; . Depending how folks organize their config files, they may have them sorted out into multiple directories, so not sure limiting to the top level directory would help there.

Going with the above find command, you would be returned the relative path to any matching files, so something like: config1 config 2 ./mydir/config3

Which, depending on who you ask, looks a little ugly. What you could do from there would be parse out just the filename from the matching grep command (could be done within the same find command above) and then when you go to set the config file, you could execute another find command to find the appropriate file. That obviously brings up the issue of what happens if someone has a config with the same name under multiple parent directories

   .kube
        dir1
            alpha
        dir2
            alpha

Obviously a dark hole to climb down to start handling some things like that. I started playing around with this a little bit, but wanted to pick your brain to see if this is what you had in mind for this tool before heading down this path too far.

chuckha commented 6 years ago

closed by #8 Thank you!