Skip to content

Instantly share code, notes, and snippets.

@phwelo
Created September 30, 2020 23:15
Show Gist options
  • Select an option

  • Save phwelo/c9692bfd8595fe97097538108d98ac50 to your computer and use it in GitHub Desktop.

Select an option

Save phwelo/c9692bfd8595fe97097538108d98ac50 to your computer and use it in GitHub Desktop.
Quick kube switcher
#!/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