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

Include the unversioned.DiscoveryClient in the generated clientset #20320

Merged
merged 1 commit into from Feb 1, 2016
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
29 changes: 24 additions & 5 deletions cmd/libs/go2idl/client-gen/generators/generator-for-clientset.go
Expand Up @@ -97,16 +97,22 @@ func (g *genClientset) GenerateType(c *generator.Context, t *types.Type, w io.Wr
}

m := map[string]interface{}{
"allGroups": allGroups,
"Config": c.Universe.Type(types.Name{Package: pkgUnversioned, Name: "Config"}),
"DefaultKubernetesUserAgent": c.Universe.Function(types.Name{Package: pkgUnversioned, Name: "DefaultKubernetesUserAgent"}),
"RESTClient": c.Universe.Type(types.Name{Package: pkgUnversioned, Name: "RESTClient"}),
"allGroups": allGroups,
"Config": c.Universe.Type(types.Name{Package: pkgUnversioned, Name: "Config"}),
"DefaultKubernetesUserAgent": c.Universe.Function(types.Name{Package: pkgUnversioned, Name: "DefaultKubernetesUserAgent"}),
"RESTClient": c.Universe.Type(types.Name{Package: pkgUnversioned, Name: "RESTClient"}),
"DiscoveryInterface": c.Universe.Type(types.Name{Package: pkgUnversioned, Name: "DiscoveryInterface"}),
"DiscoveryClient": c.Universe.Type(types.Name{Package: pkgUnversioned, Name: "DiscoveryClient"}),
"NewDiscoveryClientForConfig": c.Universe.Function(types.Name{Package: pkgUnversioned, Name: "NewDiscoveryClientForConfig"}),
"NewDiscoveryClientForConfigOrDie": c.Universe.Function(types.Name{Package: pkgUnversioned, Name: "NewDiscoveryClientForConfigOrDie"}),
"NewDiscoveryClient": c.Universe.Function(types.Name{Package: pkgUnversioned, Name: "NewDiscoveryClient"}),
}
sw.Do(clientsetInterfaceTemplate, m)
sw.Do(clientsetTemplate, m)
for _, g := range allGroups {
sw.Do(clientsetInterfaceImplTemplate, g)
}
sw.Do(getDiscoveryTemplate, m)
sw.Do(newClientsetForConfigTemplate, m)
sw.Do(newClientsetForConfigOrDieTemplate, m)
sw.Do(newClientsetForRESTClientTemplate, m)
Expand All @@ -116,6 +122,7 @@ func (g *genClientset) GenerateType(c *generator.Context, t *types.Type, w io.Wr

var clientsetInterfaceTemplate = `
type Interface interface {
Discovery() $.DiscoveryInterface|raw$
$range .allGroups$$.Group$() $.PackageName$.$.Group$Interface
$end$
}
Expand All @@ -125,6 +132,7 @@ var clientsetTemplate = `
// Clientset contains the clients for groups. Each group has exactly one
// version included in a Clientset.
type Clientset struct {
*$.DiscoveryClient|raw$
$range .allGroups$*$.PackageName$.$.Group$Client
$end$
}
Expand All @@ -136,6 +144,12 @@ func (c *Clientset) $.Group$() $.PackageName$.$.Group$Interface {
return c.$.Group$Client
}
`
var getDiscoveryTemplate = `
// Discovery retrieves the DiscoveryClient
func (c *Clientset) Discovery() $.DiscoveryInterface|raw$ {
return c.DiscoveryClient
}
`

var newClientsetForConfigTemplate = `
// NewForConfig creates a new Clientset for the given config.
Expand All @@ -147,6 +161,10 @@ $range .allGroups$ clientset.$.Group$Client, err =$.PackageName$.NewForConfig
return nil, err
}
$end$
clientset.DiscoveryClient, err = $.NewDiscoveryClientForConfig|raw$(c)
if err!=nil {
return nil, err
}
return &clientset, nil
}
`
Expand All @@ -158,6 +176,7 @@ func NewForConfigOrDie(c *$.Config|raw$) *Clientset {
var clientset Clientset
$range .allGroups$ clientset.$.Group$Client =$.PackageName$.NewForConfigOrDie(c)
$end$
clientset.DiscoveryClient = $.NewDiscoveryClientForConfigOrDie|raw$(c)
return &clientset
}
`
Expand All @@ -168,7 +187,7 @@ func New(c *$.RESTClient|raw$) *Clientset {
var clientset Clientset
$range .allGroups$ clientset.$.Group$Client =$.PackageName$.New(c)
$end$

clientset.DiscoveryClient = $.NewDiscoveryClient|raw$(c)
return &clientset
}
`
Expand Up @@ -22,12 +22,14 @@ import (
)

type Interface interface {
Discovery() unversioned.DiscoveryInterface
Testgroup() testgroup_unversioned.TestgroupInterface
}

// Clientset contains the clients for groups. Each group has exactly one
// version included in a Clientset.
type Clientset struct {
*unversioned.DiscoveryClient
*testgroup_unversioned.TestgroupClient
}

Expand All @@ -36,6 +38,11 @@ func (c *Clientset) Testgroup() testgroup_unversioned.TestgroupInterface {
return c.TestgroupClient
}

// Discovery retrieves the DiscoveryClient
func (c *Clientset) Discovery() unversioned.DiscoveryInterface {
return c.DiscoveryClient
}

// NewForConfig creates a new Clientset for the given config.
func NewForConfig(c *unversioned.Config) (*Clientset, error) {
var clientset Clientset
Expand All @@ -45,6 +52,10 @@ func NewForConfig(c *unversioned.Config) (*Clientset, error) {
return nil, err
}

clientset.DiscoveryClient, err = unversioned.NewDiscoveryClientForConfig(c)
if err != nil {
return nil, err
}
return &clientset, nil
}

Expand All @@ -54,6 +65,7 @@ func NewForConfigOrDie(c *unversioned.Config) *Clientset {
var clientset Clientset
clientset.TestgroupClient = testgroup_unversioned.NewForConfigOrDie(c)

clientset.DiscoveryClient = unversioned.NewDiscoveryClientForConfigOrDie(c)
return &clientset
}

Expand All @@ -62,5 +74,6 @@ func New(c *unversioned.RESTClient) *Clientset {
var clientset Clientset
clientset.TestgroupClient = testgroup_unversioned.New(c)

clientset.DiscoveryClient = unversioned.NewDiscoveryClient(c)
return &clientset
}
13 changes: 13 additions & 0 deletions pkg/client/clientset_generated/release_1_1/clientset.go
Expand Up @@ -23,13 +23,15 @@ import (
)

type Interface interface {
Discovery() unversioned.DiscoveryInterface
Legacy() legacy_unversioned.LegacyInterface
Extensions() extensions_unversioned.ExtensionsInterface
}

// Clientset contains the clients for groups. Each group has exactly one
// version included in a Clientset.
type Clientset struct {
*unversioned.DiscoveryClient
*legacy_unversioned.LegacyClient
*extensions_unversioned.ExtensionsClient
}
Expand All @@ -44,6 +46,11 @@ func (c *Clientset) Extensions() extensions_unversioned.ExtensionsInterface {
return c.ExtensionsClient
}

// Discovery retrieves the DiscoveryClient
func (c *Clientset) Discovery() unversioned.DiscoveryInterface {
return c.DiscoveryClient
}

// NewForConfig creates a new Clientset for the given config.
func NewForConfig(c *unversioned.Config) (*Clientset, error) {
var clientset Clientset
Expand All @@ -57,6 +64,10 @@ func NewForConfig(c *unversioned.Config) (*Clientset, error) {
return nil, err
}

clientset.DiscoveryClient, err = unversioned.NewDiscoveryClientForConfig(c)
if err != nil {
return nil, err
}
return &clientset, nil
}

Expand All @@ -67,6 +78,7 @@ func NewForConfigOrDie(c *unversioned.Config) *Clientset {
clientset.LegacyClient = legacy_unversioned.NewForConfigOrDie(c)
clientset.ExtensionsClient = extensions_unversioned.NewForConfigOrDie(c)

clientset.DiscoveryClient = unversioned.NewDiscoveryClientForConfigOrDie(c)
return &clientset
}

Expand All @@ -76,5 +88,6 @@ func New(c *unversioned.RESTClient) *Clientset {
clientset.LegacyClient = legacy_unversioned.New(c)
clientset.ExtensionsClient = extensions_unversioned.New(c)

clientset.DiscoveryClient = unversioned.NewDiscoveryClient(c)
return &clientset
}
5 changes: 5 additions & 0 deletions pkg/client/testing/fake/clientset.go
Expand Up @@ -24,6 +24,7 @@ import (
extensions_unversioned_fake "k8s.io/kubernetes/pkg/client/typed/generated/extensions/unversioned/fake"
legacy_unversioned "k8s.io/kubernetes/pkg/client/typed/generated/legacy/unversioned"
legacy_unversioned_fake "k8s.io/kubernetes/pkg/client/typed/generated/legacy/unversioned/fake"
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/watch"
)
Expand Down Expand Up @@ -61,3 +62,7 @@ func (c *Clientset) Legacy() legacy_unversioned.LegacyInterface {
func (c *Clientset) Extensions() extensions_unversioned.ExtensionsInterface {
return &extensions_unversioned_fake.FakeExtensions{&c.Fake}
}

func (c *Clientset) Discovery() unversioned.DiscoveryInterface {
return &FakeDiscovery{&c.Fake}
}
74 changes: 74 additions & 0 deletions pkg/client/testing/fake/discovery.go
@@ -0,0 +1,74 @@
/*
Copyright 2016 The Kubernetes Authors All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package fake

import (
"github.com/emicklei/go-restful/swagger"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/client/testing/core"
"k8s.io/kubernetes/pkg/version"
)

type FakeDiscovery struct {
*core.Fake
}

func (c *FakeDiscovery) ServerResourcesForGroupVersion(groupVersion string) (*unversioned.APIResourceList, error) {
action := core.ActionImpl{
Verb: "get",
Resource: "resource",
}
c.Invokes(action, nil)
return c.Resources[groupVersion], nil
}

func (c *FakeDiscovery) ServerResources() (map[string]*unversioned.APIResourceList, error) {
action := core.ActionImpl{
Verb: "get",
Resource: "resource",
}
c.Invokes(action, nil)
return c.Resources, nil
}

func (c *FakeDiscovery) ServerGroups() (*unversioned.APIGroupList, error) {
return nil, nil
}

func (c *FakeDiscovery) ServerVersion() (*version.Info, error) {
action := core.ActionImpl{}
action.Verb = "get"
action.Resource = "version"

c.Invokes(action, nil)
versionInfo := version.Get()
return &versionInfo, nil
}

func (c *FakeDiscovery) SwaggerSchema(version unversioned.GroupVersion) (*swagger.ApiDeclaration, error) {
action := core.ActionImpl{}
action.Verb = "get"
if version == v1.SchemeGroupVersion {
action.Resource = "/swaggerapi/api/" + version.Version
} else {
action.Resource = "/swaggerapi/apis/" + version.Group + "/" + version.Version
}

c.Invokes(action, nil)
return &swagger.ApiDeclaration{}, nil
}
20 changes: 18 additions & 2 deletions pkg/client/unversioned/discovery_client.go
Expand Up @@ -214,13 +214,29 @@ func setDiscoveryDefaults(config *Config) error {
return nil
}

// NewDiscoveryClient creates a new DiscoveryClient for the given config. This client
// NewDiscoveryClientForConfig creates a new DiscoveryClient for the given config. This client
// can be used to discover supported resources in the API server.
func NewDiscoveryClient(c *Config) (*DiscoveryClient, error) {
func NewDiscoveryClientForConfig(c *Config) (*DiscoveryClient, error) {
config := *c
if err := setDiscoveryDefaults(&config); err != nil {
return nil, err
}
client, err := UnversionedRESTClientFor(&config)
return &DiscoveryClient{client}, err
}

// NewDiscoveryClientForConfig creates a new DiscoveryClient for the given config. If
// there is an error, it panics.
func NewDiscoveryClientForConfigOrDie(c *Config) *DiscoveryClient {
client, err := NewDiscoveryClientForConfig(c)
if err != nil {
panic(err)
}
return client

}

// New creates a new DiscoveryClient for the given RESTClient.
func NewDiscoveryClient(c *RESTClient) *DiscoveryClient {
return &DiscoveryClient{c}
}
2 changes: 1 addition & 1 deletion pkg/client/unversioned/helper.go
Expand Up @@ -150,7 +150,7 @@ func New(c *Config) (*Client, error) {
}

discoveryConfig := *c
discoveryClient, err := NewDiscoveryClient(&discoveryConfig)
discoveryClient, err := NewDiscoveryClientForConfig(&discoveryConfig)
if err != nil {
return nil, err
}
Expand Down