Created
April 5, 2019 23:04
-
-
Save mtgto/924a8043cc3848a6ab147bbd759074fa to your computer and use it in GitHub Desktop.
Show Kubernetes context in Powerline segment (need kubernetes-py)
This file contains 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
# -*- coding: utf-8 -*- | |
# I made it because below related libraries doesn't work with python 3.7. | |
# | |
# - https://github.com/zcmarine/powerkube | |
# - https://github.com/so0k/powerline-kubernetes | |
# | |
# NOTE: I don't understand completely how to use powerline watcher. | |
from kubernetes_py import K8sConfig | |
from powerline.theme import requires_filesystem_watcher | |
from os.path import expanduser | |
watcher = None | |
context = '' | |
namespace = '' | |
@requires_filesystem_watcher | |
def kubernetes(pl, create_watcher): | |
global watcher, context, namespace | |
if watcher is None: | |
watcher = create_watcher() | |
config = K8sConfig() | |
context = config.current_context | |
namespace = config.namespace | |
elif watcher("{0}/.kube/config".format(expanduser("~"))): | |
config = K8sConfig() | |
context = config.current_context | |
namespace = config.namespace | |
return [{ | |
'contents': '{}/{}'.format(context, namespace), | |
'highlight_groups': ['information:regular'] | |
}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment