diff --git a/README.md b/README.md index 8877a811..0e25415e 100644 --- a/README.md +++ b/README.md @@ -415,6 +415,8 @@ You can now override the context portForward default address configuration by se maxConnRetry: 5 # Indicates whether modification commands like delete/kill/edit are disabled. Default is false readOnly: false + # This setting allows users to specify the default view, but it is not set by default. + defaultView: "" # Toggles whether k9s should exit when CTRL-C is pressed. When set to true, you will need to exit k9s via the :quit command. Default is false. noExitOnCtrlC: false #UI settings diff --git a/cmd/root.go b/cmd/root.go index f7ab52b5..9e74a35b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -113,6 +113,10 @@ func run(*cobra.Command, []string) error { slog.Warn("Fail to load global/context configuration", slogs.Error, err) } app := view.NewApp(cfg) + if app.Config.K9s.DefaultView != "" { + app.Config.SetActiveView(app.Config.K9s.DefaultView) + } + if err := app.Init(version, *k9sFlags.RefreshRate); err != nil { return err } diff --git a/internal/config/json/schemas/k9s.json b/internal/config/json/schemas/k9s.json index 5b3e6b53..ebc2a5ec 100644 --- a/internal/config/json/schemas/k9s.json +++ b/internal/config/json/schemas/k9s.json @@ -15,6 +15,7 @@ "noExitOnCtrlC": { "type": "boolean" }, "skipLatestRevCheck": { "type": "boolean" }, "disablePodCounting": { "type": "boolean" }, + "defaultView": { "type": "string" }, "portForwardAddress": { "type": "string" }, "ui": { "type": "object", diff --git a/internal/config/k9s.go b/internal/config/k9s.go index f32e0dfa..462f999c 100644 --- a/internal/config/k9s.go +++ b/internal/config/k9s.go @@ -35,6 +35,7 @@ type K9s struct { ImageScans ImageScans `json:"imageScans" yaml:"imageScans"` Logger Logger `json:"logger" yaml:"logger"` Thresholds Threshold `json:"thresholds" yaml:"thresholds"` + DefaultView string `json:"defaultView" yaml:"defaultView"` manualRefreshRate int manualReadOnly *bool manualCommand *string @@ -113,6 +114,7 @@ func (k *K9s) Merge(k1 *K9s) { } k.LiveViewAutoRefresh = k1.LiveViewAutoRefresh + k.DefaultView = k1.DefaultView k.ScreenDumpDir = k1.ScreenDumpDir k.RefreshRate = k1.RefreshRate k.MaxConnRetry = k1.MaxConnRetry diff --git a/internal/config/testdata/configs/default.yaml b/internal/config/testdata/configs/default.yaml index 07eb60f7..feb8b77a 100644 --- a/internal/config/testdata/configs/default.yaml +++ b/internal/config/testdata/configs/default.yaml @@ -43,3 +43,4 @@ k9s: memory: critical: 90 warn: 70 + defaultView: "" diff --git a/internal/config/testdata/configs/expected.yaml b/internal/config/testdata/configs/expected.yaml index be1d6645..0fd8085a 100644 --- a/internal/config/testdata/configs/expected.yaml +++ b/internal/config/testdata/configs/expected.yaml @@ -43,3 +43,4 @@ k9s: memory: critical: 90 warn: 70 + defaultView: "" diff --git a/internal/config/testdata/configs/k9s.yaml b/internal/config/testdata/configs/k9s.yaml index 232c52b9..053fa9bf 100644 --- a/internal/config/testdata/configs/k9s.yaml +++ b/internal/config/testdata/configs/k9s.yaml @@ -43,3 +43,4 @@ k9s: memory: critical: 90 warn: 70 + defaultView: "" diff --git a/internal/config/testdata/configs/k9s_toast.yaml b/internal/config/testdata/configs/k9s_toast.yaml index dd6d0330..6433ca71 100644 --- a/internal/config/testdata/configs/k9s_toast.yaml +++ b/internal/config/testdata/configs/k9s_toast.yaml @@ -39,3 +39,4 @@ k9s: memory: critical: 90 warn: 70 + defaultView: ""