Skip to content

fix bug: some OpAMPBridge values are always overriden by default #3934

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

OhJuhun
Copy link

@OhJuhun OhJuhun commented Apr 26, 2025

Description:

I fixed a bug where certain variables that could be set via both the config file and CLI were always being overridden by their default values, even if a config file was present. Now, when a config file exists, its values take precedence over the defaults, and if both a config file and CLI input are provided, the CLI input takes precedence.

@jaronoff97

Link to tracking Issue(s):

Testing:

Documentation:

@OhJuhun OhJuhun requested a review from a team as a code owner April 26, 2025 12:09
@OhJuhun
Copy link
Author

OhJuhun commented Apr 30, 2025

@jaronoff97 Can you review this plz?

@swiatekm
Copy link
Contributor

Instead of trying to detect if a value was loaded from file, I'd prefer if we took an approach similar to #3962. That is:

  1. Set all the defaults in a dedicated function.
  2. Load values from the config value on top of that.
  3. Apply flag values on top of the above, but only if they're actually set (by using flag.Changed).

WDYT @jaronoff97 ?

@jaronoff97
Copy link
Contributor

@swiatekm i think that approach is best. @OhJuhun would you be able to do a similar approach to what Mikolaj has done in his pr?

@OhJuhun
Copy link
Author

OhJuhun commented May 1, 2025

@jaronoff97 @swiatekm I fixed. thank you

@@ -212,10 +273,9 @@ func TestLoad(t *testing.T) {
}
got := NewConfig(logr.Discard())
err := LoadFromFile(got, tt.args.file)
if !tt.wantErr(t, err, fmt.Sprintf("Load(%v)", tt.args.file)) {
if err != nil && tt.wantErr(t, err, fmt.Sprintf("Load(%v)", tt.args.file)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaronoff97
this line didn't work before.
I understood that if err is not nil and wantErr is satisfied, the process should not continue any further.
That's why I changed it this way. Isn't that correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did it not work before? We want to check both cases here, i.e. if we expect an error (where wantErr = assert.Error) and there is no error, then we should fail. And if we don't expect an error and get one we should fail too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaronoff97
I understood that in cases where wantErr is not NoError, meaning when an error should occur, it was intended to terminate at this return statement and not execute the following code. However, in reality, even in cases where an error should occur, it wasn't returning from the if statement and was continuing to execute the next lines.
It seems to be fixed now.

Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one thought about the test, otherwise looks good. thank you! 🙇

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.

3 participants