Created
September 30, 2020 23:15
-
-
Save phwelo/c9692bfd8595fe97097538108d98ac50 to your computer and use it in GitHub Desktop.
Quick kube switcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # HEADS UP: Requires that kubeconfig files be named `config.description`!!! | |
| from iterfzf import iterfzf | |
| import glob | |
| import os | |
| import shutil | |
| searchpath = "/.kube/config.*" | |
| configpath = "/.kube/config" | |
| def list_kubeconfigs(path): | |
| return glob.glob(path) | |
| def give_choice(kc_list): | |
| nicer_list = [] | |
| for index, kc in enumerate(kc_list): | |
| nicer_list.append(str(index) + ": "+ kc.split("/")[4]) | |
| return kc_list[int(str(iterfzf(nicer_list))[0])] | |
| def implement_choice(filepath): | |
| shutil.copy(filepath, os.path.expanduser("~") + configpath) | |
| def main(): | |
| kc_searchpath = os.path.expanduser("~") + searchpath | |
| kcs = list_kubeconfigs(kc_searchpath) | |
| kc_path = give_choice(kcs) | |
| implement_choice(kc_path) | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment