Skip to content

pull client API version negotiation out of the CLI and into the client#32779

Merged
cpuguy83 merged 1 commit intomoby:masterfrom
rremer:auto-update-client
Jun 22, 2017
Merged

pull client API version negotiation out of the CLI and into the client#32779
cpuguy83 merged 1 commit intomoby:masterfrom
rremer:auto-update-client

Conversation

@rremer
Copy link
Copy Markdown
Contributor

@rremer rremer commented Apr 22, 2017

- 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

docker run --privileged -e DOCKER_GITCOMMIT=eebfdd0 docker hack/make.sh test-unit test-integration-cli test-docker-py

or

cd client
go test

The manual/functional verification for the CLI built against this commit:

  1. start a daemon of an older version
  2. docker info

The test cases cover a few more edges than that:

  • if the server doesn't return an APIVersion
  • if the environment of the CLI specifically pins DOCKER_API_VERSION

- Description for the changelog

UpdateClientVersion can auto-downgrade to the server APIVersion

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

shibs

@AkihiroSuda AkihiroSuda added area/cli Client status/failing-ci Indicates that the PR in its current state fails the test suite labels Apr 25, 2017
@vdemeester vdemeester requested review from dnephin and vieux April 26, 2017 13:20
@vdemeester
Copy link
Copy Markdown
Member

@rremer build error

09:50:33 --- FAIL: TestClientDebugEnabled (0.00s)
09:50:33 	assertions.go:226: 
                          
	Error Trace:	docker_test.go:21
09:50:33 		
	Error:      	Received unexpected error:
09:50:33 		
	            	Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
09:50:33 FAIL
09:50:33 coverage: 29.1% of statements

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.

Overall I think this is good, so design LGTM

Comment thread cli/command/cli.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.

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.

Comment thread client/client.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.

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.

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.

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)

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.

We don't make any promises about not breaking the API on client/ it's not being released as a versioned package.

Comment thread client/client.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.

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() ?

Comment thread client/client.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.

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
}

Comment thread client/client_test.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.

assert.Equal(t, expected, client.version)

(same with the other assertions)

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.

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.

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, we are slowly migrating everything to testify assertions.

@GordonTheTurtle GordonTheTurtle added the dco/no Automatically set by a bot when one of the commits lacks proper signature label Apr 28, 2017
@rremer
Copy link
Copy Markdown
Contributor Author

rremer commented Apr 28, 2017

Thanks for the feedback, @dnephin !

Comment thread cli/command/cli.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 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.

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.

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".

Comment thread cli/command/cli.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 be `NegotiateAPIVersionPing(ping)

@rremer rremer force-pushed the auto-update-client branch from 0cb5794 to e298205 Compare April 30, 2017 23:46
@GordonTheTurtle GordonTheTurtle removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label Apr 30, 2017
@dnephin dnephin added rebuild/powerpc and removed status/failing-ci Indicates that the PR in its current state fails the test suite labels May 1, 2017
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

@cpuguy83
Copy link
Copy Markdown
Member

cpuguy83 commented Jun 9, 2017

This one needs a rebase because the CLI has been removed from this repo (though the client still exists here).

@rremer rremer force-pushed the auto-update-client branch from e298205 to fe396be Compare June 13, 2017 01:21
@rremer
Copy link
Copy Markdown
Contributor Author

rremer commented Jun 13, 2017

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.

Comment thread client/client.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.

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.

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.

Done.

@rremer rremer force-pushed the auto-update-client branch 2 times, most recently from 174200d to 75b5de5 Compare June 16, 2017 00:02
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

@rremer
Copy link
Copy Markdown
Contributor Author

rremer commented Jun 16, 2017

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?

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

And yes, that timeout should be increased. I've seen it fail a few times on windowsRS1

@rremer
Copy link
Copy Markdown
Contributor Author

rremer commented Jun 19, 2017

FYI, I standardized the timeouts in daemon logger tests in #33727, and implemented the same assertion framework there @dnephin ... so hopefully you won't have to rebuild as much :p

Comment thread client/client_test.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 not be exported.

Comment thread client/client_test.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 not be exported.

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.

sure, done.

@rremer rremer force-pushed the auto-update-client branch from 75b5de5 to 5f1d94e Compare June 21, 2017 05:58
Comment thread client/client.go

// 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) {
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.

Does this need to be exposed on the interface?

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.

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.

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

@cpuguy83 cpuguy83 merged commit 8a672ba into moby:master Jun 22, 2017
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.

7 participants