k9s: add aliases, plugins, views

Adding the remaining config files of k9s that weren't covered yet.

PR #4627
This commit is contained in:
Paul Meyer 2023-11-02 07:51:00 +01:00 committed by Robert Helgesson
parent e27be9db7b
commit 691cbcc03a
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
5 changed files with 155 additions and 13 deletions

View file

@ -20,10 +20,8 @@ in {
type = yamlFormat.type;
default = { };
description = ''
Configuration written to
{file}`$XDG_CONFIG_HOME/k9s/config.yml`. See
<https://k9scli.io/topics/config/>
for supported values.
Configuration written to {file}`$XDG_CONFIG_HOME/k9s/config.yml`. See
<https://k9scli.io/topics/config/> for supported values.
'';
example = literalExpression ''
k9s = {
@ -36,10 +34,8 @@ in {
type = yamlFormat.type;
default = { };
description = ''
Skin written to
{file}`$XDG_CONFIG_HOME/k9s/skin.yml`. See
<https://k9scli.io/topics/skins/>
for supported values.
Skin written to {file}`$XDG_CONFIG_HOME/k9s/skin.yml`. See
<https://k9scli.io/topics/skins/> for supported values.
'';
example = literalExpression ''
k9s = {
@ -50,14 +46,27 @@ in {
'';
};
aliases = mkOption {
type = yamlFormat.type;
default = { };
description = ''
Aliases written to {file}`$XDG_CONFIG_HOME/k9s/aliases.yml`. See
<https://k9scli.io/topics/aliases/> for supported values.
'';
example = literalExpression ''
alias = {
# Use pp as an alias for Pod
pp = "v1/pods";
};
'';
};
hotkey = mkOption {
type = yamlFormat.type;
default = { };
description = ''
hotkeys written to
{file}`$XDG_CONFIG_HOME/k9s/hotkey.yml`. See
<https://k9scli.io/topics/hotkeys/>
for supported values.
Hotkeys written to {file}`$XDG_CONFIG_HOME/k9s/hotkey.yml`. See
<https://k9scli.io/topics/hotkeys/> for supported values.
'';
example = literalExpression ''
hotkey = {
@ -72,6 +81,63 @@ in {
};
'';
};
plugin = mkOption {
type = yamlFormat.type;
default = { };
description = ''
Plugins written to {file}`$XDG_CONFIG_HOME/k9s/plugin.yml`. See
<https://k9scli.io/topics/plugins/> for supported values.
'';
example = literalExpression ''
plugin = {
# Defines a plugin to provide a `ctrl-l` shortcut to
# tail the logs while in pod view.
fred = {
shortCut = "Ctrl-L";
description = "Pod logs";
scopes = [ "po" ];
command = "kubectl";
background = false;
args = [
"logs"
"-f"
"$NAME"
"-n"
"$NAMESPACE"
"--context"
"$CLUSTER"
];
};
};
'';
};
views = mkOption {
type = yamlFormat.type;
default = { };
description = ''
Resource column views written to {file}`$XDG_CONFIG_HOME/k9s/views.yml`.
See <https://k9scli.io/topics/columns/> for supported values.
'';
example = literalExpression ''
k9s = {
views = {
"v1/pods" = {
columns = [
"AGE"
"NAMESPACE"
"NAME"
"IP"
"NODE"
"STATUS"
"READY"
];
};
};
};
'';
};
};
config = mkIf cfg.enable {
@ -85,8 +151,20 @@ in {
source = yamlFormat.generate "k9s-skin" cfg.skin;
};
xdg.configFile."k9s/aliases.yml" = mkIf (cfg.aliases != { }) {
source = yamlFormat.generate "k9s-aliases" cfg.aliases;
};
xdg.configFile."k9s/hotkey.yml" = mkIf (cfg.hotkey != { }) {
source = yamlFormat.generate "k9s-hotkey" cfg.hotkey;
};
xdg.configFile."k9s/plugin.yml" = mkIf (cfg.plugin != { }) {
source = yamlFormat.generate "k9s-plugin" cfg.plugin;
};
xdg.configFile."k9s/views.yml" = mkIf (cfg.views != { }) {
source = yamlFormat.generate "k9s-views" cfg.views;
};
};
}

View file

@ -0,0 +1,2 @@
alias:
pp: v1/pods

View file

@ -0,0 +1,16 @@
plugin:
fred:
args:
- logs
- -f
- $NAME
- -n
- $NAMESPACE
- --context
- $CLUSTER
background: false
command: kubectl
description: Pod logs
scopes:
- po
shortCut: Ctrl-L

View file

@ -35,6 +35,29 @@
};
};
};
aliases = { alias = { pp = "v1/pods"; }; };
plugin = {
plugin = {
fred = {
shortCut = "Ctrl-L";
description = "Pod logs";
scopes = [ "po" ];
command = "kubectl";
background = false;
args =
[ "logs" "-f" "$NAME" "-n" "$NAMESPACE" "--context" "$CLUSTER" ];
};
};
};
views = {
k9s = {
views = {
"v1/pods" = {
columns = [ "AGE" "NAMESPACE" "NAME" "IP" "NODE" "STATUS" "READY" ];
};
};
};
};
};
nmt.script = ''
@ -43,12 +66,24 @@
home-files/.config/k9s/config.yml \
${./example-config-expected.yml}
assertFileExists home-files/.config/k9s/skin.yml
assertFileExists home-files/.config/k9s/hotkey.yml
assertFileContent \
home-files/.config/k9s/skin.yml \
${./example-skin-expected.yml}
assertFileExists home-files/.config/k9s/hotkey.yml
assertFileContent \
home-files/.config/k9s/hotkey.yml \
${./example-hotkey-expected.yml}
assertFileExists home-files/.config/k9s/aliases.yml
assertFileContent \
home-files/.config/k9s/aliases.yml \
${./example-aliases-expected.yml}
assertFileExists home-files/.config/k9s/plugin.yml
assertFileContent \
home-files/.config/k9s/plugin.yml \
${./example-plugin-expected.yml}
assertFileExists home-files/.config/k9s/views.yml
assertFileContent \
home-files/.config/k9s/views.yml \
${./example-views-expected.yml}
'';
}

View file

@ -0,0 +1,11 @@
k9s:
views:
v1/pods:
columns:
- AGE
- NAMESPACE
- NAME
- IP
- NODE
- STATUS
- READY