Merge pull request #3940 from jlowdermilk/fix-client-for-version

Fix client for version
This commit is contained in:
Satnam Singh 2015-01-30 07:58:13 -08:00
commit a6fd7204b6
2 changed files with 29 additions and 2 deletions

View File

@ -329,17 +329,19 @@ func (c *clientCache) ClientConfigForVersion(version string) (*client.Config, er
return nil, err
}
c.defaultConfig = config
if c.matchVersion {
if err := client.MatchesServerVersion(config); err != nil {
return nil, err
}
}
}
// TODO: have a better config copy method
config := *c.defaultConfig
if len(version) != 0 {
config.Version = version
}
client.SetKubernetesDefaults(&config)
return &config, nil
}

View File

@ -21,6 +21,7 @@ import (
"fmt"
"io"
"io/ioutil"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
@ -172,3 +173,27 @@ func objBody(codec runtime.Codec, obj runtime.Object) io.ReadCloser {
func stringBody(body string) io.ReadCloser {
return ioutil.NopCloser(bytes.NewReader([]byte(body)))
}
// Verify that resource.RESTClients constructed from a factory respect mapping.APIVersion
func TestClientVersions(t *testing.T) {
f := NewFactory(nil)
versions := []string{
"v1beta1",
"v1beta2",
"v1beta3",
}
for _, version := range versions {
mapping := &meta.RESTMapping{
APIVersion: version,
}
c, err := f.RESTClient(nil, mapping)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
client := c.(*client.RESTClient)
if client.APIVersion() != version {
t.Errorf("unexpected Client APIVersion: %s %v", client.APIVersion, client)
}
}
}