-
Notifications
You must be signed in to change notification settings - Fork 178
feat(config): default configuration with merge support for downstream overrides #396
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
Cali0707
merged 2 commits into
containers:main
from
marcnuri-forks:feat/config-defaults
Oct 23, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "bytes" | ||
|
|
||
| "github.com/BurntSushi/toml" | ||
| ) | ||
|
|
||
| func Default() *StaticConfig { | ||
| defaultConfig := StaticConfig{ | ||
| ListOutput: "table", | ||
| Toolsets: []string{"core", "config", "helm"}, | ||
| } | ||
| overrides := defaultOverrides() | ||
| mergedConfig := mergeConfig(defaultConfig, overrides) | ||
| return &mergedConfig | ||
| } | ||
|
|
||
| // HasDefaultOverrides indicates whether the internal defaultOverrides function | ||
| // provides any overrides or an empty StaticConfig. | ||
| func HasDefaultOverrides() bool { | ||
| overrides := defaultOverrides() | ||
| var buf bytes.Buffer | ||
| if err := toml.NewEncoder(&buf).Encode(overrides); err != nil { | ||
| // If marshaling fails, assume no overrides | ||
| return false | ||
| } | ||
| return len(bytes.TrimSpace(buf.Bytes())) > 0 | ||
| } | ||
|
|
||
| // mergeConfig applies non-zero values from override to base using TOML serialization | ||
| // and returns the merged StaticConfig. | ||
| // In case of any error during marshalling or unmarshalling, it returns the base config unchanged. | ||
| func mergeConfig(base, override StaticConfig) StaticConfig { | ||
| var overrideBuffer bytes.Buffer | ||
| if err := toml.NewEncoder(&overrideBuffer).Encode(override); err != nil { | ||
| // If marshaling fails, return base unchanged | ||
| return base | ||
| } | ||
|
|
||
| _, _ = toml.NewDecoder(&overrideBuffer).Decode(&base) | ||
| return base | ||
| } | ||
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,8 @@ | ||
| package config | ||
|
|
||
| func defaultOverrides() StaticConfig { | ||
| return StaticConfig{ | ||
| // IMPORTANT: this file is used to override default config values in downstream builds. | ||
| // This is intentionally left blank. | ||
| } | ||
|
Comment on lines
+4
to
+7
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great @manusa ! |
||
| } | ||
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 |
|---|---|---|
|
|
@@ -65,6 +65,9 @@ func (s *ToolsetsSuite) TestNoToolsets() { | |
| } | ||
|
|
||
| func (s *ToolsetsSuite) TestDefaultToolsetsTools() { | ||
| if configuration.HasDefaultOverrides() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this is a good hook, for downstream. |
||
| s.T().Skip("Skipping test because default configuration overrides are present (this is a downstream fork)") | ||
| } | ||
| s.Run("Default configuration toolsets", func() { | ||
| s.InitMcpClient() | ||
| tools, err := s.ListTools(s.T().Context(), mcp.ListToolsRequest{}) | ||
|
|
@@ -82,6 +85,9 @@ func (s *ToolsetsSuite) TestDefaultToolsetsTools() { | |
| } | ||
|
|
||
| func (s *ToolsetsSuite) TestDefaultToolsetsToolsInOpenShift() { | ||
| if configuration.HasDefaultOverrides() { | ||
| s.T().Skip("Skipping test because default configuration overrides are present (this is a downstream fork)") | ||
| } | ||
| s.Run("Default configuration toolsets in OpenShift", func() { | ||
| s.Handle(&test.InOpenShiftHandler{}) | ||
| s.InitMcpClient() | ||
|
|
@@ -100,6 +106,9 @@ func (s *ToolsetsSuite) TestDefaultToolsetsToolsInOpenShift() { | |
| } | ||
|
|
||
| func (s *ToolsetsSuite) TestDefaultToolsetsToolsInMultiCluster() { | ||
| if configuration.HasDefaultOverrides() { | ||
| s.T().Skip("Skipping test because default configuration overrides are present (this is a downstream fork)") | ||
| } | ||
| s.Run("Default configuration toolsets in multi-cluster (with 11 clusters)", func() { | ||
| kubeconfig := s.Kubeconfig() | ||
| for i := 0; i < 10; i++ { | ||
|
|
@@ -123,6 +132,9 @@ func (s *ToolsetsSuite) TestDefaultToolsetsToolsInMultiCluster() { | |
| } | ||
|
|
||
| func (s *ToolsetsSuite) TestDefaultToolsetsToolsInMultiClusterEnum() { | ||
| if configuration.HasDefaultOverrides() { | ||
| s.T().Skip("Skipping test because default configuration overrides are present (this is a downstream fork)") | ||
| } | ||
| s.Run("Default configuration toolsets in multi-cluster (with 2 clusters)", func() { | ||
| kubeconfig := s.Kubeconfig() | ||
| // Add additional cluster to force multi-cluster behavior with enum parameter | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this approach