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.

PR #4627
  • Loading branch information
katexochen authored and rycee committed Nov 11, 2023
1 parent e27be9d commit 691cbcc
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 13 deletions.
102 changes: 90 additions & 12 deletions modules/programs/k9s.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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 {
Expand All @@ -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;
};
};
}
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 691cbcc

Please sign in to comment.