k9s: fix config files not generated correctly & improve options (#7262)

This commit is contained in:
Josef Hofer
2025-06-23 05:55:09 +02:00
committed by GitHub
parent 6fa01d524b
commit 520fc4b50a
7 changed files with 144 additions and 101 deletions

View File

@@ -33,6 +33,8 @@ in
"skin"
]
)
(lib.mkRenamedOptionModule [ "programs" "k9s" "hotkey" ] [ "programs" "k9s" "hotKeys" ])
(lib.mkRenamedOptionModule [ "programs" "k9s" "plugin" ] [ "programs" "k9s" "plugins" ])
];
options.programs.k9s = {
@@ -86,14 +88,14 @@ in
<https://k9scli.io/topics/aliases/> for supported values.
'';
example = literalExpression ''
alias = {
{
# Use pp as an alias for Pod
pp = "v1/pods";
};
}
'';
};
hotkey = mkOption {
hotKeys = mkOption {
type = yamlFormat.type;
default = { };
description = ''
@@ -102,20 +104,17 @@ in
<https://k9scli.io/topics/hotkeys/> for supported values.
'';
example = literalExpression ''
hotkey = {
# Make sure this is camel case
hotKey = {
shift-0 = {
shortCut = "Shift-0";
description = "Viewing pods";
command = "pods";
};
{
shift-0 = {
shortCut = "Shift-0";
description = "Viewing pods";
command = "pods";
};
};
}
'';
};
plugin = mkOption {
plugins = mkOption {
type = yamlFormat.type;
default = { };
description = ''
@@ -124,7 +123,7 @@ in
<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 = {
@@ -143,7 +142,7 @@ in
"$CLUSTER"
];
};
};
}
'';
};
@@ -157,21 +156,19 @@ in
See <https://k9scli.io/topics/columns/> for supported values.
'';
example = literalExpression ''
k9s = {
views = {
"v1/pods" = {
columns = [
"AGE"
"NAMESPACE"
"NAME"
"IP"
"NODE"
"STATUS"
"READY"
];
};
{
"v1/pods" = {
columns = [
"AGE"
"NAMESPACE"
"NAME"
"IP"
"NODE"
"STATUS"
"READY"
];
};
};
}
'';
};
};
@@ -206,6 +203,16 @@ in
in
mkIf cfg.enable {
home.packages = lib.mkIf (cfg.package != null) [ cfg.package ];
warnings =
(lib.optional (cfg.aliases ? alias)
"Nested 'alias' key in programs.k9s.aliases is deprecated, move the contents directly under programs.k9s.aliases"
)
++ (lib.optional (cfg.plugins ? plugin)
"Nested 'plugin' key in programs.k9s.plugins is deprecated, move the contents directly under programs.k9s.plugins"
)
++ (lib.optional (cfg.views ? k9s.views)
"Nested 'k9s.views' structure in programs.k9s.views is deprecated, move the contents directly under programs.k9s.views"
);
xdg.configFile = mkIf enableXdgConfig (
{
@@ -214,19 +221,19 @@ in
};
"k9s/aliases.yaml" = mkIf (cfg.aliases != { }) {
source = yamlFormat.generate "k9s-aliases" cfg.aliases;
source = yamlFormat.generate "k9s-aliases" { inherit (cfg) aliases; };
};
"k9s/hotkeys.yaml" = mkIf (cfg.hotkey != { }) {
source = yamlFormat.generate "k9s-hotkey" cfg.hotkey;
"k9s/hotkeys.yaml" = mkIf (cfg.hotKeys != { }) {
source = yamlFormat.generate "k9s-hotkeys" { inherit (cfg) hotKeys; };
};
"k9s/plugins.yaml" = mkIf (cfg.plugin != { }) {
source = yamlFormat.generate "k9s-plugin" cfg.plugin;
"k9s/plugins.yaml" = mkIf (cfg.plugins != { }) {
source = yamlFormat.generate "k9s-plugins" { inherit (cfg) plugins; };
};
"k9s/views.yaml" = mkIf (cfg.views != { }) {
source = yamlFormat.generate "k9s-views" cfg.views;
source = yamlFormat.generate "k9s-views" { inherit (cfg) views; };
};
}
// skinFiles
@@ -239,19 +246,19 @@ in
};
"Library/Application Support/k9s/aliases.yaml" = mkIf (cfg.aliases != { }) {
source = yamlFormat.generate "k9s-aliases" cfg.aliases;
source = yamlFormat.generate "k9s-aliases" { inherit (cfg) aliases; };
};
"Library/Application Support/k9s/hotkeys.yaml" = mkIf (cfg.hotkey != { }) {
source = yamlFormat.generate "k9s-hotkey" cfg.hotkey;
"Library/Application Support/k9s/hotkeys.yaml" = mkIf (cfg.hotKeys != { }) {
source = yamlFormat.generate "k9s-hotkeys" { inherit (cfg) hotKeys; };
};
"Library/Application Support/k9s/plugins.yaml" = mkIf (cfg.plugin != { }) {
source = yamlFormat.generate "k9s-plugin" cfg.plugin;
"Library/Application Support/k9s/plugins.yaml" = mkIf (cfg.plugins != { }) {
source = yamlFormat.generate "k9s-plugins" { inherit (cfg) plugins; };
};
"Library/Application Support/k9s/views.yaml" = mkIf (cfg.views != { }) {
source = yamlFormat.generate "k9s-views" cfg.views;
source = yamlFormat.generate "k9s-views" { inherit (cfg) views; };
};
}
// skinFiles

View File

@@ -16,11 +16,60 @@
};
};
};
hotkey = {
shift-0 = {
shortCut = "Shift-0";
description = "Viewing pods";
command = "pods";
};
};
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/services" = {
columns = [
"NAME"
"TYPE"
];
};
};
"v1/pods" = {
columns = [
"AGE"
"NAMESPACE"
"NAME"
"IP"
"NODE"
"STATUS"
"READY"
];
};
};
};
test.asserts.warnings.enable = true;
test.asserts.warnings.expected = [
"The option `programs.k9s.plugin' defined in ${lib.showFiles options.programs.k9s.plugin.files} has been renamed to `programs.k9s.plugins'."
"The option `programs.k9s.hotkey' defined in ${lib.showFiles options.programs.k9s.hotkey.files} has been renamed to `programs.k9s.hotKeys'."
"The option `programs.k9s.skin' defined in ${lib.showFiles options.programs.k9s.skin.files} has been renamed to `programs.k9s.skins.skin'."
"Nested 'k9s.views' structure in programs.k9s.views is deprecated, move the contents directly under programs.k9s.views"
];
nmt.script = ''
assertFileExists home-files/.config/k9s/skins/skin.yaml

