Skip to content

plugins: add user-defined shortcuts from config.yaml - #42

Open
beagleknight wants to merge 2 commits into
bjarneo:mainfrom
beagleknight:plugins
Open

plugins: add user-defined shortcuts from config.yaml#42
beagleknight wants to merge 2 commits into
bjarneo:mainfrom
beagleknight:plugins

Conversation

@beagleknight

Copy link
Copy Markdown

What

Add a plugin system. A plugins: list in ~/.config/ku/config.yaml binds a key on the table to an external command, in the spirit of k9s plugins.

plugins:
  - key: ctrl+o
    desc: open dashboard
    scopes: [pods, deployments]
    command: open
    args: ["https://dashboard.example.com/$CLUSTER/$NAMESPACE/$RESOURCE/$NAME"]
    background: true
  • Fields: key, desc, scopes, command, args, background, confirm.
  • Variables $NAMESPACE, $NAME, $RESOURCE, $CONTEXT, $CLUSTER and $KUBECONFIG are expanded in args and exported to the command's environment.
  • The command runs directly, without a shell.
  • background: true runs the command detached and shows the result as a notice. Without it, the command runs in the embedded terminal.
  • confirm: true asks before the run.
  • Scopes accept any string the resource picker resolves, plus all.

Behaviour

  • Plugins show in the footer, the command palette and the help screen for their scoped resources.
  • Keys the table already uses are refused. ku shows a startup notice and skips that plugin.
  • On a duplicate key, the first plugin wins.
  • Plugins run in read-only mode. The user authored them, so ku trusts them.

Code

  • New internal/ui/plugins.go and plugins_test.go.
  • startEdit and plugins share a new startPTY helper.
  • k8s.Client exposes ClusterName for $CLUSTER.
  • Docs updated: docs/configuration.md, docs/keybindings.md, docs/features.md, README.md.

Test

  • make test and make vet pass. 18 new tests.
  • Manual run against a live cluster: background plugin, terminal plugin, confirm flow, palette, footer, help, reserved-key notice, filter capture.

Motivation

I run GitHub Actions runners on Kubernetes (ARC). A plugin resolves a runner pod to its workflow job page and opens it in the browser. The same mechanism covers any "open this row in an external tool" need without adding code to ku.

A `plugins:` list in ~/.config/ku/config.yaml binds a key on the table
to an external command. The command receives the selected row as
$NAMESPACE, $NAME, $RESOURCE, $CONTEXT, $CLUSTER and $KUBECONFIG, both
expanded in `args` and exported to its environment. It runs detached
with a result notice (`background: true`) or inside the embedded
terminal. `confirm: true` asks first. Scopes accept any resource string
the picker resolves, plus `all`.

Plugins appear in the footer, the command palette and the help screen
for the resources they are scoped to. Keys the table already uses are
refused with a startup notice, and the first plugin wins a duplicate
key. Plugins work in read-only mode: the user authored them.

The editor and plugin sessions share a new startPTY helper. The client
exposes ClusterName for $CLUSTER.
@fcsonline

Copy link
Copy Markdown
Contributor

Wow, great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants