Skip to content

Fixes Issue 9677: Docker client errors out, when daemon flags are passed to docker subcommands#11418

Closed
shishir-a412ed wants to merge 1 commit intomoby:masterfrom
shishir-a412ed:docker_daemon_flags
Closed

Fixes Issue 9677: Docker client errors out, when daemon flags are passed to docker subcommands#11418
shishir-a412ed wants to merge 1 commit intomoby:masterfrom
shishir-a412ed:docker_daemon_flags

Conversation

@shishir-a412ed
Copy link
Copy Markdown
Contributor

Fixes #9677

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.

I wish there was another way to do this because this is begging for this list to be out of sync.

Could you put this list in alphabetical order so its easier to visually compare it with the help text to see if something is missing?

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.

actually.... I know our flag setup code is kind of weird, but I wonder if it would be possible to put all daemon flags into a struct/table and then we have code iterate over that table to set all of the flags. Then we can reference that same table in this code AND in a testcase to validate it all.
Just a thought

@shishir-a412ed
Copy link
Copy Markdown
Contributor Author

@duglin right now docker flag parsing relies on one hashmap to classify whether the incoming argument is a flag or not. That map includes both daemon and global flags. Unless we use two maps to store daemon and global args separately, I don't see a way to avoid this extra map.

N Separating IMHO would not be easy, it has dependencies everywhere.
For this error, we need some kind of data structure to look-up if the incoming argument is a daemon flag or not.

I will reorder the entries according to the help menu. And also add the deprecated flags which I have not added.

Shishir

@duglin
Copy link
Copy Markdown
Contributor

duglin commented Mar 23, 2015

@shishir-a412ed sorry if I wasn't clear. I wasn't talking about a map during parsing, I was talking about a map/struct during flag setup time. For example, if you look at the InstallFlags() func, that is what will register all of our daemon-side flags. And it does it via a list of flag.XXX calls. A hard coded list of calls. So knowing when a new one (like perhaps "-log-driver" at the end) is added is hard to detect when you also want to have your new code work. So, I was wondering if we could take all of the flag definitions from InstallFlags() and put them into a struct. InstallFlags() would then look over that struct to make all of the appropriate flag.XXX calls.
But, and this is the point, your new code can then use that same struct to perform the checks you need to know if any of them were specified w/o the -d flag. Then as new flags are added you won't need to update your code. Does this make any sense?

@shishir-a412ed
Copy link
Copy Markdown
Contributor Author

@duglin
I think I get the central idea of what you are trying to achieve.
You are trying to have a common struct/map that can be used to set the flags in daemon/config.go InstallFlags() method. By iterating over that data structure and populating the flags rather than hard coding it.

N use the same struct/map to do the look-up for my use-case to identify if it's a daemon flag or not.
So that updates are made at one central location rather than at two different places.

Few open questions:

  1. " So, I was wondering if we could take all of the flag definitions from InstallFlags() and put them into a struct. InstallFlags() would then look over that struct to make all of the appropriate flag.XXX calls."
    Isn't that what we are doing right now ? flag.XXX call is using the daemon config struct to populate the flags. InstallFlags is a method typed to daemon config struct i.e. struct.InstallFlags()
    Not sure how you would iterate over a struct and avoid the hard coding ?

  2. Populating a flag needs a struct. I am not sure how a map would work here, as iterating over a map won't tell me which field I am getting back. Checking daemon flags would needs a map to do the lookup {struct won't work here}. I feel these are two different use cases requiring two different data structures.

Nways let other maintainers jump in, and see what they feel.
I ll be happy to change the code, if there is a mutual consensus on a solution.
Till that time, I ll clean up the code.

Shishir

@shishir-a412ed shishir-a412ed force-pushed the docker_daemon_flags branch 3 times, most recently from 4fc9f5a to a18e133 Compare March 27, 2015 20:36
@shishir-a412ed
Copy link
Copy Markdown
Contributor Author

@duglin I have reordered the flags according to the help menu.
And added support for deprecated flags.

ping @tiborvass

Shishir