View File

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

View File

@@ -1,4 +1,4 @@
hotKey:
hotKeys:
shift-0:
command: pods
description: Viewing pods

View File

@@ -21,13 +21,11 @@
ui.skin = "default";
};
};
hotkey = {
hotKey = {
shift-0 = {
shortCut = "Shift-0";
description = "Viewing pods";
command = "pods";
};
hotKeys = {
shift-0 = {
shortCut = "Shift-0";
description = "Viewing pods";
command = "pods";
};
};
skins = {
@@ -60,45 +58,37 @@
};
};
aliases = {
alias = {
pp = "v1/pods";
};
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"
];
};
plugins = {
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"
];
};
};
"v1/pods" = {
columns = [
"AGE"
"NAMESPACE"
"NAME"
"IP"
"NODE"
"STATUS"
"READY"
];
};
};
};
@@ -124,18 +114,16 @@
assertFileContent \
"home-files/${configDir}/skins/alt-skin.yaml" \
${./example-skin-expected-alt.yaml}
assertFileExists "home-files/${configDir}/hotkeys.yaml"
assertFileContent \
"home-files/${configDir}/hotkeys.yaml" \
${./example-hotkey-expected.yaml}
${./example-hotkeys-expected.yaml}
assertFileExists "home-files/${configDir}/aliases.yaml"
assertFileContent \
"home-files/${configDir}/aliases.yaml" \
${./example-aliases-expected.yaml}
assertFileExists "home-files/${configDir}/plugins.yaml"
assertFileContent \
"home-files/${configDir}/plugins.yaml" \
${./example-plugin-expected.yaml}
${./example-plugins-expected.yaml}
assertFileExists "home-files/${configDir}/views.yaml"
assertFileContent \
"home-files/${configDir}/views.yaml" \

View File

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