mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #3940 from jlowdermilk/fix-client-for-version
Fix client for version
This commit is contained in:
commit
a6fd7204b6
@ -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
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user