close
Skip to content

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

Merged
tiborvass merged 1 commit into
moby:masterfrom
calavera:userland_proxy_config_fix
Feb 20, 2016
Merged

Avoid setting default truthy values from flags that are not set.#20471
tiborvass merged 1 commit into
moby:masterfrom
calavera:userland_proxy_config_fix

Conversation

@calavera

Copy link
Copy Markdown
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
Copy Markdown
Member

LGTM 🐰

@tiborvass

Copy link
Copy Markdown
Contributor

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

@anusha-ragunathan

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread daemon/config.go Outdated

Copy link
Copy Markdown
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
Copy Markdown
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 calavera force-pushed the userland_proxy_config_fix branch from caa7742 to 5a5a11f Compare February 19, 2016 22:14
@calavera

Copy link
Copy Markdown
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
Copy Markdown
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>
@calavera calavera force-pushed the userland_proxy_config_fix branch from 5a5a11f to 31cb96d Compare February 19, 2016 23:39
@tiborvass

Copy link
Copy Markdown
Contributor

LGTM

@anusha-ragunathan

Copy link
Copy Markdown
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
Copy Markdown

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.

5 participants