Skip to content

Commit

Permalink
k9s: add aliases, plugins, views
Browse files Browse the repository at this point in the history
Adding the remaining config files of k9s that weren't covered yet.

Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
  • Loading branch information
katexochen committed Nov 2, 2023
1 parent 48b0a30 commit 2dc6ed5
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 1 deletion.
89 changes: 89 additions & 0 deletions modules/programs/k9s.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ 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 = { };
Expand All @@ -72,6 +89,66 @@ 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 {
Expand All @@ -85,8 +162,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;
};
};
}
2 changes: 2 additions & 0 deletions tests/modules/programs/k9s/example-aliases-expected.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alias:
pp: v1/pods
16 changes: 16 additions & 0 deletions tests/modules/programs/k9s/example-plugin-expected.yml
Original file line number Diff line number Diff line change
@@ -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
37 changes: 36 additions & 1 deletion tests/modules/programs/k9s/example-settings.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand All @@ -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}
'';
}
11 changes: 11 additions & 0 deletions tests/modules/programs/k9s/example-views-expected.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
k9s:
views:
v1/pods:
columns:
- AGE
- NAMESPACE
- NAME
- IP
- NODE
- STATUS
- READY

0 comments on commit 2dc6ed5

Please sign in to comment.