@duglin
Copy link
Copy Markdown
Contributor

duglin commented Mar 30, 2015

@shishir-a412ed to your questions:

  1. no its not. Each call to flag.XXX is hand coded, not reading from a structure/array. This means that each time a new daemon flag is created people will need to not only add a new call to flag.XXX but also remember to update your Init() func - which I'm sure they'll forget. By having a single spot that is used to define the daemon flags (via a flag.XXX call) and setup your mapDaemonFlags structure, we avoid one being updated w/o the other.
  2. wouldn't all daemon flags, except -d, be added to your mapDaemonFlags structure? If so, then we just need one if-statement to avoid adding it to your mapDaemonFlags.
    But perhaps I'm missing something, or defining such a structure/array is more complicated than I'm thinking.

@shishir-a412ed shishir-a412ed force-pushed the docker_daemon_flags branch 2 times, most recently from d346428 to 5f87f98 Compare March 30, 2015 18:23
@shishir-a412ed
Copy link
Copy Markdown
Contributor Author

@duglin I have re-factored the code. Does this solve your concern ?

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.

Sorry but 9 times the same block of code? Really?

@shishir-a412ed shishir-a412ed force-pushed the docker_daemon_flags branch 2 times, most recently from 0d5029a to 64b206a Compare April 4, 2015 15:00
@shishir-a412ed
Copy link
Copy Markdown
Contributor Author

@icecrime Thanks, I have made the changes. Please check now.

@calavera
Copy link
Copy Markdown
Contributor

@shishir-a412ed I'm afraid this also needs to be rebased. The code looks good to me except for a minor comment.

@jessfraz
Copy link
Copy Markdown
Contributor

sorry needs rebase

@shishir-a412ed
Copy link
Copy Markdown
Contributor Author

@jfrazelle I have rebased the PR.

@shishir-a412ed
Copy link
Copy Markdown
Contributor Author

@calavera I have changed this HasDaemonFlag = MapDaemonFlags[name] back to my original code.
This has a small bug. If a daemon flag is followed by a global flag. At the end of the flag parsing flag.Parse()
HasDaemonFlag would be set to false eventhough it should have been true.

@calavera
Copy link
Copy Markdown
Contributor

@shishir-a412ed it makes sense, thanks for fixing it. I think it would make sense to add a few tests to validate this behavior.

I was also wondering if it would make sense to have two completely different FlagSet lists, one for the daemon flags and another for the rest. That way we wouldn't need to modify the flag package. I don't know if that would work as expected though.

@rhatdan
Copy link
Copy Markdown
Contributor

rhatdan commented Apr 21, 2015

We are planning on a more extensive patch to break these flags apart. But we need to do a lot of hacking for backwards compatibility. Sadly if we could go back to original docker and just have

docker daemon ...

All of this would be unnecessary...

@shishir-a412ed
Copy link
Copy Markdown
Contributor Author

@calavera I ll add the test cases in 1-2 days. Thanks.

@icecrime icecrime removed the dco/yes label Apr 23, 2015
@shishir-a412ed shishir-a412ed force-pushed the docker_daemon_flags branch 2 times, most recently from f6d7cee to db8fffa Compare April 26, 2015 23:14
…sed to docker subcommands

Signed-off-by: Shishir Mahajan <shishir.mahajan@redhat.com>
@shishir-a412ed
Copy link
Copy Markdown
Contributor Author

@calavera I have added the test cases.
ping @tiborvass

@tiborvass
Copy link
Copy Markdown
Contributor

@shishir-a412ed Thanks for your work Shishir, I'll carry this PR and #10535 to get it in asap.

@tiborvass tiborvass closed this May 4, 2015
@rhatdan
Copy link
Copy Markdown
Contributor

rhatdan commented May 5, 2015

Where is this going to be carried?

@tiborvass
Copy link
Copy Markdown
Contributor

Carried in #13771

@shishir-a412ed shishir-a412ed deleted the docker_daemon_flags branch October 5, 2015 20:59
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.

docker client doesn't error when given daemon flags

8 participants