Skip to content
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

Avoid setting default truthy values from flags that are not set. #20471

Merged
merged 1 commit into from Feb 20, 2016

Conversation

calavera
Copy link
Contributor

When the value for a configuration option in the file is false,
and the default value for a flag is true, we should not
take the value from the later as final value for the option,
because the user explicitly set false.

This change overrides the default value in the flagSet with
the value in the configuration file so we get the correct
result when we merge the two configurations together.

Fixes #20289.

Signed-off-by: David Calavera david.calavera@gmail.com

@calavera calavera force-pushed the userland_proxy_config_fix branch 2 times, most recently from 720113f to 39384dc Compare February 19, 2016 03:23
@calavera calavera added this to the 1.10.2 milestone Feb 19, 2016
@calavera calavera force-pushed the userland_proxy_config_fix branch 3 times, most recently from 6888281 to caa7742 Compare February 19, 2016 18:43
@vdemeester
Copy link
Member

LGTM 🐰

@tiborvass
Copy link
Contributor

janky failed on authz test only, thats a known issue.

@anusha-ragunathan
Copy link
Contributor

AFAICT, mergo.Merge(dst, src) overwrites any field in dst that has zero or false with the src field's value. Wouldnt this affect fields with 0 int values in the fileConfig that have non-zero defaults in flagConfig? i.e issue affects more than just bool types?

@calavera
Copy link
Contributor Author

@anusha-ragunathan that is correct. However, we only have one Int flag option, Mtu, which default is 0, making it not an issue like boolean flags:

https://github.com/docker/docker/blob/master/daemon/config.go#L117

@anusha-ragunathan
Copy link
Contributor

Ulimit (part of InstallFlags) is also int, but has null initialization. So we should be okay there as well. I'd like a comment about ints, so that in future if we add such a integer flag, we also add a corresponding patch to handle this case.

}
}
if len(namedOptions) > 0 {
// set also default for mergeVal flags that are boolValue at the same time.
Copy link
Contributor

Choose a reason for hiding this comment

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

In the above loop, we are looping through the configSet, looking up their corresponding flags and setting flag values.

In this loop, we are looping through all flags, looking up their config values and again setting the flags.

Can you please explain with an example, why the second set is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not all option names match 1-to-1 with flag names, like label and labels. We only perform the second loop if there are in fact any of those options specified in the configuration file.

@calavera
Copy link
Contributor Author

I'd like a comment about ints, so that in future if we add such a integer flag, we also add a corresponding patch to handle this case.

I don't think a code comment can prevent that to happen unfortunately. I'd like to have more tests around those kind of cases, but they don't apply here.

@anusha-ragunathan
Copy link
Contributor

There's already a comment about 'config file with nullable values". Add a line about how this behavior affects integers as well. That's it.

When the value for a configuration option in the file is `false`,
and the default value for a flag is `true`, we should not
take the value from the later as final value for the option,
because the user explicitly set `false`.

This change overrides the default value in the flagSet with
the value in the configuration file so we get the correct
result when we merge the two configurations together.

Signed-off-by: David Calavera <david.calavera@gmail.com>
@tiborvass
Copy link
Contributor

LGTM

@anusha-ragunathan
Copy link
Contributor

LGTM!

tiborvass added a commit that referenced this pull request Feb 20, 2016
Avoid setting default truthy values from flags that are not set.
@tiborvass tiborvass merged commit 6668326 into moby:master Feb 20, 2016
@GordonTheTurtle
Copy link

Job: Docker-PRs-WoW-TP4 FAILED:

---
          56    docker-1.11.0-dev.exe.md5
  0%  
100%  
        New File              88    docker-1.11.0-dev.exe.sha256
  0%  
100%  
        New File          27.0 m    docker.exe
  0.0%
  3.6%
  7.3%
 11.0%
 14.7%
 18.4%
 22.1%
 25.8%
 29.5%
 33.2%
 36.9%
 40.6%
 44.3%
 48.0%
 51.7%
 55.4%
 59.1%
 62.8%
 66.5%
 70.2%
 73.9%
 77.6%
 81.3%
 85.0%
 88.7%
 92.4%
 96.1%
 99.8%
100%  

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         1         0         0         0
   Files :         4         4         0         0         0         0
   Bytes :   54.09 m   54.09 m         0         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00


   Speed :           766509540 Bytes/sec.
   Speed :           43860.027 MegaBytes/min.
   Ended : Saturday, February 20, 2016 1:44:44 AM

+ ec=0
+ set +x
INFO: Linking the built binary to /d/CI/CI-3bc9f
---

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants