Skip to content

Commit 6c274ea

Browse files
committed
update client gen
1 parent dde6e8e commit 6c274ea

File tree

2 files changed

+42
-28
lines changed

2 files changed

+42
-28
lines changed

staging/src/k8s.io/code-generator/cmd/client-gen/generators/fake/generator_fake_for_type.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,12 @@ func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.
122122
"group": canonicalGroup,
123123
"groupName": groupName,
124124
"version": g.version,
125+
"CreateOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "CreateOptions"}),
125126
"DeleteOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "DeleteOptions"}),
126-
"ListOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"}),
127127
"GetOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GetOptions"}),
128+
"ListOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"}),
129+
"PatchOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "PatchOptions"}),
130+
"UpdateOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "UpdateOptions"}),
128131
"Everything": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/labels", Name: "Everything"}),
129132
"GroupVersionResource": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersionResource"}),
130133
"GroupVersionKind": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersionKind"}),
@@ -392,7 +395,7 @@ func (c *Fake$.type|publicPlural$) DeleteCollection(ctx context.Context, options
392395
`
393396
var createTemplate = `
394397
// Create takes the representation of a $.inputType|private$ and creates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
395-
func (c *Fake$.type|publicPlural$) Create(ctx context.Context, $.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
398+
func (c *Fake$.type|publicPlural$) Create(ctx context.Context, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (result *$.resultType|raw$, err error) {
396399
obj, err := c.Fake.
397400
$if .namespaced$Invokes($.NewCreateAction|raw$($.inputType|allLowercasePlural$Resource, c.ns, $.inputType|private$), &$.resultType|raw${})
398401
$else$Invokes($.NewRootCreateAction|raw$($.inputType|allLowercasePlural$Resource, $.inputType|private$), &$.resultType|raw${})$end$
@@ -405,7 +408,7 @@ func (c *Fake$.type|publicPlural$) Create(ctx context.Context, $.inputType|priva
405408

406409
var createSubresourceTemplate = `
407410
// Create takes the representation of a $.inputType|private$ and creates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
408-
func (c *Fake$.type|publicPlural$) Create(ctx context.Context, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
411+
func (c *Fake$.type|publicPlural$) Create(ctx context.Context, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (result *$.resultType|raw$, err error) {
409412
obj, err := c.Fake.
410413
$if .namespaced$Invokes($.NewCreateSubresourceAction|raw$($.type|allLowercasePlural$Resource, $.type|private$Name, "$.subresourcePath$", c.ns, $.inputType|private$), &$.resultType|raw${})
411414
$else$Invokes($.NewRootCreateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "$.subresourcePath$", $.inputType|private$), &$.resultType|raw${})$end$
@@ -418,7 +421,7 @@ func (c *Fake$.type|publicPlural$) Create(ctx context.Context, $.type|private$Na
418421

419422
var updateTemplate = `
420423
// Update takes the representation of a $.inputType|private$ and updates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
421-
func (c *Fake$.type|publicPlural$) Update(ctx context.Context, $.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
424+
func (c *Fake$.type|publicPlural$) Update(ctx context.Context, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) {
422425
obj, err := c.Fake.
423426
$if .namespaced$Invokes($.NewUpdateAction|raw$($.inputType|allLowercasePlural$Resource, c.ns, $.inputType|private$), &$.resultType|raw${})
424427
$else$Invokes($.NewRootUpdateAction|raw$($.inputType|allLowercasePlural$Resource, $.inputType|private$), &$.resultType|raw${})$end$
@@ -431,7 +434,7 @@ func (c *Fake$.type|publicPlural$) Update(ctx context.Context, $.inputType|priva
431434

432435
var updateSubresourceTemplate = `
433436
// Update takes the representation of a $.inputType|private$ and updates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
434-
func (c *Fake$.type|publicPlural$) Update(ctx context.Context, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
437+
func (c *Fake$.type|publicPlural$) Update(ctx context.Context, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) {
435438
obj, err := c.Fake.
436439
$if .namespaced$Invokes($.NewUpdateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "$.subresourcePath$", c.ns, $.inputType|private$), &$.inputType|raw${})
437440
$else$Invokes($.NewRootUpdateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "$.subresourcePath$", $.inputType|private$), &$.resultType|raw${})$end$
@@ -445,7 +448,7 @@ func (c *Fake$.type|publicPlural$) Update(ctx context.Context, $.type|private$Na
445448
var updateStatusTemplate = `
446449
// UpdateStatus was generated because the type contains a Status member.
447450
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
448-
func (c *Fake$.type|publicPlural$) UpdateStatus(ctx context.Context, $.type|private$ *$.type|raw$) (*$.type|raw$, error) {
451+
func (c *Fake$.type|publicPlural$) UpdateStatus(ctx context.Context, $.type|private$ *$.type|raw$, opts $.UpdateOptions|raw$) (*$.type|raw$, error) {
449452
obj, err := c.Fake.
450453
$if .namespaced$Invokes($.NewUpdateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "status", c.ns, $.type|private$), &$.type|raw${})
451454
$else$Invokes($.NewRootUpdateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "status", $.type|private$), &$.type|raw${})$end$
@@ -467,7 +470,7 @@ func (c *Fake$.type|publicPlural$) Watch(ctx context.Context, opts $.ListOptions
467470

468471
var patchTemplate = `
469472
// Patch applies the patch and returns the patched $.resultType|private$.
470-
func (c *Fake$.type|publicPlural$) Patch(ctx context.Context, name string, pt $.PatchType|raw$, data []byte, subresources ...string) (result *$.resultType|raw$, err error) {
473+
func (c *Fake$.type|publicPlural$) Patch(ctx context.Context, name string, pt $.PatchType|raw$, data []byte, opts $.PatchOptions|raw$, subresources ...string) (result *$.resultType|raw$, err error) {
471474
obj, err := c.Fake.
472475
$if .namespaced$Invokes($.NewPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, c.ns, name, pt, data, subresources... ), &$.resultType|raw${})
473476
$else$Invokes($.NewRootPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, name, pt, data, subresources...), &$.resultType|raw${})$end$

staging/src/k8s.io/code-generator/cmd/client-gen/generators/generator_for_type.go

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ type genClientForType struct {
4343
var _ generator.Generator = &genClientForType{}
4444

4545
// Filter ignores all but one type because we're making a single file per type.
46-
func (g *genClientForType) Filter(c *generator.Context, t *types.Type) bool { return t == g.typeToMatch }
46+
func (g *genClientForType) Filter(c *generator.Context, t *types.Type) bool {
47+
return t == g.typeToMatch
48+
}
4749

4850
func (g *genClientForType) Namers(c *generator.Context) namer.NameSystems {
4951
return namer.NameSystems{
@@ -116,9 +118,10 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
116118
"type": t,
117119
"inputType": &inputType,
118120
"resultType": &resultType,
119-
"DeleteOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "DeleteOptions"}),
120-
"ListOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"}),
121+
"CreateOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "CreateOptions"}),
121122
"GetOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GetOptions"}),
123+
"ListOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"}),
124+
"UpdateOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "UpdateOptions"}),
122125
"PatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "PatchType"}),
123126
},
124127
})
@@ -135,9 +138,12 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
135138
"subresourcePath": "",
136139
"GroupGoName": g.groupGoName,
137140
"Version": namer.IC(g.version),
141+
"CreateOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "CreateOptions"}),
138142
"DeleteOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "DeleteOptions"}),
139-
"ListOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"}),
140143
"GetOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GetOptions"}),
144+
"ListOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"}),
145+
"PatchOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "PatchOptions"}),
146+
"UpdateOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "UpdateOptions"}),
141147
"PatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "PatchType"}),
142148
"watchInterface": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "Interface"}),
143149
"RESTClientInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Interface"}),
@@ -304,22 +310,22 @@ func generateInterface(tags util.Tags) string {
304310
}
305311

306312
var subresourceDefaultVerbTemplates = map[string]string{
307-
"create": `Create(ctx context.Context, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$) (*$.resultType|raw$, error)`,
313+
"create": `Create(ctx context.Context, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (*$.resultType|raw$, error)`,
308314
"list": `List(ctx context.Context, $.type|private$Name string, opts $.ListOptions|raw$) (*$.resultType|raw$List, error)`,
309-
"update": `Update(ctx context.Context, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$) (*$.resultType|raw$, error)`,
315+
"update": `Update(ctx context.Context, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (*$.resultType|raw$, error)`,
310316
"get": `Get(ctx context.Context, $.type|private$Name string, options $.GetOptions|raw$) (*$.resultType|raw$, error)`,
311317
}
312318

313319
var defaultVerbTemplates = map[string]string{
314-
"create": `Create(context.Context, *$.inputType|raw$) (*$.resultType|raw$, error)`,
315-
"update": `Update(context.Context, *$.inputType|raw$) (*$.resultType|raw$, error)`,
316-
"updateStatus": `UpdateStatus(context.Context, *$.type|raw$) (*$.type|raw$, error)`,
317-
"delete": `Delete(ctx context.Context, name string, options *$.DeleteOptions|raw$) error`,
318-
"deleteCollection": `DeleteCollection(ctx context.Context, options *$.DeleteOptions|raw$, listOptions $.ListOptions|raw$) error`,
319-
"get": `Get(ctx context.Context, name string, options $.GetOptions|raw$) (*$.resultType|raw$, error)`,
320+
"create": `Create(ctx context.Context, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (*$.resultType|raw$, error)`,
321+
"update": `Update(ctx context.Context, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (*$.resultType|raw$, error)`,
322+
"updateStatus": `UpdateStatus(ctx context.Context, $.inputType|private$ *$.type|raw$, opts $.UpdateOptions|raw$) (*$.type|raw$, error)`,
323+
"delete": `Delete(ctx context.Context, name string, opts *$.DeleteOptions|raw$) error`,
324+
"deleteCollection": `DeleteCollection(ctx context.Context, opts *$.DeleteOptions|raw$, listOpts $.ListOptions|raw$) error`,
325+
"get": `Get(ctx context.Context, name string, opts $.GetOptions|raw$) (*$.resultType|raw$, error)`,
320326
"list": `List(ctx context.Context, opts $.ListOptions|raw$) (*$.resultType|raw$List, error)`,
321327
"watch": `Watch(ctx context.Context, opts $.ListOptions|raw$) ($.watchInterface|raw$, error)`,
322-
"patch": `Patch(ctx context.Context, name string, pt $.PatchType|raw$, data []byte, subresources ...string) (result *$.resultType|raw$, err error)`,
328+
"patch": `Patch(ctx context.Context, name string, pt $.PatchType|raw$, data []byte, opts $.PatchOptions|raw$, subresources ...string) (result *$.resultType|raw$, err error)`,
323329
}
324330

325331
// group client will implement this interface.
@@ -488,13 +494,14 @@ func (c *$.type|privatePlural$) DeleteCollection(ctx context.Context, options *$
488494

489495
var createSubresourceTemplate = `
490496
// Create takes the representation of a $.inputType|private$ and creates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
491-
func (c *$.type|privatePlural$) Create(ctx context.Context, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
497+
func (c *$.type|privatePlural$) Create(ctx context.Context, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (result *$.resultType|raw$, err error) {
492498
result = &$.resultType|raw${}
493499
err = c.client.Post().
494500
$if .namespaced$Namespace(c.ns).$end$
495501
Resource("$.type|resource$").
496502
Name($.type|private$Name).
497503
SubResource("$.subresourcePath$").
504+
VersionedParams(&opts, $.schemeParameterCodec|raw$).
498505
Body($.inputType|private$).
499506
Do(ctx).
500507
Into(result)
@@ -504,11 +511,12 @@ func (c *$.type|privatePlural$) Create(ctx context.Context, $.type|private$Name
504511

505512
var createTemplate = `
506513
// Create takes the representation of a $.inputType|private$ and creates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
507-
func (c *$.type|privatePlural$) Create(ctx context.Context, $.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
514+
func (c *$.type|privatePlural$) Create(ctx context.Context, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (result *$.resultType|raw$, err error) {
508515
result = &$.resultType|raw${}
509516
err = c.client.Post().
510517
$if .namespaced$Namespace(c.ns).$end$
511518
Resource("$.type|resource$").
519+
VersionedParams(&opts, $.schemeParameterCodec|raw$).
512520
Body($.inputType|private$).
513521
Do(ctx).
514522
Into(result)
@@ -518,13 +526,14 @@ func (c *$.type|privatePlural$) Create(ctx context.Context, $.inputType|private$
518526

519527
var updateSubresourceTemplate = `
520528
// Update takes the top resource name and the representation of a $.inputType|private$ and updates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
521-
func (c *$.type|privatePlural$) Update(ctx context.Context, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
529+
func (c *$.type|privatePlural$) Update(ctx context.Context, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) {
522530
result = &$.resultType|raw${}
523531
err = c.client.Put().
524532
$if .namespaced$Namespace(c.ns).$end$
525533
Resource("$.type|resource$").
526534
Name($.type|private$Name).
527535
SubResource("$.subresourcePath$").
536+
VersionedParams(&opts, $.schemeParameterCodec|raw$).
528537
Body($.inputType|private$).
529538
Do(ctx).
530539
Into(result)
@@ -534,12 +543,13 @@ func (c *$.type|privatePlural$) Update(ctx context.Context, $.type|private$Name
534543

535544
var updateTemplate = `
536545
// Update takes the representation of a $.inputType|private$ and updates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
537-
func (c *$.type|privatePlural$) Update(ctx context.Context, $.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
546+
func (c *$.type|privatePlural$) Update(ctx context.Context, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) {
538547
result = &$.resultType|raw${}
539548
err = c.client.Put().
540549
$if .namespaced$Namespace(c.ns).$end$
541550
Resource("$.type|resource$").
542551
Name($.inputType|private$.Name).
552+
VersionedParams(&opts, $.schemeParameterCodec|raw$).
543553
Body($.inputType|private$).
544554
Do(ctx).
545555
Into(result)
@@ -550,14 +560,14 @@ func (c *$.type|privatePlural$) Update(ctx context.Context, $.inputType|private$
550560
var updateStatusTemplate = `
551561
// UpdateStatus was generated because the type contains a Status member.
552562
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
553-
554-
func (c *$.type|privatePlural$) UpdateStatus(ctx context.Context, $.type|private$ *$.type|raw$) (result *$.type|raw$, err error) {
563+
func (c *$.type|privatePlural$) UpdateStatus(ctx context.Context, $.type|private$ *$.type|raw$, opts $.UpdateOptions|raw$) (result *$.type|raw$, err error) {
555564
result = &$.type|raw${}
556565
err = c.client.Put().
557566
$if .namespaced$Namespace(c.ns).$end$
558567
Resource("$.type|resource$").
559568
Name($.type|private$.Name).
560569
SubResource("status").
570+
VersionedParams(&opts, $.schemeParameterCodec|raw$).
561571
Body($.type|private$).
562572
Do(ctx).
563573
Into(result)
@@ -584,13 +594,14 @@ func (c *$.type|privatePlural$) Watch(ctx context.Context, opts $.ListOptions|ra
584594

585595
var patchTemplate = `
586596
// Patch applies the patch and returns the patched $.resultType|private$.
587-
func (c *$.type|privatePlural$) Patch(ctx context.Context, name string, pt $.PatchType|raw$, data []byte, subresources ...string) (result *$.resultType|raw$, err error) {
597+
func (c *$.type|privatePlural$) Patch(ctx context.Context, name string, pt $.PatchType|raw$, data []byte, opts $.PatchOptions|raw$, subresources ...string) (result *$.resultType|raw$, err error) {
588598
result = &$.resultType|raw${}
589599
err = c.client.Patch(pt).
590600
$if .namespaced$Namespace(c.ns).$end$
591601
Resource("$.type|resource$").
592-
SubResource(subresources...).
593602
Name(name).
603+
SubResource(subresources...).
604+
VersionedParams(&opts, $.schemeParameterCodec|raw$).
594605
Body(data).
595606
Do(ctx).
596607
Into(result)

0 commit comments

Comments
 (0)