Browse Source

Merge pull request #35008 from yujuhong/cli-version

Fix version comparison when negotiating the the API version
Yong Tang 7 years ago
parent
commit
14ce1f1cf4
2 changed files with 10 additions and 2 deletions
  1. 2 2
      client/client.go
  2. 8 0
      client/client_test.go

+ 2 - 2
client/client.go

@@ -248,8 +248,8 @@ func (cli *Client) NegotiateAPIVersionPing(p types.Ping) {
 		cli.version = api.DefaultVersion
 		cli.version = api.DefaultVersion
 	}
 	}
 
 
-	// if server version is lower than the maximum version supported by the Client, downgrade
-	if versions.LessThan(p.APIVersion, api.DefaultVersion) {
+	// if server version is lower than the client version, downgrade
+	if versions.LessThan(p.APIVersion, cli.version) {
 		cli.version = p.APIVersion
 		cli.version = p.APIVersion
 	}
 	}
 }
 }

+ 8 - 0
client/client_test.go

@@ -276,6 +276,14 @@ func TestNegotiateAPIVersion(t *testing.T) {
 	// test downgrade
 	// test downgrade
 	client.NegotiateAPIVersionPing(ping)
 	client.NegotiateAPIVersionPing(ping)
 	assert.Equal(t, expected, client.version)
 	assert.Equal(t, expected, client.version)
+
+	// set the client version to something older, and verify that we keep the
+	// original setting.
+	expected = "1.20"
+	client.version = expected
+	client.NegotiateAPIVersionPing(ping)
+	assert.Equal(t, expected, client.version)
+
 }
 }
 
 
 // TestNegotiateAPIVersionOverride asserts that we honor
 // TestNegotiateAPIVersionOverride asserts that we honor