-
Notifications
You must be signed in to change notification settings - Fork 794
Add configurable default theme support #4384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
illume
merged 6 commits into
kubernetes-sigs:main
from
guillaumebernard84:default-theme
May 17, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6e5d5db
backend: config: Add default-theme and force-theme flags
guillaumebernard84 1e1e3a1
frontend: Apply backend theme config to theme selection
guillaumebernard84 4d4f70f
frontend: Settings: Lock theme selector when admin forces theme
guillaumebernard84 e6595f3
backend: config: Fix linter issues in theme config and update snapshot
guillaumebernard84 b385f35
frontend: themeSlice: Preserve user theme preference when force-theme…
guillaumebernard84 d5c3af0
frontend: themeSlice: Fix test isolation for localStorage in applyBac…
guillaumebernard84 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package config_test | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/kubernetes-sigs/headlamp/backend/pkg/config" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestParseThemeConfiguration_DefaultLightTheme(t *testing.T) { | ||
| conf, err := config.Parse([]string{"go run ./cmd", "--default-light-theme=corporate-light"}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "corporate-light", conf.DefaultLightTheme) | ||
| assert.Equal(t, "", conf.DefaultDarkTheme) | ||
| assert.Equal(t, "", conf.ForceTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_DefaultDarkTheme(t *testing.T) { | ||
| conf, err := config.Parse([]string{"go run ./cmd", "--default-dark-theme=corporate-dark"}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "", conf.DefaultLightTheme) | ||
| assert.Equal(t, "corporate-dark", conf.DefaultDarkTheme) | ||
| assert.Equal(t, "", conf.ForceTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_BothDefaults(t *testing.T) { | ||
| conf, err := config.Parse([]string{ | ||
| "go run ./cmd", | ||
| "--default-light-theme=corporate-light", | ||
| "--default-dark-theme=corporate-dark", | ||
| }) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "corporate-light", conf.DefaultLightTheme) | ||
| assert.Equal(t, "corporate-dark", conf.DefaultDarkTheme) | ||
| assert.Equal(t, "", conf.ForceTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_ForceTheme(t *testing.T) { | ||
| conf, err := config.Parse([]string{"go run ./cmd", "--force-theme=corporate-branded"}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "", conf.DefaultLightTheme) | ||
| assert.Equal(t, "", conf.DefaultDarkTheme) | ||
| assert.Equal(t, "corporate-branded", conf.ForceTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_ForceWithDefaults(t *testing.T) { | ||
| conf, err := config.Parse([]string{ | ||
| "go run ./cmd", | ||
| "--default-light-theme=light", | ||
| "--default-dark-theme=dark", | ||
| "--force-theme=corporate", | ||
| }) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "light", conf.DefaultLightTheme) | ||
| assert.Equal(t, "dark", conf.DefaultDarkTheme) | ||
| assert.Equal(t, "corporate", conf.ForceTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_FromEnv(t *testing.T) { | ||
| require.NoError(t, os.Setenv("HEADLAMP_CONFIG_DEFAULT_LIGHT_THEME", "env-light")) | ||
| require.NoError(t, os.Setenv("HEADLAMP_CONFIG_DEFAULT_DARK_THEME", "env-dark")) | ||
|
|
||
| defer func() { | ||
| require.NoError(t, os.Unsetenv("HEADLAMP_CONFIG_DEFAULT_LIGHT_THEME")) | ||
| require.NoError(t, os.Unsetenv("HEADLAMP_CONFIG_DEFAULT_DARK_THEME")) | ||
| }() | ||
|
|
||
| conf, err := config.Parse([]string{"go run ./cmd"}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "env-light", conf.DefaultLightTheme) | ||
| assert.Equal(t, "env-dark", conf.DefaultDarkTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_ForceFromEnv(t *testing.T) { | ||
| require.NoError(t, os.Setenv("HEADLAMP_CONFIG_FORCE_THEME", "env-forced")) | ||
|
|
||
| defer func() { require.NoError(t, os.Unsetenv("HEADLAMP_CONFIG_FORCE_THEME")) }() | ||
|
|
||
| conf, err := config.Parse([]string{"go run ./cmd"}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "env-forced", conf.ForceTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_ArgsOverrideEnv(t *testing.T) { | ||
| require.NoError(t, os.Setenv("HEADLAMP_CONFIG_DEFAULT_LIGHT_THEME", "env-theme")) | ||
|
|
||
| defer func() { require.NoError(t, os.Unsetenv("HEADLAMP_CONFIG_DEFAULT_LIGHT_THEME")) }() | ||
|
|
||
| conf, err := config.Parse([]string{"go run ./cmd", "--default-light-theme=arg-theme"}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "arg-theme", conf.DefaultLightTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_NoConfig(t *testing.T) { | ||
| conf, err := config.Parse([]string{"go run ./cmd"}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "", conf.DefaultLightTheme) | ||
| assert.Equal(t, "", conf.DefaultDarkTheme) | ||
| assert.Equal(t, "", conf.ForceTheme) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.