Exit if service config is loaded unsuccessfully on startup#34495
Exit if service config is loaded unsuccessfully on startup#34495yongtang merged 1 commit intomoby:masterfrom boaz0:registry_mirror_json
Conversation
There was a problem hiding this comment.
This should rather return an error and cmd/dockerd/daemon.go should catch that err.
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I thought about it and the main issues were:
- I will have to update other parts in the code
- There is overhead.
Loadsfunctions are called innewServiceConfigand will be called again inNewService.
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? 💭
There was a problem hiding this comment.
Ah yes, that makes more sense. newServiceConfig should be the right place!
There was a problem hiding this comment.
@vrothberg 👍
@AkihiroSuda @thaJeztah can you please give feedback.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Yes, actually we do otherwise there is no way to propagate that error.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :-)
|
Okay, I am going to update this commit as discussed here. I will change |
|
LGTM. Thank you very much for your changes, @ripcurld0! |
thaJeztah
left a comment
There was a problem hiding this comment.
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)
dnephin
left a comment
There was a problem hiding this comment.
I think this can be tested with a unit test of newServiceConfig(). I don't think there needs to be an integration test.
|
@dnephin thanks I figured it out. ❤️ |
Signed-off-by: Boaz Shuster <[email protected]>
|
@thaJeztah and @dnephin |
- What I did
This PR closes #34476
In
registry/config.goatnewServiceConfigthe error returned byconfig.LoadMirrorsandconfig.LoadInsecureRegistriesweren't checked and by that caused the service configurations error to be silently ignored.- How I did it
Check whether
config.LoadMirrors/config.LoadInsecureRegistriesreturns an error. If it does, the daemon will print it and exit.- How to verify it
Should exit and print:
- 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)