Skip to content

Exit if service config is loaded unsuccessfully on startup#34495

Merged
yongtang merged 1 commit intomoby:masterfrom
boaz0:registry_mirror_json
Sep 19, 2017
Merged

Exit if service config is loaded unsuccessfully on startup#34495
yongtang merged 1 commit intomoby:masterfrom
boaz0:registry_mirror_json

Conversation

@boaz0
Copy link
Copy Markdown
Contributor

@boaz0 boaz0 commented Aug 13, 2017

- What I did

This PR closes #34476

In registry/config.go at newServiceConfig the error returned by config.LoadMirrors and config.LoadInsecureRegistries weren't checked and by that caused the service configurations error to be silently ignored.

- How I did it

Check whether config.LoadMirrors/config.LoadInsecureRegistries returns an error. If it does, the daemon will print it and exit.

- How to verify it

$ mkdir -p /etc/docker/ && echo '{"registry-mirrors": ["example.com:5000"]}' > /etc/docker/daemon.json
$ dockerd

Should exit and print:

invalid registry mirror configurations: invalid mirror: unsupported scheme "example.com" in "example.com:5000

- Description for the changelog

Fix #34476: invalid registry mirrors configuration isn't being silently ignored

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

@boaz0 boaz0 changed the title Exit if LoadMirrors returns an error while ServiceConfig is created Exit if service config is loaded unsuccessfully on startup Aug 13, 2017
Comment thread registry/config.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should rather return an error and cmd/dockerd/daemon.go should catch that err.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes I think that would be better; I also think we can drop the invalid registry mirror configurations and invalid insecure registry configurations prefix here; the error itself looks pretty self-describing already;

invalid mirror: unsupported scheme "example.com" in "example.com:5000

When handling in the daemon, we could have a prefix added, similar as what's used for reloading the configuration, e.g.:

Error configuring the daemon: 

Comment thread registry/config.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes I think that would be better; I also think we can drop the invalid registry mirror configurations and invalid insecure registry configurations prefix here; the error itself looks pretty self-describing already;

invalid mirror: unsupported scheme "example.com" in "example.com:5000

When handling in the daemon, we could have a prefix added, similar as what's used for reloading the configuration, e.g.:

Error configuring the daemon: 

@boaz0 boaz0 added status/failing-ci Indicates that the PR in its current state fails the test suite rebuild/janky and removed status/failing-ci Indicates that the PR in its current state fails the test suite labels Aug 16, 2017
Comment thread registry/config_test.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.

looks like you forgot to point to testCase.err here, janky:

registry/config_test.go:196: missing argument for Errorf("%s"): format reads arg 1, have only 0 args

Comment thread cmd/dockerd/daemon.go Outdated
Copy link
Copy Markdown

@vrothberg vrothberg Aug 31, 2017

Choose a reason for hiding this comment

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

How about adding a second (error) return value to NewService()? This would leave validation to the service and the errors when loading mirrors and registry, etc. wouldn't be ignored anymore (see a similar change in bd3cf1e). Also, notice that the change in the current form is likely to break what @stevvooe suggests in #34319, namely to add private-registry-mirror semantics to --registry-mirror.

tl;dr To me it seems like redundant checks, so I suggest to add a second error return value to NewService() and leave validation there.

Copy link
Copy Markdown
Contributor Author

@boaz0 boaz0 Aug 31, 2017

Choose a reason for hiding this comment

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

I thought about it and the main issues were:

  • I will have to update other parts in the code
  • There is overhead. Loads functions are called in newServiceConfig and will be called again in NewService.

I thought maybe it would be a good idea to change newServiceConfig to return error but the main reason I stopped is because it broke a lot of tests and I wasn't sure I should go that path.

WDYT? 💭

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ah yes, that makes more sense. newServiceConfig should be the right place!

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.

@vrothberg 👍
@AkihiroSuda @thaJeztah can you please give feedback.

Copy link
Copy Markdown

@vrothberg vrothberg Aug 31, 2017

Choose a reason for hiding this comment

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

But we still need to pass an error to daemon start, which implies adding an error return to newService (as it calls newServiceConfig). Doesn't it?

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.

Yes, actually we do otherwise there is no way to propagate that error.

Copy link
Copy Markdown
Contributor Author

@boaz0 boaz0 Aug 31, 2017

Choose a reason for hiding this comment

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

In a second thought we can create a new function called NewServiceWithError and use it in daemon/dockerd.go
In that case we break less parts and still be able to make it work.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think that a function that parses or validates user input should return an error, so I prefer to do that for newService. But that's just my 2 cents :-)

@boaz0
Copy link
Copy Markdown
Contributor Author

boaz0 commented Aug 31, 2017

Okay, I am going to update this commit as discussed here.

I will change newServiceConfig to return error too and adjust the code to this change.

@boaz0 boaz0 added the status/failing-ci Indicates that the PR in its current state fails the test suite label Sep 1, 2017
@boaz0 boaz0 removed the status/failing-ci Indicates that the PR in its current state fails the test suite label Sep 3, 2017
@vrothberg
Copy link
Copy Markdown

LGTM. Thank you very much for your changes, @ripcurld0!

Copy link
Copy Markdown
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐮

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

changes LGTM, but am I correct that we don't have a test-case added to test the new behaviour? I saw there was a test in an older version of this PR 😅 (perhaps I missed some of the discussion during my vacation)

Copy link
Copy Markdown
Member

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

I think this can be tested with a unit test of newServiceConfig(). I don't think there needs to be an integration test.

@boaz0
Copy link
Copy Markdown
Contributor Author

boaz0 commented Sep 16, 2017

@dnephin thanks I figured it out. ❤️
@thaJeztah I am working on this. Thanks for noticing. 😄

@boaz0
Copy link
Copy Markdown
Contributor Author

boaz0 commented Sep 17, 2017

@thaJeztah and @dnephin
can you please revisit my changes and verify I am not missing anything.
🍔 😆

Copy link
Copy Markdown
Member

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

LGTM

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

LGTM, thanks!

@yongtang yongtang merged commit b075cd2 into moby:master Sep 19, 2017
@boaz0 boaz0 deleted the registry_mirror_json branch October 6, 2017 14:21
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.

Invalid registry-mirrors in daemon.json silently ignored