Code Monkey home page Code Monkey logo

kube-ps1's Issues

stat: cannot read file system information for '%m': No such file or directory

seeing the following in osx with debug on, the prompt never displays any information.

[⎈ |:]]

+++ stat -f %m /Users/user/.kube/config
stat: cannot read file system information for '%m': No such file or directory
++ mtime='  File: "/Users/user/.kube/config"
    ID: 100000500000018 Namelen: ?       Type: apfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 488475719  Free: 420205592  Available: 418951658
Inodes: Total: 9223372036854775807 Free: 9223372036852263089'
++ [[   File: "/Users/user/.kube/config"
    ID: 100000500000018 Namelen: ?       Type: apfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 488475719  Free: 420205592  Available: 418951658
Inodes: Total: 9223372036854775807 Free: 9223372036852263089 -gt 0 ]]
-bash: [[: File: "/Users/user/.kube/config"
    ID: 100000500000018 Namelen: ?       Type: apfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 488475719  Free: 420205592  Available: 418951658
Inodes: Total: 9223372036854775807 Free: 9223372036852263089: syntax error in expression (error token is ": "/Users/user/.kube/config"
    ID: 100000500000018 Namelen: ?       Type: apfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 488475719  Free: 420205592  Available: 418951658
Inodes: Total: 9223372036854775807 Free: 9223372036852263089")

Add support for aliases

When using kube-ps1 the prompt can be very long as seen in this example:

image

It would be great if one could create a shorter alias for the context (and possibly namespace as well).

For example:

KUBE_PS1_CONTEXT_ALIASES='gke_xxxxxxxxxxxxxxxxxxxxxxx_europe-west1-c_prod=prod, another_context=another'

thus rendering only prod instead of gke_xxxxxxxxxxxxxxxxxxxxxxx_europe-west1-c_prod and another instead of another_context as context name in the prompt.

Rendering Issue

Ubuntu: 16.04
Issue
The latest pull has changed the icon to odd characters.
Example:
[(�⎈ |minikube:default)�]

KUBECONFIG ENV ignored

When using the KUBECONFIG environment variable to change the path to the kubeconfig file it results in the prompt not being updated.

~  (⎈ |minikube:default) export  KUBECONFIG=~/.kube/config-n10
~  (⎈ |minikube:default) kctx
kubernetes-admin@kubernetes

I would have expected my prompt to have changed to

~  (⎈ |kubernetes-admin@kubernetes:default)

seeing empty namespace

kubectl config view --minify --output 'jsonpath={..namespace}' can return empty if you haven't explicitly set the namespace.

I'm seeing (⎈ |minikube:) in my prompt, for instance. Setting a namespace fixes it. So maybe default to "default" if value is missing.

(⎈ |minikube:) ➜  ~ git:(master) kubens default
Context "minikube" modified.
Active namespace is "default".
(⎈ |minikube:default) ➜  ~ git:(master)

kube_ps1 adds 200+ ms to every command

not particularly an issue, but I think calling kube_ps1 function takes about 200ms. this is because kube-ps1 calls kubectl, twice, for each shell prompt.

this is visibly making my shell slower.

  • just keep typing ls(enter), ls(enter), ls(enter) ,ls(enter) and get a feeling for it
  • reset the function: function kube_ps1() {}
  • now run ls(enter), ls(enter), ls(enter) ,ls(enter)
  • much faster without kube_ps1

to measure the delay added, paste this to your shell:

while :; do
    ts=$(date +%s%N) ; kube_ps1 ; tt=$((($(date +%s%N) - $ts)/1000000)) ; echo "Time taken: $tt milliseconds"
done
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 229 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 201 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 238 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 219 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 204 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 210 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 207 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 203 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 208 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 209 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 198 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 208 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 219 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 242 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 218 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 208 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 220 milliseconds

I'll talk about some potential improvements in the next isssue.

Compatibility with oh-my-zsh

Is this working with oh-my-zsh?

I am on a CentOS 7 machine and I have kubectl installed. I am using oh-my-zsh with agnoster as a theme.

I have added the following lines in my .zshrc file but nothing is happening when I source /.zshrc`:

source /path/to/kube-ps1.sh
PROMPT='$(kube-ps1)'$PROMPT

For zsh prompt config error

As the README, config ~/.zshrc

source /path/to/kube-ps1.sh
PROMPT='$(kube_ps1) $PROMPT'

Get this prompt:

(⎈ |kubernetes:default)$(kube_ps1) $PROMPT

Change to

PROMPT='$(kube_ps1)'$PROMPT

Get this:

(⎈ |kubernetes:dev)➜  ~

Add ability to specify background color

I'd like to change the background color of prompt so it would be nice if this would be available as a configuration option. Currently I do like this to get it to work the way I want:

PROMPT=%{$bg[white]%}'$(kube_ps1)'$PROMPT

command not found: add-zsh-hook

Hi, there, after I ran upgrade_oh_my_zsh and restarted shell, I get this:

.oh-my-zsh/plugins/kube-ps1/kube-ps1.plugin.zsh:24: command not found: add-zsh-hook

Best regards

Faster ways to calculate context/namespace

As seen in #4, kube_ps1 shell function is slow (adds about 200 ms to every shell prompt users get).
This is because kubectl is not a fast program as one would think and it has a startup latency.

I have a few ideas to make this faster. Here's my top idea that I think can work really fast:

  • make yq (https://github.com/kislyuk/yq) (or another yaml parser) a mandatory dependency for this script
  • figure out where the kubectl config file is ($KUBECONFIG if set, otherwise ~/.kube/config)
  • read the namespace/context with a cat $f | yq (..path-query..).

this should be muuuchhhh faster, I bet it can complete within 10 ms, which is an acceptable delay.

empty KUBE_PS1_SEPARATOR not working

export KUBE_PS1_SEPARATOR=''

when I specify that I still get the | character:

{⎈ |test:default}

any other non-empty value works fine, however.

Ability to hide namespace

Would it be possible and make sense to add an environment variable that hides the namespace? In my case I virtually never change the namespace so I might as well not show it.

Whitespace is appended on tab completion

Hey,
thanks for this nice tool. I have just one problem: Everytime i hit tab to complete paths in zsh, it appends a whitespace and thus destroys further navigation with tab.
Any idea?
Here is my config (.zshrc):

source /usr/local/Cellar/kube-ps1/0.6.0/share/kube-ps1.sh
KUBE_PS1_SYMBOL_USE_IMG=true
KUBE_PS1_SYMBOL_ENABLE=true
KUBE_PS1_NS_ENABLE=true
PROMPT=$(kube_ps1)$PROMPT
KUBE_PS1_BG_COLOR=black

Specifying different color for bash prompt

Hello,

I'm trying to specify a different color for the Kubernetes context according to the documentation for bash but this doesn't seem to work.
Would you be able to assist me with this ?
I basically want to modify the context color from red to purple.

Thanks.

Regards,
Dieter.

Add LICENSE

I see it's on the file, but would be nice to have in repo root as a file as well. GitHub detects that and shows in the UI.

Kubernetes context not loaded on shell creation

Hello,

I've sourced the kube-ps1.sh file in my bash configuration and modified my bash prompt to include the kubernetes context information.
However, it seems that when I open a new shell for the first time, the kubernetes context is not loaded. Only after hitting 'Enter' on the command line, is the context loaded.
See my prompt output below.

Last login: Sun Jan 21 19:25:42 on ttys002
(⎈ |:) » ~
(⎈ |docker-for-desktop:default) » ~

Any idea what could be wrong in my configuration ?

Thanks.

KUBE_PS1_SEPARATOR not working

(⎈ |test:default) ➜  ~ export KUBE_PS1_PREFIX=''
⎈ |test:default) ➜  ~ export KUBE_PS1_SEPARATOR=''
⎈ |test:default) ➜  ~ export KUBE_PS1_SEPARATOR='x'
⎈ |test:default) ➜  ~

bash error

In bash following lines are not working. Removing parts in brackets is work arounding it.

https://github.com/jonmosco/kube-ps1/blob/master/kube-ps1.sh#L31-L34

github.com/jonmosco/kube-ps1/kube-ps1.sh: line 31: conditional binary operator expected
github.com/jonmosco/kube-ps1/kube-ps1.sh: line 31: syntax error near KUBE_PS1_PREFIX' github.com/jonmosco/kube-ps1/kube-ps1.sh: line 31: [[ -v KUBE_PS1_PREFIX ]] || KUBE_PS1_PREFIX="("'

Enabling kube-ps1 messes up completion in zsh?

It looks like my zsh completion doesn't work as expected when the kube-ps1 prompt is enabled. This is the relavant parts of my ~/.zshrc file:

KUBE_PS1_SYMBOL_USE_IMG=true
KUBE_PS1_SYMBOL_ENABLE=true
KUBE_PS1_SEPARATOR=' '
KUBE_PS1_PREFIX=''
KUBE_PS1_SUFFIX=''
KUBE_PS1_NS_ENABLE=false
source ~/.zsh/scripts/kube-ps1.sh
PROMPT='$(kube_ps1)'$PROMPT
# Disable kube prompt by default, enable with "kubeon"
kubeoff

The prompt now looks like this when I start a new window:
image

If I enter kubec and press tab it's expanded to:
image

But when I run kubeon and enter kubec and pressing tab I get this:
image

Notice the extra "k" that is inserted.

Do not load zsh modules

kube-ps1/kube-ps1.sh

Lines 61 to 62 in 7d06e2d

zmodload zsh/stat
zmodload zsh/datetime

This caused me at least 1 hour of debugging.

I was trying to figure out what the hell is loading zsh stat module, because it prevented me from calling the actual stat binary on my machine.

Please remove these lines. It's unexpected for a simple tool like kube-ps1 to have substantial side-effects like this.

on/off -g does not change the current session

Starting state: kubeoff -g, run 3 shell windows

When I run kubeon -g on the current shell, I expect:

  • current shell will turn on the PS1
  • new shells will also have PS1 turned on
  • already open shells (other tabs) will not change behavior when I hit return

Current behavior:

  • current shell doesn't turn on PS1 (UNEXPECTED)
  • new shells have PS1 turned on
  • already open shells (other tabs) are turning it on (UNEXPECTED)

Starting state: kubeon -g, run 3 shell windows

When I run kubeoff -g on the current shell, I expect:

  • current shell will turn OFF the PS1
  • new shells will also have PS1 turned OFF
  • already open shells (other tabs) will not change behavior when I hit return

Current behavior:

  • current shell doesn't turn off PS1 (UNEXPECTED)
  • new shells have PS1 turned off
  • already open shells (other tabs) are turning it on (UNEXPECTED)

Are my expectations not accurate? I kind of expected kubeon/kubeoff to work this way.

Do not update ps1 cache if kube config's file type is symlink

stat function does not check target file's changed time but symlink files' changed time. Therefore, _kube_ps1_file_newer_than function always return false if kube config file is symlink

_kube_ps1_file_newer_than() {
  local mtime
  local file=$1
  local check_time=$2

  if [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then
    mtime=$(stat +mtime "${file}")
  elif stat -c "%s" /dev/null &> /dev/null; then
    # GNU stat
    mtime=$(stat -c %Y "${file}")
  else
    # BSD stat
    mtime=$(stat -f %m "$file")
  fi

  [[ "${mtime}" -gt "${check_time}" ]]
}

Display kube-ps1 prompt on the right side of the terminal

Could you possibly add the ability to display the kube_ps1 part of the prompt on the right side of the terminal (refer to screenshots).

This is how kube-ps1 looks in my terminal window:
screen shot 2018-08-14 at 17 49 11

And this is how zsh-kubectl-prompt looks in my terminal window:
screen shot 2018-08-14 at 17 49 50

I think a custom option that would implement this functionality would also be extremely useful for people who use bullet train/powerline9k type themes where the prompt tends to get pretty long.

If there is already a way through which I can accomplish this by modifying my zsh config then do let me know, I'd highly appreciate that and would love to switch to over to kube-ps1.

command not found: add-zsh-hook

I just downloaded from master and sourced, but I got:

_kube_ps1_shell_settings:4: command not found: add-zsh-hook

I'm using oh-my-zsh on Mac.

kubeon/kubeoff not working as expected

  1. open terminal tab → kube-ps1 string shows (expected)
  2. kubeoff -g→ hides kube-ps1 string (expected)
  3. kubeon → ps1 string still does not show up (NOT EXPECTED)

side-effect/overriden environment variables

the following doesn't work for two reasons:

# .zshrc file:
export KUBE_PS1_PREFIX='['
export KUBE_PS1_SUFFIX=']'
source "$HOME/workspace/dotfiles/kube-ps1.sh"
  1. it ignores my settings
  2. replaces the passed value with the defaults ( and ).
(⎈ |docker-for-desktop:default) ➜  ~ env | grep KUBE
KUBE_PS1_PREFIX=(
KUBE_PS1_SUFFIX=)

ideally the order of export and source shouldn't matter in this case I think.

If I move export after sourcing, it works.

Could not customize KUBE_PS1_SYMBOL_DEFAULT on bash

Hello, I'm using a font that didn't support the unicode symbol \u2388, so I try to customize the symbol in ~/.bashrc, then I found the symbol is hard coded in the bash block of _kube_ps1_symbol(), not using the KUBE_PS1_SYMBOL_DEFAULT.
I think this is the reason why the customization of the symbol not taking effect, tried to fix it and tested on bash 4.x.
Due to the different encode way , I don't know how to fix it on bash version lower than 4.x, because I don't have the envirment to test it, does anyone have a good idea?

wrong unicode symbols

I see similar issue was reported but closed here.
In my case (Linux Mint 18.3 Sylvia) it looks like this:

image

I fixed it by using:
_KUBE_PS1_OPEN_ESC=$'' _KUBE_PS1_CLOSE_ESC=$''
instead of:
_KUBE_PS1_OPEN_ESC=$'\001' _KUBE_PS1_CLOSE_ESC=$'\002'

Why is kubeon/kubeoff deprecated now?

kubeon/kubeoff no longer seems to work with comments indicating deprecation in the source code.

Was there a discussion about this? I’m lately a little frustrated in number of the ways the project is getting in my way of doing things.

I have developed kubectx/kubens so people set it up once and forget about it. So far I tend to think I achieved that. I have ideas to add there but I’ve been holding off on making major changes, because a lot of people tell me that it’s very much central to their day-to-day workflow.

I want to see the same from kube-ps1. However, so far my experience is reflecting it's been the case that things keep breaking, too many configurable knobs mostly untested, kubeon/kubeoff stops working either because of badly implemented state machine or some arbitrary deprecation.

I am no longer able to keep up with these changes. If you are seeking help or guidance on this project, I can provide support such as reviewing every single commit. But I can no longer stand the fact that this project is being pulled to different directions in many directions. I just want it to work.

Does not work when bash-git-prompt is already installed.

Installed bash-git-prompt using brew before on my MacOS.

Here is how my ~/.bash_profile look like:

if [ -f $(brew --prefix)/etc/bash_completion ]; then
    source $(brew --prefix)/etc/bash_completion
fi

if [ -f $(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh ]; then
    __GIT_PROMPT_DIR=$(brew --prefix)/opt/bash-git-prompt/share
    source $(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh
fi

if [ -f $(brew --prefix)/opt/kube-ps1/share/kube-ps1.sh ]; then
    source $(brew --prefix)/opt/kube-ps1/share/kube-ps1.sh
    PS1='$(kube_ps1) $(__git_ps1)'
fi

However the new terminal window only shows git prompt.

I also tried putting the new lines in ~/.bashrc as said in the installation setup, but no luck.

I also tried putting the new lines before git-prompt setup, but no luck.

The only way to get kube_ps1 to work is to remove git-prompt.

Trim cluster name & namespace name

For long cluster names & namespaces it takes a lot of space in a prompt:
(kubernetes.us-west-2.dev.subenv.company.domain:application.namepsace)~prompt$

Two options can be introduced:

  • namespace trim len
  • cluster trim len

setting both to 10 will end to:
(kube.us-we..:applicatio..)~prompt$
default: -1 (no trim)

Proposal: kubeon/kubeoff

I propose we introduce these commands kubeon/kubeoff to indicate whether we want Kubernetes status shown on our ps1 or not.

  • kubeoff would create a sentinel file, say, ~/.kube/ps1/off. When this exists, the kube_ps1 would return empty string/noop, so no Kubernetes shown in PS1.
  • kubeon would delete that file.

Fails if there's no config in ~/.kube

I have 3 different contexts, all set in KUBECONFIG.
kube-prompt fails when I try to get a certain pod or service

>>> get pods panic: stat /Users/tarekmehrez/.kube/config: no such file or directory

goroutine 36 [running]:
github.com/c-bata/kube-prompt/kube.NewClient(0x0)
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/client.go:29 +0x140
github.com/c-bata/kube-prompt/kube.getClient(0x0)
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/client.go:14 +0x2e
github.com/c-bata/kube-prompt/kube.fetchPods()
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/resource.go:177 +0x72
created by github.com/c-bata/kube-prompt/kube.getPodSuggestions
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/resource.go:183 +0x39

Is there a way that this might work just by checking my current context?

Prompt is slow when enabled

First off, awesome prompt! I enabled it and noticed that it appears to significantly slow down my prompt. The simple test is hitting enter a few times. If I run kubeoff the response is immediate, but if I run kubeon then hitting enter multiple times results in a rather significant delay. Unfortunately, I have not had much time to look into why this might be the case, but figured I would file an issue.

Proposal: kubeon/kubeoff should only affect current session

Kubeon/off currently applies to all shells based off a file check.

I think these functions could be more useful if they apply to the current session only. This can be achieved by setting and unsetting a variable:

KUBE_PS1_DISABLE=true
unset KUBE_PS1_DISABLE
then test for this on kube_ps1

retake demo.gif

It looks like it's outdated.

It can now use kubeon/kubeoff, along with the usual kubectx/kubens jazz!

kube-ps1 messed up my kubectl bash completion

Hi!

I've installed kube-ps1 but it messed my bash completion :(
It completes commands properly but not resources names (for instance pod names).

It still won't work, even after I've uninstalled kube-ps1.

Some help would be really appreciated, thanks!

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.