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

Fix client for version #3940

Merged
merged 1 commit into from
Jan 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/kubectl/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
25 changes: 25 additions & 0 deletions pkg/kubectl/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"io"
"io/ioutil"
"testing"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
Expand Down Expand Up @@ -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)
}
}
}