Update clientset generator to use RESTClient interface instead of the RESTClient data type
This commit is contained in:
@@ -60,10 +60,11 @@ func (g *genFakeForGroup) GenerateType(c *generator.Context, t *types.Type, w io
|
||||
const pkgTestingCore = "k8s.io/kubernetes/pkg/client/testing/core"
|
||||
const pkgRESTClient = "k8s.io/kubernetes/pkg/client/restclient"
|
||||
m := map[string]interface{}{
|
||||
"group": g.group,
|
||||
"Group": namer.IC(g.group),
|
||||
"Fake": c.Universe.Type(types.Name{Package: pkgTestingCore, Name: "Fake"}),
|
||||
"RESTClient": c.Universe.Type(types.Name{Package: pkgRESTClient, Name: "RESTClient"}),
|
||||
"group": g.group,
|
||||
"Group": namer.IC(g.group),
|
||||
"Fake": c.Universe.Type(types.Name{Package: pkgTestingCore, Name: "Fake"}),
|
||||
"RESTClientInterface": c.Universe.Type(types.Name{Package: pkgRESTClient, Name: "Interface"}),
|
||||
"RESTClient": c.Universe.Type(types.Name{Package: pkgRESTClient, Name: "RESTClient"}),
|
||||
}
|
||||
sw.Do(groupClientTemplate, m)
|
||||
for _, t := range g.types {
|
||||
@@ -103,9 +104,10 @@ func (c *Fake$.Group$) $.type|publicPlural$() $.realClientPackage$.$.type|public
|
||||
`
|
||||
|
||||
var getRESTClient = `
|
||||
// GetRESTClient returns a RESTClient that is used to communicate
|
||||
// RESTClient returns a RESTClient that is used to communicate
|
||||
// with API server by this client implementation.
|
||||
func (c *Fake$.Group$) GetRESTClient() *$.RESTClient|raw$ {
|
||||
return nil
|
||||
func (c *Fake$.Group$) RESTClient() $.RESTClientInterface|raw$ {
|
||||
var ret *$.RESTClient|raw$
|
||||
return ret
|
||||
}
|
||||
`
|
||||
|
@@ -92,7 +92,7 @@ func (g *genClientset) GenerateType(c *generator.Context, t *types.Type, w io.Wr
|
||||
"allGroups": allGroups,
|
||||
"Config": c.Universe.Type(types.Name{Package: pkgRESTClient, Name: "Config"}),
|
||||
"DefaultKubernetesUserAgent": c.Universe.Function(types.Name{Package: pkgRESTClient, Name: "DefaultKubernetesUserAgent"}),
|
||||
"RESTClient": c.Universe.Type(types.Name{Package: pkgRESTClient, Name: "RESTClient"}),
|
||||
"RESTClientInterface": c.Universe.Type(types.Name{Package: pkgRESTClient, Name: "Interface"}),
|
||||
"DiscoveryInterface": c.Universe.Type(types.Name{Package: pkgDiscovery, Name: "DiscoveryInterface"}),
|
||||
"DiscoveryClient": c.Universe.Type(types.Name{Package: pkgDiscovery, Name: "DiscoveryClient"}),
|
||||
"NewDiscoveryClientForConfig": c.Universe.Function(types.Name{Package: pkgDiscovery, Name: "NewDiscoveryClientForConfig"}),
|
||||
@@ -183,7 +183,7 @@ $end$
|
||||
|
||||
var newClientsetForRESTClientTemplate = `
|
||||
// New creates a new Clientset for the given RESTClient.
|
||||
func New(c *$.RESTClient|raw$) *Clientset {
|
||||
func New(c $.RESTClientInterface|raw$) *Clientset {
|
||||
var clientset Clientset
|
||||
$range .allGroups$ clientset.$.Group$Client =$.PackageName$.New(c)
|
||||
$end$
|
||||
|
@@ -89,7 +89,7 @@ func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer
|
||||
"types": g.types,
|
||||
"Config": c.Universe.Type(types.Name{Package: pkgRESTClient, Name: "Config"}),
|
||||
"DefaultKubernetesUserAgent": c.Universe.Function(types.Name{Package: pkgRESTClient, Name: "DefaultKubernetesUserAgent"}),
|
||||
"RESTClient": c.Universe.Type(types.Name{Package: pkgRESTClient, Name: "RESTClient"}),
|
||||
"RESTClientInterface": c.Universe.Type(types.Name{Package: pkgRESTClient, Name: "Interface"}),
|
||||
"RESTClientFor": c.Universe.Function(types.Name{Package: pkgRESTClient, Name: "RESTClientFor"}),
|
||||
"latestGroup": c.Universe.Variable(types.Name{Package: pkgRegistered, Name: "Group"}),
|
||||
"GroupOrDie": c.Universe.Variable(types.Name{Package: pkgRegistered, Name: "GroupOrDie"}),
|
||||
@@ -128,7 +128,7 @@ func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer
|
||||
|
||||
var groupInterfaceTemplate = `
|
||||
type $.Group$Interface interface {
|
||||
GetRESTClient() *$.RESTClient|raw$
|
||||
RESTClient() $.RESTClientInterface|raw$
|
||||
$range .types$ $.|publicPlural$Getter
|
||||
$end$
|
||||
}
|
||||
@@ -137,7 +137,7 @@ type $.Group$Interface interface {
|
||||
var groupClientTemplate = `
|
||||
// $.Group$Client is used to interact with features provided by the $.Group$ group.
|
||||
type $.Group$Client struct {
|
||||
*$.RESTClient|raw$
|
||||
restClient $.RESTClientInterface|raw$
|
||||
}
|
||||
`
|
||||
|
||||
@@ -181,19 +181,19 @@ func NewForConfigOrDie(c *$.Config|raw$) *$.Group$Client {
|
||||
`
|
||||
|
||||
var getRESTClient = `
|
||||
// GetRESTClient returns a RESTClient that is used to communicate
|
||||
// RESTClient returns a RESTClient that is used to communicate
|
||||
// with API server by this client implementation.
|
||||
func (c *$.Group$Client) GetRESTClient() *$.RESTClient|raw$ {
|
||||
func (c *$.Group$Client) RESTClient() $.RESTClientInterface|raw$ {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return c.RESTClient
|
||||
return c.restClient
|
||||
}
|
||||
`
|
||||
|
||||
var newClientForRESTClientTemplate = `
|
||||
// New creates a new $.Group$Client for the given RESTClient.
|
||||
func New(c *$.RESTClient|raw$) *$.Group$Client {
|
||||
func New(c $.RESTClientInterface|raw$) *$.Group$Client {
|
||||
return &$.Group$Client{c}
|
||||
}
|
||||
`
|
||||
|
@@ -69,14 +69,15 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
|
||||
pkg := filepath.Base(t.Name.Package)
|
||||
namespaced := !extractBoolTagOrDie("nonNamespaced", t.SecondClosestCommentLines)
|
||||
m := map[string]interface{}{
|
||||
"type": t,
|
||||
"package": pkg,
|
||||
"Package": namer.IC(pkg),
|
||||
"Group": namer.IC(g.group),
|
||||
"watchInterface": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/watch", Name: "Interface"}),
|
||||
"apiParameterCodec": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "ParameterCodec"}),
|
||||
"PatchType": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "PatchType"}),
|
||||
"namespaced": namespaced,
|
||||
"type": t,
|
||||
"package": pkg,
|
||||
"Package": namer.IC(pkg),
|
||||
"Group": namer.IC(g.group),
|
||||
"watchInterface": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/watch", Name: "Interface"}),
|
||||
"RESTClientInterface": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/client/restclient", Name: "Interface"}),
|
||||
"apiParameterCodec": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "ParameterCodec"}),
|
||||
"PatchType": c.Universe.Type(types.Name{Package: "k8s.io/kubernetes/pkg/api", Name: "PatchType"}),
|
||||
"namespaced": namespaced,
|
||||
}
|
||||
|
||||
if g.version == "unversioned" {
|
||||
@@ -134,7 +135,7 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
|
||||
|
||||
// group client will implement this interface.
|
||||
var getterComment = `
|
||||
// $.type|publicPlural$Getter has a method to return a $.type|public$Interface.
|
||||
// $.type|publicPlural$Getter has a method to return a $.type|public$Interface.
|
||||
// A group's client should implement this interface.`
|
||||
|
||||
var getterNamesapced = `
|
||||
@@ -179,7 +180,7 @@ var interfaceTemplate4 = `
|
||||
var structNamespaced = `
|
||||
// $.type|privatePlural$ implements $.type|public$Interface
|
||||
type $.type|privatePlural$ struct {
|
||||
client *$.Group$Client
|
||||
client $.RESTClientInterface|raw$
|
||||
ns string
|
||||
}
|
||||
`
|
||||
@@ -188,7 +189,7 @@ type $.type|privatePlural$ struct {
|
||||
var structNonNamespaced = `
|
||||
// $.type|privatePlural$ implements $.type|public$Interface
|
||||
type $.type|privatePlural$ struct {
|
||||
client *$.Group$Client
|
||||
client $.RESTClientInterface|raw$
|
||||
}
|
||||
`
|
||||
|
||||
@@ -196,7 +197,7 @@ var newStructNamespaced = `
|
||||
// new$.type|publicPlural$ returns a $.type|publicPlural$
|
||||
func new$.type|publicPlural$(c *$.Group$Client, namespace string) *$.type|privatePlural$ {
|
||||
return &$.type|privatePlural${
|
||||
client: c,
|
||||
client: c.RESTClient(),
|
||||
ns: namespace,
|
||||
}
|
||||
}
|
||||
@@ -206,7 +207,7 @@ var newStructNonNamespaced = `
|
||||
// new$.type|publicPlural$ returns a $.type|publicPlural$
|
||||
func new$.type|publicPlural$(c *$.Group$Client) *$.type|privatePlural$ {
|
||||
return &$.type|privatePlural${
|
||||
client: c,
|
||||
client: c.RESTClient(),
|
||||
}
|
||||
}
|
||||
`
|
||||
|
@@ -82,7 +82,7 @@ func NewForConfigOrDie(c *restclient.Config) *Clientset {
|
||||
}
|
||||
|
||||
// New creates a new Clientset for the given RESTClient.
|
||||
func New(c *restclient.RESTClient) *Clientset {
|
||||
func New(c restclient.Interface) *Clientset {
|
||||
var clientset Clientset
|
||||
clientset.TestgroupClient = unversionedtestgroup.New(c)
|
||||
|
||||
|
@@ -35,7 +35,7 @@ func ClientSetRateLimiterTest(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("creating clientset for config %v failed: %v", config, err)
|
||||
}
|
||||
testGroupThrottler := clientSet.Testgroup().GetRESTClient().GetRateLimiter()
|
||||
testGroupThrottler := clientSet.Testgroup().RESTClient().GetRateLimiter()
|
||||
|
||||
if rateLimiter != testGroupThrottler {
|
||||
t.Errorf("Clients in client set should use rateLimiter passed in config:\noriginal: %v\ntestGroup: %v", rateLimiter, testGroupThrottler)
|
||||
|
@@ -30,8 +30,9 @@ func (c *FakeTestgroup) TestTypes(namespace string) unversioned.TestTypeInterfac
|
||||
return &FakeTestTypes{c, namespace}
|
||||
}
|
||||
|
||||
// GetRESTClient returns a RESTClient that is used to communicate
|
||||
// RESTClient returns a RESTClient that is used to communicate
|
||||
// with API server by this client implementation.
|
||||
func (c *FakeTestgroup) GetRESTClient() *restclient.RESTClient {
|
||||
return nil
|
||||
func (c *FakeTestgroup) RESTClient() restclient.Interface {
|
||||
var ret *restclient.RESTClient
|
||||
return ret
|
||||
}
|
||||
|
@@ -23,13 +23,13 @@ import (
|
||||
)
|
||||
|
||||
type TestgroupInterface interface {
|
||||
GetRESTClient() *restclient.RESTClient
|
||||
RESTClient() restclient.Interface
|
||||
TestTypesGetter
|
||||
}
|
||||
|
||||
// TestgroupClient is used to interact with features provided by the Testgroup group.
|
||||
type TestgroupClient struct {
|
||||
*restclient.RESTClient
|
||||
restClient restclient.Interface
|
||||
}
|
||||
|
||||
func (c *TestgroupClient) TestTypes(namespace string) TestTypeInterface {
|
||||
@@ -60,7 +60,7 @@ func NewForConfigOrDie(c *restclient.Config) *TestgroupClient {
|
||||
}
|
||||
|
||||
// New creates a new TestgroupClient for the given RESTClient.
|
||||
func New(c *restclient.RESTClient) *TestgroupClient {
|
||||
func New(c restclient.Interface) *TestgroupClient {
|
||||
return &TestgroupClient{c}
|
||||
}
|
||||
|
||||
@@ -89,11 +89,11 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetRESTClient returns a RESTClient that is used to communicate
|
||||
// RESTClient returns a RESTClient that is used to communicate
|
||||
// with API server by this client implementation.
|
||||
func (c *TestgroupClient) GetRESTClient() *restclient.RESTClient {
|
||||
func (c *TestgroupClient) RESTClient() restclient.Interface {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return c.RESTClient
|
||||
return c.restClient
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ package unversioned
|
||||
import (
|
||||
testgroup_k8s_io "k8s.io/kubernetes/cmd/libs/go2idl/client-gen/test_apis/testgroup.k8s.io"
|
||||
api "k8s.io/kubernetes/pkg/api"
|
||||
restclient "k8s.io/kubernetes/pkg/client/restclient"
|
||||
watch "k8s.io/kubernetes/pkg/watch"
|
||||
)
|
||||
|
||||
@@ -44,14 +45,14 @@ type TestTypeInterface interface {
|
||||
|
||||
// testTypes implements TestTypeInterface
|
||||
type testTypes struct {
|
||||
client *TestgroupClient
|
||||
client restclient.Interface
|
||||
ns string
|
||||
}
|
||||
|
||||
// newTestTypes returns a TestTypes
|
||||
func newTestTypes(c *TestgroupClient, namespace string) *testTypes {
|
||||
return &testTypes{
|
||||
client: c,
|
||||
client: c.RESTClient(),
|
||||
ns: namespace,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user