Skip to content

Commit

Permalink
Merge pull request kubernetes#17316 from deads2k/gv-ClientForVersion
Browse files Browse the repository at this point in the history
Auto commit by PR queue bot
  • Loading branch information
k8s-merge-robot committed Nov 24, 2015
2 parents a229925 + a87d927 commit 4fd6b6d
Show file tree
Hide file tree
Showing 45 changed files with 314 additions and 224 deletions.
7 changes: 4 additions & 3 deletions cluster/addons/dns/kube2sky/kube2sky.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/golang/glog"
skymsg "github.com/skynetservices/skydns/msg"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
kcache "k8s.io/kubernetes/pkg/client/cache"
kclient "k8s.io/kubernetes/pkg/client/unversioned"
kclientcmd "k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
Expand Down Expand Up @@ -479,8 +480,8 @@ func newKubeClient() (*kclient.Client, error) {
if masterURL != "" && *argKubecfgFile == "" {
// Only --kube_master_url was provided.
config = &kclient.Config{
Host: masterURL,
Version: "v1",
Host: masterURL,
GroupVersion: &unversioned.GroupVersion{Version: "v1"},
}
} else {
// We either have:
Expand All @@ -498,7 +499,7 @@ func newKubeClient() (*kclient.Client, error) {
}

glog.Infof("Using %s for kubernetes master", config.Host)
glog.Infof("Using kubernetes API %s", config.Version)
glog.Infof("Using kubernetes API %v", config.GroupVersion)
return kclient.New(config)
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ func startComponents(firstManifestURL, secondManifestURL string) (string, string
glog.Fatalf("Failed to connect to etcd")
}

cl := client.NewOrDie(&client.Config{Host: apiServer.URL, Version: testapi.Default.GroupAndVersion()})
cl := client.NewOrDie(&client.Config{Host: apiServer.URL, GroupVersion: testapi.Default.GroupVersion()})

// TODO: caesarxuchao: hacky way to specify version of Experimental client.
// We will fix this by supporting multiple group versions in Config
cl.ExtensionsClient = client.NewExtensionsOrDie(&client.Config{Host: apiServer.URL, Version: testapi.Extensions.GroupAndVersion()})
cl.ExtensionsClient = client.NewExtensionsOrDie(&client.Config{Host: apiServer.URL, GroupVersion: testapi.Extensions.GroupVersion()})

storageVersions := make(map[string]string)
etcdStorage, err := master.NewEtcdStorage(etcdClient, latest.GroupOrDie("").InterfacesFor, testapi.Default.GroupAndVersion(), etcdtest.PathPrefix())
Expand Down Expand Up @@ -987,10 +987,10 @@ func main() {
// Wait for the synchronization threads to come up.
time.Sleep(time.Second * 10)

kubeClient := client.NewOrDie(&client.Config{Host: apiServerURL, Version: testapi.Default.GroupAndVersion()})
kubeClient := client.NewOrDie(&client.Config{Host: apiServerURL, GroupVersion: testapi.Default.GroupVersion()})
// TODO: caesarxuchao: hacky way to specify version of Experimental client.
// We will fix this by supporting multiple group versions in Config
kubeClient.ExtensionsClient = client.NewExtensionsOrDie(&client.Config{Host: apiServerURL, Version: testapi.Extensions.GroupAndVersion()})
kubeClient.ExtensionsClient = client.NewExtensionsOrDie(&client.Config{Host: apiServerURL, GroupVersion: testapi.Extensions.GroupVersion()})

// Run tests in parallel
testFuncs := []testFunc{
Expand Down
12 changes: 10 additions & 2 deletions cmd/kube-apiserver/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/latest"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/unversioned"
apiutil "k8s.io/kubernetes/pkg/api/util"
"k8s.io/kubernetes/pkg/api/validation"
"k8s.io/kubernetes/pkg/apiserver"
Expand Down Expand Up @@ -432,9 +433,16 @@ func (s *APIServer) Run(_ []string) error {
}

clientConfig := &client.Config{
Host: net.JoinHostPort(s.InsecureBindAddress.String(), strconv.Itoa(s.InsecurePort)),
Version: s.DeprecatedStorageVersion,
Host: net.JoinHostPort(s.InsecureBindAddress.String(), strconv.Itoa(s.InsecurePort)),
}
if len(s.DeprecatedStorageVersion) != 0 {
gv, err := unversioned.ParseGroupVersion(s.DeprecatedStorageVersion)
if err != nil {
glog.Fatalf("error in parsing group version: %s", err)
}
clientConfig.GroupVersion = &gv
}

client, err := client.New(clientConfig)
if err != nil {
glog.Fatalf("Invalid server address: %v", err)
Expand Down
8 changes: 4 additions & 4 deletions contrib/mesos/pkg/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ func TestExecutorLaunchAndKillTask(t *testing.T) {
Updates: updates,
NodeInfos: make(chan NodeInfo, 1),
APIClient: client.NewOrDie(&client.Config{
Host: testApiServer.server.URL,
Version: testapi.Default.Version(),
Host: testApiServer.server.URL,
GroupVersion: testapi.Default.GroupVersion(),
}),
PodStatusFunc: func(pod *api.Pod) (*api.PodStatus, error) {
return &api.PodStatus{
Expand Down Expand Up @@ -338,8 +338,8 @@ func TestExecutorFrameworkMessage(t *testing.T) {
Updates: make(chan kubetypes.PodUpdate, 1024),
NodeInfos: make(chan NodeInfo, 1),
APIClient: client.NewOrDie(&client.Config{
Host: testApiServer.server.URL,
Version: testapi.Default.Version(),
Host: testApiServer.server.URL,
GroupVersion: testapi.Default.GroupVersion(),
}),
PodStatusFunc: func(pod *api.Pod) (*api.PodStatus, error) {
return &api.PodStatus{
Expand Down
4 changes: 2 additions & 2 deletions contrib/mesos/pkg/scheduler/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ func newLifecycleTest(t *testing.T) lifecycleTest {

// create framework
client := client.NewOrDie(&client.Config{
Host: apiServer.server.URL,
Version: testapi.Default.Version(),
Host: apiServer.server.URL,
GroupVersion: testapi.Default.GroupVersion(),
})
c := *schedcfg.CreateDefaultConfig()
fw := framework.New(framework.Config{
Expand Down
9 changes: 9 additions & 0 deletions pkg/api/testapi/testapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"k8s.io/kubernetes/pkg/api"
_ "k8s.io/kubernetes/pkg/api/install"
"k8s.io/kubernetes/pkg/api/unversioned"
_ "k8s.io/kubernetes/pkg/apis/extensions/install"
_ "k8s.io/kubernetes/pkg/apis/metrics/install"

Expand Down Expand Up @@ -87,6 +88,14 @@ func (g TestGroup) GroupAndVersion() string {
return g.GroupVersionUnderTest
}

func (g TestGroup) GroupVersion() *unversioned.GroupVersion {
gv, err := unversioned.ParseGroupVersion(g.GroupVersionUnderTest)
if err != nil {
panic(err)
}
return &gv
}

// Codec returns the codec for the API version to test against, as set by the
// KUBE_TEST_API env var.
func (g TestGroup) Codec() runtime.Codec {
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/cache/listwatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestListWatchesCanList(t *testing.T) {
}
server := httptest.NewServer(&handler)
defer server.Close()
client := client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Default.Version()})
client := client.NewOrDie(&client.Config{Host: server.URL, GroupVersion: testapi.Default.GroupVersion()})
lw := NewListWatchFromClient(client, item.resource, item.namespace, item.fieldSelector)
// This test merely tests that the correct request is made.
lw.List()
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestListWatchesCanWatch(t *testing.T) {
}
server := httptest.NewServer(&handler)
defer server.Close()
client := client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Default.Version()})
client := client.NewOrDie(&client.Config{Host: server.URL, GroupVersion: testapi.Default.GroupVersion()})
lw := NewListWatchFromClient(client, item.resource, item.namespace, item.fieldSelector)
// This test merely tests that the correct request is made.
lw.Watch(api.ListOptions{ResourceVersion: item.rv})
Expand Down
17 changes: 4 additions & 13 deletions pkg/client/unversioned/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ type testClient struct {
Response Response
Error bool
Created bool
Version string
server *httptest.Server
handler *util.FakeHandler
// For query args, an optional function to validate the contents
Expand All @@ -80,24 +79,16 @@ func (c *testClient) Setup(t *testing.T) *testClient {
}
c.server = httptest.NewServer(c.handler)
if c.Client == nil {
version := c.Version
if len(version) == 0 {
version = testapi.Default.Version()
}
c.Client = NewOrDie(&Config{
Host: c.server.URL,
Version: version,
Host: c.server.URL,
GroupVersion: testapi.Default.GroupVersion(),
})

// TODO: caesarxuchao: hacky way to specify version of Experimental client.
// We will fix this by supporting multiple group versions in Config
version = c.Version
if len(version) == 0 {
version = testapi.Extensions.Version()
}
c.ExtensionsClient = NewExtensionsOrDie(&Config{
Host: c.server.URL,
Version: version,
Host: c.server.URL,
GroupVersion: testapi.Extensions.GroupVersion(),
})
}
c.QueryValidator = map[string]func(string, string) bool{}
Expand Down
9 changes: 8 additions & 1 deletion pkg/client/unversioned/clientcmd/client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/imdario/mergo"

"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
client "k8s.io/kubernetes/pkg/client/unversioned"
clientauth "k8s.io/kubernetes/pkg/client/unversioned/auth"
clientcmdapi "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
Expand Down Expand Up @@ -99,7 +100,13 @@ func (config DirectClientConfig) ClientConfig() (*client.Config, error) {
u.Fragment = ""
clientConfig.Host = u.String()
}
clientConfig.Version = configClusterInfo.APIVersion
if len(configClusterInfo.APIVersion) != 0 {
gv, err := unversioned.ParseGroupVersion(configClusterInfo.APIVersion)
if err != nil {
return nil, err
}
clientConfig.GroupVersion = &gv
}

// only try to read the auth information if we are secure
if client.IsConfigTransportTLS(*clientConfig) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/unversioned/clientcmd/client_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func TestCreateClean(t *testing.T) {

matchStringArg(config.Clusters["clean"].Server, clientConfig.Host, t)
matchStringArg("", clientConfig.Prefix, t)
matchStringArg(config.Clusters["clean"].APIVersion, clientConfig.Version, t)
matchStringArg(config.Clusters["clean"].APIVersion, clientConfig.GroupVersion.String(), t)
matchBoolArg(config.Clusters["clean"].InsecureSkipTLSVerify, clientConfig.Insecure, t)
matchStringArg(config.AuthInfos["clean"].Token, clientConfig.BearerToken, t)
}
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestCreateCleanDefault(t *testing.T) {
}

matchStringArg(config.Clusters["clean"].Server, clientConfig.Host, t)
matchStringArg(config.Clusters["clean"].APIVersion, clientConfig.Version, t)
matchStringArg(config.Clusters["clean"].APIVersion, clientConfig.GroupVersion.String(), t)
matchBoolArg(config.Clusters["clean"].InsecureSkipTLSVerify, clientConfig.Insecure, t)
matchStringArg(config.AuthInfos["clean"].Token, clientConfig.BearerToken, t)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/unversioned/discovery_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (d *DiscoveryClient) ServerResources() (map[string]*unversioned.APIResource

func setDiscoveryDefaults(config *Config) error {
config.Prefix = ""
config.Version = ""
config.GroupVersion = nil
// Discovery client deals with unversioned objects, so we use api.Codec.
config.Codec = api.Codec
return nil
Expand Down
12 changes: 8 additions & 4 deletions pkg/client/unversioned/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,17 @@ func setExtensionsDefaults(config *Config) error {
}
// TODO: Unconditionally set the config.Version, until we fix the config.
//if config.Version == "" {
config.Version = g.GroupVersion
gv, err := unversioned.ParseGroupVersion(g.GroupVersion)
if err != nil {
return err
}
config.GroupVersion = &gv
//}

versionInterfaces, err := g.InterfacesFor(config.Version)
versionInterfaces, err := g.InterfacesFor(config.GroupVersion.String())
if err != nil {
return fmt.Errorf("Extensions API version '%s' is not recognized (valid values: %s)",
config.Version, strings.Join(latest.GroupOrDie("extensions").Versions, ", "))
return fmt.Errorf("Extensions API group/version '%v' is not recognized (valid values: %s)",
config.GroupVersion, strings.Join(latest.GroupOrDie("extensions").Versions, ", "))
}
config.Codec = versionInterfaces.Codec
if config.QPS == 0 {
Expand Down
Loading

0 comments on commit 4fd6b6d

Please sign in to comment.