Skip to content

Add configuration validation option.#38138

Closed
justrich wants to merge 1 commit intomoby:masterfrom
justrich:36911
Closed

Add configuration validation option.#38138
justrich wants to merge 1 commit intomoby:masterfrom
justrich:36911

Conversation

@justrich
Copy link

@justrich justrich commented Nov 5, 2018

Fixes #36911

Add a command line option.
Add option to exit before daemon startup if validating config.

If config file is invalid we'll exit anyhow, so this just prevents
the daemon from starting if the configuration is fine.

Mainly useful for making config changes and restarting the daemon
iff the config is valid.

Signed-off-by: Rich Horwood [email protected]

- What I did

- How I did it

- How to verify it

- Description for the changelog

Add option to validate daemon configuration file and exit.

- A picture of a cute animal (not mandatory but encouraged)

@codecov
Copy link

codecov bot commented Dec 19, 2018

Codecov Report

Merging #38138 into master will increase coverage by 0.52%.
The diff coverage is 29.35%.

@@            Coverage Diff             @@
##           master   #38138      +/-   ##
==========================================
+ Coverage   36.18%   36.70%   +0.52%     
==========================================
  Files         610      608       -2     
  Lines       45363    45082     -281     
==========================================
+ Hits        16413    16547     +134     
+ Misses      26707    26252     -455     
- Partials     2243     2283      +40     

@olljanat
Copy link
Contributor

olljanat commented Jan 2, 2019

@justrich this one need to be rebased

@derek derek bot added the status/failing-ci Indicates that the PR in its current state fails the test suite label Jan 2, 2019
@olljanat
Copy link
Contributor

olljanat commented Jan 8, 2019

(reserved for my derek comments)

@olljanat
Copy link
Contributor

@thaJeztah FYI. this looks to be updated based on your review and passing CI (except codecov/patch).

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

oh boy, looks like I started a review, and never submitted

Screenshot 2019-06-05 at 12 12 15

Copy link
Member

Choose a reason for hiding this comment

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

We're generally conservative when adding single-letter flags, and want to reserve new ones for "frequently used options"; could you remove the -V shorthand? (It's easy to add in future if we see a need, but it's much harder to remove an option, once it's been released 😅)

Suggested change
flags.BoolVarP(&o.Validate, "validate", "V", false, "Validate configuration file and exit")
flags.BoolVar(&o.Validate, "validate", false, "Validate configuration file and exit")

Copy link
Author

Choose a reason for hiding this comment

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

done.

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

forgot about this one. I think this one is good to have (docker/cli#1922 would still be useful to have as well, but is orthogonal to this change)

LGTM

(I did a quick rebase to trigger CI again)

@thaJeztah
Copy link
Member

@AkihiroSuda @tiborvass PTAL

Copy link
Contributor

@chris-crone chris-crone left a comment

Choose a reason for hiding this comment

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

LGTM

@AkihiroSuda
Copy link
Member

LGTM, but https://ci-next.docker.com/public/job/moby/job/PR-38138/2/display/redirect is now 404, so I can't click the "restart CI" button.

Could you rebase to retrigger CI?

@AkihiroSuda AkihiroSuda added the kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. label Feb 3, 2021
@thaJeztah
Copy link
Member

Oh; I think editing the top-comment triggers ci (neat little trick); let me try

@thaJeztah
Copy link
Member

Yup, that worked 😂. I think it's a bug in how jenkins is triggered, but comes in handy sometimes

@thaJeztah thaJeztah added this to the 21.xx milestone Feb 3, 2021
@thaJeztah
Copy link
Member

Failing CI; I guess it needs a rebase to get some CI fixes in; let me do so

@thaJeztah
Copy link
Member

[2021-02-03T10:22:44.308Z] === Errors
[2021-02-03T10:22:44.308Z] cmd/dockerd/options.go:63: not enough arguments in call to flags.BoolVarP
[2021-02-03T10:22:44.308Z] 	have (*bool, string, bool, string)
[2021-02-03T10:22:44.308Z] 	want (*bool, string, string, bool, string)

Fixes moby#36911

Add a command line option.
Add option to exit before daemon startup if validating config.

If config file is invalid we'll exit anyhow, so this just prevents
the daemon from starting if the configuration is fine.

Mainly useful for making config changes and restarting the daemon
iff the config is valid.

Signed-off-by: Rich Horwood <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah
Copy link
Member

Fixed the above; s/BoolVarP/BoolVar/ (as it no longer has a shorthand flag)

if opts.Validate {
// If config wasn't OK we wouldn't have made it this far.
logrus.Infof("Config OK")
os.Exit(0)
Copy link
Contributor

@coolljt0725 coolljt0725 Feb 3, 2021

Choose a reason for hiding this comment

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

IMO, we should be careful use os.Exit and let the program exit immediately in big program, this may cause some defer doesn't perform and then left with some uncleaned resoure. https://gobyexample.com/exit It's better to return a state to the caller.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, good one, actually didn't know that.

Yes, looks like that would cause some things to not be run

func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
stopc := make(chan bool)
defer close(stopc)
opts.SetDefaultOptions(opts.flags)
if cli.Config, err = loadDaemonCliConfig(opts); err != nil {

Thinking how we can achieve this; we could return a "special" error, but that may need handling of that error is various places to make sure we still still the daemon, but with a zero exit code.

@thaJeztah
Copy link
Member

Moved back to "code review" because of #38138 (comment); will have a look if there's a different approach possible

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

Labels

area/daemon Core Engine docs/revisit impact/changelog kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dockerd needs a 'validate config' option

7 participants