Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: set cli.manualOverride when env var not empty #28647

Merged
merged 1 commit into from
Nov 21, 2016

Conversation

WeiZhang555
Copy link
Contributor

@WeiZhang555 WeiZhang555 commented Nov 21, 2016

In function NewEnvClient, the cli.manualOverride will be set to true
always which is wrong, to fix it we should let manualOverride set to
true only if os.Getenv("DOCKER_API_VERSION") isn't empty.

One more step forward, even user set os.Getenv("DOCKER_API_VERSION"),
we should still allow updating client API version, in case that user set
a unreasonable version number.

If env var "DOCKER_API_VERSION" is specified by user, we'll set
cli.manualOverride, before this, this field is always true due to
wrong logic.

Signed-off-by: Zhang Wei zhangwei555@huawei.com

@WeiZhang555
Copy link
Contributor Author

In function NewEnvClient, the cli.manualOverride will be set to true
always which is wrong,

You can see it in this piece of code:

 	version := os.Getenv("DOCKER_API_VERSION")
 	if version == "" {
 		version = DefaultVersion
 	}
 
 	cli, err := NewClient(host, version, client, nil)
  	if err != nil {
  		return cli, err
  	}
 	if version != "" {
 		cli.manualOverride = true
 	}

version is never an empty string, which will make cli.manualOverride = true

ping related person: @vieux

@vieux vieux self-assigned this Nov 21, 2016
@vieux
Copy link
Contributor

vieux commented Nov 21, 2016

@WeiZhang555 it's is not set to true always, it's only set to true when the env var is not specified.

This is the intended behavior, is you specify a version in the env, we should not try to use anything else.

@WeiZhang555
Copy link
Contributor Author

@vieux I mean in this piece of code:

 	version := os.Getenv("DOCKER_API_VERSION")
 	if version == "" {
 		version = DefaultVersion
 	}

if os.Getenv("DOCKER_API_VERSION") is empty, the version will be set to DefaultVersion (1.25), after that

    if version != "" {
 		cli.manualOverride = true
 	}

the if statement will always be true

@WeiZhang555
Copy link
Contributor Author

WeiZhang555 commented Nov 21, 2016

This is the intended behavior, is you specify a version in the env, we should not try to use anything else.

I can accept it if this is exactly the design, what I'll suggest is modify this line:

https://github.com/docker/docker/blob/master/client/client.go#L125-L127

instead:

	if os.Getenv("DOCKER_API_VERSION") != "" {
		cli.manualOverride = true
	}

@WeiZhang555
Copy link
Contributor Author

it's is not set to true always, it's only set to true when the env var is not specified.

Ooops, you mean env var is not specified? I thought it should be is specified. Are you making a typo or you really mean it ?

@vieux
Copy link
Contributor

vieux commented Nov 21, 2016

@WeiZhang555 you're right, it should be

if os.Getenv("DOCKER_API_VERSION") != "" {
		cli.manualOverride = true
	}

we set the manualOverride when DOCKER_API_VERSION is specified

@thaJeztah
Copy link
Member

Hm, looks like I commented something like that, but it got lost in the last change there? #27745 (comment)

@vdemeester vdemeester added this to the 1.13.0 milestone Nov 21, 2016
@WeiZhang555
Copy link
Contributor Author

WeiZhang555 commented Nov 21, 2016

Let me make some update to fix it 😄

@thaJeztah
Copy link
Member

My previous comment may not be related here (was discussing with @vieux) 😊 Thanks for addressing this @WeiZhang555

If env var "DOCKER_API_VERSION" is specified by user, we'll set
`cli.manualOverride`, before this, this field is always true due to
wrong logic.

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
@WeiZhang555 WeiZhang555 changed the title Allow DOCKER_API_VERSION to be overrided by docker Bugfix: set cli.manualOverride when env var not empty Nov 21, 2016
@WeiZhang555
Copy link
Contributor Author

Updated, PTAL~~

@vieux
Copy link
Contributor

vieux commented Nov 21, 2016

LGTM thanks @WeiZhang555

Copy link
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 🐮

@vieux vieux merged commit 51c107b into moby:master Nov 21, 2016
@WeiZhang555 WeiZhang555 deleted the dont-lock-client-version branch November 22, 2016 01:35
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.

5 participants