-
Notifications
You must be signed in to change notification settings - Fork 90
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
Implement -c/--config
flag
#4242
Conversation
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
d55ac29
to
a2bb09b
Compare
456de34
to
0529b2b
Compare
- closes #4217
- Ensures values set via -c/--config flag override file config in bacalhu repo
includes code generation to produce descriptions of each config type based on go code comments in config struct.
a741d3f
to
7a03503
Compare
The documented behaviour looks as intended. Though I pulled the branch locally, and here are some issues I've found: 1. No config file found:no config file provided, and no config file under
2. Still auto-creating
|
My recommendation is to improve the testing coverage of these changes, and to document the testing plan and manual testing you've done to verify the changes are working as expected. This is a very tricky area you are working on, and easy for issues to slip through :) |
if userDir, err := os.UserConfigDir(); err == nil { | ||
return filepath.Join(userDir, defaultBacalhauDir) | ||
} |
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.
We discussed having the UserConfigDir
as a default for the config path, and not for the repo path. Both locations should be decoupled from other. The only reason we are still considering <repo>/config.yaml
as the default location for configs is for backward compatibility only. After implementing migration logic where we migrate configs from repo to UserConfigDir
, then we should no longer look for configs under the repo
Our tenant in this area should be less-is-more. We should avoid doing more magic on-behalf of the user and avoid having too many paths and forks in the logic of config setup. My original preference was to even not have a default config path, but I understand that will complicate migration logic
cmd/util/repo.go
Outdated
return nil, err | ||
} | ||
} | ||
configFiles = append(configFiles, repoConfig, xdgConfig) |
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.
you should look for xddConfig
and only if not preset (indicating no migration yet), then look at repoConfig
Great catch, this has been addressed and tests for it have been added in
This is still the intended behavior until the repo is decoupled from the config file. At present the generated config file contains paths to various stores on disk. We will migrate away from this as part of #4219
Another good catch, this is fixed and tests implemented to verify.
I have made these clearer. e.g.
|
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.
Looks good
pkg/config/config.go
Outdated
/* | ||
if len(c.values) > 0 { | ||
if err := c.base.MergeConfigMap(c.values); err != nil { | ||
return nil, fmt.Errorf("merging config values: %w", err) | ||
} | ||
} | ||
*/ |
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.
leftover commented code
Closes #4217 and #4243
Changes to Configuration Handling
The
config
package has been refactored to allow more flexible and powerful configuration options. The configuration constructor now accepts the following inputs:Precedence of Configuration Sources
The precedence of these options, from highest to lowest, is as follows:
This means that if a configuration key is defined in multiple sources, the value from the source higher on this list will be used.
Example Usage
Here’s an example of how to use the new configuration constructor:
A more detailed example specific to Bacalhau can be found here.
Handling of Configuration Files in Bacalhau
When using Bacalhau, configuration files are treated differently depending on their location:
--config
flag: When multiple configuration files are provided via the --config flag, Bacalhau merges the values from these files. The order in which the files are listed determines the precedence, with later files overriding earlier ones.Files in
~/.bacalhau
and~/.config/bacalhau
: These files are not merged, and only used a file(s) isn't specified by the--config
flag. . Instead, Bacalhau prioritizes~/.config/bacalhau
. If a config file is found in~/.config/bacalhau
, it is used exclusively. If not, Bacalhau falls back to~/.bacalhau
. If neither file is present, Bacalhau does not load a config file.Precedence with Flags and Configuration Files
The client host will be set to 1.1.1.1, even if this key is present in config.yaml or override.yaml.
Here, the client host will be set to 2.2.2.2 as specified by the -c node.clientapi.host=2.2.2.2 flag.
Changes to Agent API
In order to implement proper testing of the bacalhau configuration package the
agent
API was extended with a new endpoint/api/v1/agent/config
which returns the current configuration used by an agent as json. This API allows bacalhau to be started with a specific configuration and then queried to make assertions on the configuration being used.test/config.sh
implements coverage of this API and the config package.Changes to
config list
Previously this command returns a list of config keys and their default values. It now returns a list of config keys and their descriptions.