Git Product home page Git Product logo

powerline-kubernetes's Introduction

Powerline Kubernetes PyPI version

A Powerline segment to show the current Kubernetes context.

This segment shows the Kubernetes context together with a nice looking helm. Please feel free to propose more features and give me ideas on how to improve it.

Update: Now completely compatible with Kubernetes API 9.0.

## Requirements

The Kubernetes segment requires kubectl and official kubernetes Python API.

## Installation

Installing the Kubernetes segment can be done with pip:

$ pip install powerline-kubernetes

The Kubernetes segment uses a couple of custom highlight groups. You'll need to define those groups in your colorscheme, for example in .config/powerline/colorschemes/default.json:

{
  "groups": {
    "kubernetes_cluster":         { "fg": "gray10", "bg": "darkestblue", "attrs": [] },
    "kubernetes_cluster:alert":   { "fg": "gray10", "bg": "darkestred",  "attrs": [] },
    "kubernetes_namespace":       { "fg": "gray10", "bg": "darkestblue", "attrs": [] },
    "kubernetes_namespace:alert": { "fg": "gray10", "bg": "darkred",     "attrs": [] },
    "kubernetes:divider":         { "fg": "gray4",  "bg": "darkestblue", "attrs": [] },
  }
}

Then you can activate the Kubernetes segment by adding it to your segment configuration, for example in .config/powerline/themes/shell/default.json:

{
    "function": "powerline_kubernetes.kubernetes",
    "priority": 30,
    "args": {
        "show_kube_logo": true, // set to false to omit the Kube logo
        "show_cluster": true, // show cluster name
        "show_namespace": true, // show namespace name
        "show_default_namespace": false, // do not show namespace name if it's "default"
        "alerts": [
          "live", // show line in different color when namespace matches
          "cluster:live"  // show line in different color when cluster name and namespace match
        ]
    }
}

By default the segment will look for the Kubernetes config under ~/.kube/config.

## License

Licensed under the MIT License.

Authors

Created by so0k. Code contributions by:


Inspired by powerline-docker.

powerline-kubernetes's People

Contributors

bokysan avatar csmarchbanks avatar so0k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

powerline-kubernetes's Issues

Errors out for minikube

While i have this working well for other contexts, it does not work for minikube
on running appropriate render eg: powerline-render tmux right
I see following error.
2020-01-17 11:32:25,125:ERROR:tmux:kubernetes:'namespace'

kubernetes version v1.16.2
relevant part of minikube output

😄 minikube v1.5.2 on Darwin 10.15.2
💡 Tip: Use 'minikube start -p <name>' to create a new cluster, or 'minikube delete' to delete this one.
🔄 Starting existing hyperkit VM for "minikube" ...
⌛ Waiting for the host to be provisioned ...
🐳 Preparing Kubernetes v1.16.2 on Docker '18.09.9' ...

What troubleshooting steps should I take when segment is not showing

I believe I've followed all the steps correctly. However segment is not showing in either shell or tmux.

I can verify that the powerline_kubernetes module works fine individually:

Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import powerline_kubernetes
>>> s = powerline_kubernetes.segments.KubernetesSegment()
>>> s.config['clusters'][0]['name']
'minikube'
>>>

Here is my themes/tmux/default.json:

{
    "segments": {
        "left": [
            {
                "function": "powerline_gitstatus.gitstatus"
            }
        ],
        "right": [
            {
                "function": "powerline.segments.common.sys.cpu_load_percent",
                "args": {
                    "interval": 5
                }
            },
            {
                "function": "powerline_docker.docker"
            },
            {
                "function": "powerline_kubernetes.kubernetes",
                "args": {
                    "show_kube_logo": true,
                    "show_cluster": true,
                    "show_namespace": true,
                    "show_default_namespace": false,
                    "alerts": [
                        "prod"
                    ]
                }
            },
            {
                "function": "powerline.segments.common.net.hostname"
            }
        ]
    }
}

