pull client API version negotiation out of the CLI and into the client#32779
pull client API version negotiation out of the CLI and into the client#32779cpuguy83 merged 1 commit intomoby:masterfrom
Conversation
|
@rremer build error |
dnephin
left a comment
There was a problem hiding this comment.
Overall I think this is good, so design LGTM
There was a problem hiding this comment.
We don't want to fail here if there is an error. A user might just be running with --help to figure out how to specify the docker host.
This should return nil, and I guess could use a comment about why.
There was a problem hiding this comment.
There are two distinct use cases for this function so I don't think it makes sense to group these together.
DockerCLI.Initialize() should call DowngradeClientVersionPing() directly, and leave this functions as it was.
We might be able to just delete UpdateClientVersion() , I don't think it's called from anywhere else.
There was a problem hiding this comment.
Indeed there are no other references to UpdateClientVersion that I can find, however removing it would:
- potentially break existing consumers of the client library
- put update logic into the new negotiate function (although, it is just updating a field)
There was a problem hiding this comment.
We don't make any promises about not breaking the API on client/ it's not being released as a versioned package.
There was a problem hiding this comment.
I think this needs a more appropriate name, It's not necessarily downgrading, it might just be verifying the version is correct. It's also the "APIVersion", not the client version. Maybe NegotiateAPIVersion() ?
There was a problem hiding this comment.
Same comment about the function name, how about UpdateAPIVersionFromPing() ?
The check for if !cli.manualOverride {...} needs to move here. It should be the first line in the function I think:
if cli.manualOverride {
return
}There was a problem hiding this comment.
assert.Equal(t, expected, client.version)(same with the other assertions)
There was a problem hiding this comment.
I was trying to use the same format as the rest of the tests in this suite. If I understood your suggestion, we want to use an assertion framework, so I reworked the tests here to use the same assertion library found in other packages here. I kept this in a separate commit, since it's unrelated cleanup.
There was a problem hiding this comment.
Yes, we are slowly migrating everything to testify assertions.
|
Thanks for the feedback, @dnephin ! |
There was a problem hiding this comment.
This doesn't seem like the right place for this. We also don't want to call ping again. I think this line needs to be removed.
There was a problem hiding this comment.
Ah yes, I misunderstood the request to move this to "Initialize". I'm guessing we meant "When we remove UpdateClientVersion, then NegotiateAPIVersion should just take its place".
There was a problem hiding this comment.
This should be `NegotiateAPIVersionPing(ping)
0cb5794 to
e298205
Compare
|
This one needs a rebase because the CLI has been removed from this repo (though the client still exists here). |
e298205 to
fe396be
Compare
|
Woah, I leave the country for a bit and the whole project disappears! I've rebased, and once it's merged/released we can update the cli to take advantage of NegotiateAPIVersion() @cpuguy83 Incidentally, since the project restructure, moby/moby:master has a failing test in client_test.go: TestClientRedirect, happy to investigate that, just wanted to point out that it's unrelated to this change. |
There was a problem hiding this comment.
I guess context should be an argument to this function. the caller can decide if they have a context they'd like to re-use, or if they want to start a new background context.
174200d to
75b5de5
Compare
|
It appears that node azure-windows-rs1-5 may require daemon/logger/adapter_test.go:137 to be more than 10 milliseconds. Slow shared tenant windows vms aside, we probably don't want to consider log reading to be a failure if it takes more than 10 milliseconds . Maybe >1s is a failure? |
dnephin
left a comment
There was a problem hiding this comment.
LGTM
And yes, that timeout should be increased. I've seen it fail a few times on windowsRS1
Signed-off-by: Royce Remer <[email protected]>
75b5de5 to
5f1d94e
Compare
|
|
||
| // NegotiateAPIVersionPing updates the version string associated with this | ||
| // instance of the Client to match the latest version the server supports | ||
| func (cli *Client) NegotiateAPIVersionPing(p types.Ping) { |
There was a problem hiding this comment.
Does this need to be exposed on the interface?
There was a problem hiding this comment.
I believe it does. This is what we'll call from docker/cli because we already have a Ping object, which we need to store HasExperimental and OSType.
The other one is a "convenience" for other consumers of this library.
- What I did
Added some tests for client version discovery, and moved that logic out of the CLI and into the client.
The drive here is that I was using the go docker client, and had to call UpdateVersion with a string I needed to get from the server. I noticed that the CLI never had to do this, and sure enough there was some server version negotiation going on in the CLI. At this commit, the CLI just implements a normal client, and the client owns the logic for server version negotiation (so folks consuming the client library can enjoy that same functionality).
- How I did it
Added a new conditional statement in client/client.go UpdateClientVersion(str). If the string is empty, it will trigger DowngradeClientVersion() and step into some cut/paste logic that already existed in cli/command/cli.go for pinging the server, grabbing the APIVersion string, and updating that.
- How to verify it
or
The manual/functional verification for the CLI built against this commit:
The test cases cover a few more edges than that:
- Description for the changelog
UpdateClientVersion can auto-downgrade to the server APIVersion
- A picture of a cute animal (not mandatory but encouraged)