Skip to content

Load cluster and context level custom view configs - #4411

Open
yxshee wants to merge 1 commit into
derailed:masterfrom
yxshee:feat/cluster-level-views-config
Open

yxshee wants to merge 1 commit into
derailed:masterfrom
yxshee:feat/cluster-level-views-config

Conversation

@yxshee

@yxshee yxshee commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #4392.

Previously, custom view configurations (views.yaml) were only loaded from the single global AppViewsFile ($XDG_CONFIG_HOME/k9s/views.yaml), making it impossible to scope custom views to a cluster without affecting other clusters or duplicating configs across multiple contexts pointing at the same cluster.

This change adds support for cluster-level (context-agnostic) and context-level views.yaml files alongside the global file:

  • internal/config/files.go: Adds AppClusterViewsFile(cluster) (clusters/<cluster>/views.yaml) and AppContextViewsFile(cluster, context) (clusters/<cluster>/<context>/views.yaml), reusing data.SanitizeFileName / data.SanitizeContextSubpath.
  • internal/config/config.go: Adds Config.ClusterViewsPath() and Config.ContextViewsPath().
  • internal/config/views.go: Updates CustomView.Load to merge entries into Views rather than replacing the map, and adds CustomView.LoadFiles(paths ...string) to load and merge layers in order and notify listeners once after all layers are applied (including clearing stale settings when switching to a cluster without custom views).
  • internal/ui/config.go: Updates Configurator.RefreshCustomViews to merge global, cluster-level, and context-level views.yaml in ascending precedence (global < cluster < context), and updates Configurator.CustomViewsWatcher to watch all existing parent directories for those view config paths so cluster/context views.yaml files load and live-reload even when no global views.yaml exists.

Verification

  • CGO_ENABLED=0 go build ./... — pass
  • go vet ./... — pass
  • golangci-lint run --new-from-rev=upstream/master — 0 issues
  • go test -race -count=1 ./internal/config/... — pass
  • go test -race -count=1 -run "TestSkinnedContext|TestBenchConfig|TestRefreshStylesLogo|Test_activeConfig|TestRefreshCustomViews|TestCustomViewsWatcher" ./internal/ui — pass
  • CGO_ENABLED=0 go test -p 1 -count=1 ./... — pass

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow view configs on the cluster level (context agnostic)

1 participant