I did add following lines to the corresponding colorscheme file (tried both colorscheme/default.json and colorscheme/tmux/default.json):

        "kubernetes":                 { "fg": "yellow",          "bg": "darkblue", "attrs": [] },
        "kubernetes:divider":         { "fg": "gray4",           "bg": "darkblue", "attrs": [] },
        "kubernetes_cluster":         { "fg": "gray10", "bg": "darkestblue", "attrs": [] },
        "kubernetes_cluster:alert":   { "fg": "gray10", "bg": "darkestred",  "attrs": [] },
        "kubernetes_namespace":       { "fg": "gray10", "bg": "darkestblue", "attrs": [] },
        "kubernetes_namespace:alert": { "fg": "gray10", "bg": "darkred",     "attrs": [] },

BTW, powerline_docker works for me fine.

Please help. Thanks!

Prompt hangs on kubernetes issue

2016-11-09 10:35:37,851:ERROR:shell:docker:UnixHTTPConnectionPool(host='localhost', port=None): Read timed out. (read timeout=60)

Very long contexts when using with OpenShift

When using powerline-kubernetes with OpenShift, the context part usually gets very long, e.g.:

⎈ explore-00/master-asdf-openshift3roadshow-com:443/user00 - explore-00

A config parameter permitting to either only display the namespace or the context would be great.

bash ubuntu 18.04 doesn't worrk

Hey mate,

My default_leftonly.json
In a config.json I use default_leftonly but it doesn't work. Can you post your config.json and left_only?

shell": {
                        "colorscheme": "default",
                        "theme": "default",
                        "local_themes": {
                                "continuation": "default_leftonly",
                                "select": "select"
                        }


`{
        "segments": {
                "left": [
                        {
                                "function": "powerline.segments.common.net.hostname",
                                "priority": 10
                        },
                        {
                                "function": "powerline.segments.common.env.user",
                                "priority": 30
                        },
                        {
                                "function": "powerline.segments.common.env.virtualenv",
                                "priority": 50
                        },
                        {
                                "function": "powerline.segments.common.vcs.branch",
                                "priority": 40
                        },
                        {
                                "function": "powerline.segments.shell.cwd",
                                "priority": 10
                        },
                        {
                                "function": "powerline.segments.shell.jobnum",
                                "priority": 20
                        },
                        {
                                "function": "powerline.segments.shell.last_status",
                                "priority": 10
                        },
                         {
                                 "function": "powerline_kubernetes.kubernetes",
                                 "priority": 30,
                                   "args": {
                                                "show_kube_logo": true,
                                                "show_cluster": true,
                                                "show_namespace": true,
                                                "show_default_namespace": true,
                                                "alerts": [
                                                        "live",
                                                         "cluster:live"
                                                        ]
                                             }
                        }

                ]
        }
}

Kube Config Context Without a Namespace Causes Error

I have a kubeconfig that looks like:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: ...
    server: ...
  name: ...
contexts:
- context:
    cluster: ...
    user: ...
  name: ...
current-context: ...
kind: Config
preferences: {}
users:
- name: ...
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - token
      - -i
      - ...
      command: ...
      env:
        - name: ...
          value: ...

and when I powerline-daemon --kill I get an error similar to:

2019-12-03 10:15:52,043:ERROR:shell:kubernetes:'namespace'

I think c366a55#diff-5206fb189568a38aa689ef479153c15d intended to fix this but there's two instances of namespace = ctx['namespace'].

Kube config context without current-context causes error

Hi,
I updated all my python-modules to the latest versions, and therefore powerline-kubernetes was updated as well.

I use minkube to start (and stop) clusters locally, and when you stop minikube, it sets the current-context in the kube-config file to current-context: ""

Powerline-kubernetes cannot handle that very well, and gives me this error-message:
2019-12-28 17:55:16,301:ERROR:shell:kubernetes:Invalid kube-config file. Expected key current-context in kube-config

Is it possible to silence this error? Or just not let it error, but just act the same is if there wasn't a kube-config file available to read?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.