feat(kube-ps1): add kube-ps1 plugin#736
Conversation
Review Summary by QodoAdd kube-ps1 plugin for Kubernetes prompt integration
WalkthroughsDescription• Adds new kube-ps1 plugin displaying Kubernetes context and namespace • Implements kubeon/kubeoff commands for interactive toggling • Includes efficient kubeconfig file watching to minimize prompt overhead • Supports persistent global state via ~/.kube/kube-ps1/disabled marker Diagramflowchart LR
A["kube-ps1 Plugin"] --> B["kube_ps1 Function"]
A --> C["kubeon/kubeoff Commands"]
A --> D["PROMPT_COMMAND Hook"]
B --> E["Display Context & Namespace"]
C --> F["Toggle On/Off"]
D --> G["Watch kubeconfig Files"]
G --> H["Update Prompt Segment"]
F --> I["Persist State Globally"]
File Changes1. plugins/kube-ps1/kube-ps1.plugin.sh
|
Code Review by Qodo
1.
|
|
@rafacouto Thank you for this. I was just considering how I would do this myself. A few things:
|
…space for newline endings
…improve reliability
|
I've tested this plugin a lot in my environment and it works without problems... The bugs announced by Qodo have been fixed. What would be necessary to incorporate it into OMB? |
akinomyoga
left a comment
There was a problem hiding this comment.
I realized that my comments have been left "pending" in the GitHub interface.
| # --------------------------------------------------------------------------- | ||
| # | ||
| # This file is a derivative work based on kube-ps1 | ||
| # <https://github.com/jonmosco/kube-ps1>. |
There was a problem hiding this comment.
Is this based on which commit of jonmosco/kube-ps1? Could you include the link in the form of e.g. https://github.com/jonmosco/kube-ps1/blob/9b41c091d5dd4a99e58cf58b5d98a4847937b1bb/kube-ps1.sh?
| # Debug | ||
| [[ -n ${DEBUG:-} ]] && set -x |
There was a problem hiding this comment.
Could you remove this? This is undocumented. Also, the variable DEBUG may be used by a user for a different purpose, in which case this would cause results surprising to the user.
| # Use an index loop so hooks registered mid-cycle (e.g. by earlier hooks) are | ||
| # picked up in the same prompt-render cycle rather than deferred to the next. | ||
| for ((i = 0; i < ${#_omb_util_prompt_command[@]}; i++)); do |
There was a problem hiding this comment.
I doubt if we should do this. I think we can't say the original behavior is wrong, but it's just a design. Then, this PR tries to modify an existing utility that others have relied on, just to make the behavior useful for a specific plugin. This doesn't seem safe.
Closes #719
Description
Adds a new
kube-ps1plugin that displays the current Kubernetes context andnamespace in the shell prompt, with
kubeon/kubeoffcommands to toggle itinteractively.
Changes
plugins/kube-ps1/kube-ps1.plugin.sh— main pluginplugins/kube-ps1/README.md— documentation and configuration referenceplugins/kube-ps1/LICENSE— Apache 2.0 license from the upstream project (required by its license terms)plugins/README.md— addedkube-ps1entry to the plugin tableImplementation details
_omb_plugin_kube_ps1_*naming convention._omb_util_add_prompt_command()and_omb_util_command_exists()from the OMB API.kube_ps1segment is injected intoPS1via a lazy-registered post-theme hook, so it works correctly regardless of which theme is active — no theme modifications required.kubeon -g/kubeoff -gpersist the state across sessions via~/.kube/kube-ps1/disabled.Usage
# ~/.bashrc plugins=(... kube-ps1)