@@ -271,78 +271,72 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
271
271
m ["inputType" ] = & inputType
272
272
m ["resultType" ] = & resultType
273
273
m ["subresourcePath" ] = e .SubResourcePath
274
+ m ["verb" ] = e .VerbName
274
275
if e .HasVerb ("apply" ) {
275
276
m ["inputApplyConfig" ] = types .Ref (path .Join (g .applyConfigurationPackage , inputGVString ), inputType .Name .Name + "ApplyConfiguration" )
276
277
}
277
278
278
279
if e .HasVerb ("get" ) {
279
280
if e .IsSubresource () {
280
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , getSubresourceTemplate ) , m )
281
+ sw .Do (getSubresourceTemplate , m )
281
282
} else {
282
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , getTemplate ) , m )
283
+ sw .Do (getTemplate , m )
283
284
}
284
285
}
285
286
286
287
if e .HasVerb ("list" ) {
287
288
if e .IsSubresource () {
288
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , listSubresourceTemplate ) , m )
289
+ sw .Do (listSubresourceTemplate , m )
289
290
} else {
290
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , listTemplate ) , m )
291
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , privateListTemplate ) , m )
292
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , watchListTemplate ) , m )
291
+ sw .Do (listTemplate , m )
292
+ sw .Do (privateListTemplate , m )
293
+ sw .Do (watchListTemplate , m )
293
294
}
294
295
}
295
296
296
297
// TODO: Figure out schemantic for watching a sub-resource.
297
298
if e .HasVerb ("watch" ) {
298
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , watchTemplate ) , m )
299
+ sw .Do (watchTemplate , m )
299
300
}
300
301
301
302
if e .HasVerb ("create" ) {
302
303
if e .IsSubresource () {
303
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , createSubresourceTemplate ) , m )
304
+ sw .Do (createSubresourceTemplate , m )
304
305
} else {
305
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , createTemplate ) , m )
306
+ sw .Do (createTemplate , m )
306
307
}
307
308
}
308
309
309
310
if e .HasVerb ("update" ) {
310
311
if e .IsSubresource () {
311
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , updateSubresourceTemplate ) , m )
312
+ sw .Do (updateSubresourceTemplate , m )
312
313
} else {
313
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , updateTemplate ) , m )
314
+ sw .Do (updateTemplate , m )
314
315
}
315
316
}
316
317
317
318
// TODO: Figure out schemantic for deleting a sub-resource (what arguments
318
319
// are passed, does it need two names? etc.
319
320
if e .HasVerb ("delete" ) {
320
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , deleteTemplate ) , m )
321
+ sw .Do (deleteTemplate , m )
321
322
}
322
323
323
324
if e .HasVerb ("patch" ) {
324
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , patchTemplate ) , m )
325
+ sw .Do (patchTemplate , m )
325
326
}
326
327
327
328
if e .HasVerb ("apply" ) {
328
329
if e .IsSubresource () {
329
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , applySubresourceTemplate ) , m )
330
+ sw .Do (applySubresourceTemplate , m )
330
331
} else {
331
- sw .Do (adjustTemplate ( e . VerbName , e . VerbType , applyTemplate ) , m )
332
+ sw .Do (applyTemplate , m )
332
333
}
333
334
}
334
335
}
335
336
336
337
return sw .Error ()
337
338
}
338
339
339
- // adjustTemplate adjust the origin verb template using the expansion name.
340
- // TODO: Make the verbs in templates parametrized so the strings.Replace() is
341
- // not needed.
342
- func adjustTemplate (name , verbType , template string ) string {
343
- return strings .ReplaceAll (template , " " + titler .String (verbType ), " " + name )
344
- }
345
-
346
340
func generateInterface (defaultVerbTemplates map [string ]string , tags util.Tags ) string {
347
341
// need an ordered list here to guarantee order of generated methods.
348
342
out := []string {}
@@ -583,8 +577,8 @@ var newStruct = []string{
583
577
}
584
578
585
579
var listTemplate = `
586
- // List takes label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
587
- func (c *$.type|privatePlural$) List (ctx $.context|raw$, opts $.ListOptions|raw$) (*$.resultType|raw$List, error) {
580
+ // $.verb$ takes label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
581
+ func (c *$.type|privatePlural$) $.verb$ (ctx $.context|raw$, opts $.ListOptions|raw$) (*$.resultType|raw$List, error) {
588
582
if watchListOptions, hasWatchListOptionsPrepared, watchListOptionsErr := $.PrepareWatchListOptionsFromListOptions|raw$(opts); watchListOptionsErr != nil {
589
583
klog.Warningf("Failed preparing watchlist options for $.type|resource$, falling back to the standard LIST semantics, err = %v", watchListOptionsErr )
590
584
} else if hasWatchListOptionsPrepared {
@@ -623,8 +617,8 @@ func (c *$.type|privatePlural$) list(ctx $.context|raw$, opts $.ListOptions|raw$
623
617
`
624
618
625
619
var listSubresourceTemplate = `
626
- // List takes $.type|raw$ name, label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
627
- func (c *$.type|privatePlural$) List (ctx $.context|raw$, $.type|private$Name string, opts $.ListOptions|raw$) (result *$.resultType|raw$List, err error) {
620
+ // $.verb$ takes $.type|raw$ name, label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
621
+ func (c *$.type|privatePlural$) $.verb$ (ctx $.context|raw$, $.type|private$Name string, opts $.ListOptions|raw$) (result *$.resultType|raw$List, err error) {
628
622
var timeout time.Duration
629
623
if opts.TimeoutSeconds != nil{
630
624
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
@@ -644,8 +638,8 @@ func (c *$.type|privatePlural$) List(ctx $.context|raw$, $.type|private$Name str
644
638
`
645
639
646
640
var getTemplate = `
647
- // Get takes name of the $.type|private$, and returns the corresponding $.resultType|private$ object, and an error if there is any.
648
- func (c *$.type|privatePlural$) Get (ctx $.context|raw$, name string, options $.GetOptions|raw$) (result *$.resultType|raw$, err error) {
641
+ // $.verb$ takes name of the $.type|private$, and returns the corresponding $.resultType|private$ object, and an error if there is any.
642
+ func (c *$.type|privatePlural$) $.verb$ (ctx $.context|raw$, name string, options $.GetOptions|raw$) (result *$.resultType|raw$, err error) {
649
643
result = &$.resultType|raw${}
650
644
err = c.GetClient().Get().
651
645
$if .namespaced$Namespace(c.GetNamespace()).$end$
@@ -659,8 +653,8 @@ func (c *$.type|privatePlural$) Get(ctx $.context|raw$, name string, options $.G
659
653
`
660
654
661
655
var getSubresourceTemplate = `
662
- // Get takes name of the $.type|private$, and returns the corresponding $.resultType|raw$ object, and an error if there is any.
663
- func (c *$.type|privatePlural$) Get (ctx $.context|raw$, $.type|private$Name string, options $.GetOptions|raw$) (result *$.resultType|raw$, err error) {
656
+ // $.verb$ takes name of the $.type|private$, and returns the corresponding $.resultType|raw$ object, and an error if there is any.
657
+ func (c *$.type|privatePlural$) $.verb$ (ctx $.context|raw$, $.type|private$Name string, options $.GetOptions|raw$) (result *$.resultType|raw$, err error) {
664
658
result = &$.resultType|raw${}
665
659
err = c.GetClient().Get().
666
660
$if .namespaced$Namespace(c.GetNamespace()).$end$
@@ -675,8 +669,8 @@ func (c *$.type|privatePlural$) Get(ctx $.context|raw$, $.type|private$Name stri
675
669
`
676
670
677
671
var deleteTemplate = `
678
- // Delete takes name of the $.type|private$ and deletes it. Returns an error if one occurs.
679
- func (c *$.type|privatePlural$) Delete (ctx $.context|raw$, name string, opts $.DeleteOptions|raw$) error {
672
+ // $.verb$ takes name of the $.type|private$ and deletes it. Returns an error if one occurs.
673
+ func (c *$.type|privatePlural$) $.verb$ (ctx $.context|raw$, name string, opts $.DeleteOptions|raw$) error {
680
674
return c.GetClient().Delete().
681
675
$if .namespaced$Namespace(c.GetNamespace()).$end$
682
676
Resource("$.type|resource$").
@@ -688,8 +682,8 @@ func (c *$.type|privatePlural$) Delete(ctx $.context|raw$, name string, opts $.D
688
682
`
689
683
690
684
var createSubresourceTemplate = `
691
- // 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.
692
- func (c *$.type|privatePlural$) Create (ctx $.context|raw$, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (result *$.resultType|raw$, err error) {
685
+ // $.verb$ 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.
686
+ func (c *$.type|privatePlural$) $.verb$ (ctx $.context|raw$, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (result *$.resultType|raw$, err error) {
693
687
result = &$.resultType|raw${}
694
688
err = c.GetClient().Post().
695
689
$if .namespaced$Namespace(c.GetNamespace()).$end$
@@ -705,8 +699,8 @@ func (c *$.type|privatePlural$) Create(ctx $.context|raw$, $.type|private$Name s
705
699
`
706
700
707
701
var createTemplate = `
708
- // 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.
709
- func (c *$.type|privatePlural$) Create (ctx $.context|raw$, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (result *$.resultType|raw$, err error) {
702
+ // $.verb$ 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.
703
+ func (c *$.type|privatePlural$) $.verb$ (ctx $.context|raw$, $.inputType|private$ *$.inputType|raw$, opts $.CreateOptions|raw$) (result *$.resultType|raw$, err error) {
710
704
result = &$.resultType|raw${}
711
705
err = c.GetClient().Post().
712
706
$if .namespaced$Namespace(c.GetNamespace()).$end$
@@ -720,8 +714,8 @@ func (c *$.type|privatePlural$) Create(ctx $.context|raw$, $.inputType|private$
720
714
`
721
715
722
716
var updateSubresourceTemplate = `
723
- // 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.
724
- func (c *$.type|privatePlural$) Update (ctx $.context|raw$, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) {
717
+ // $.verb$ 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.
718
+ func (c *$.type|privatePlural$) $.verb$ (ctx $.context|raw$, $.type|private$Name string, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) {
725
719
result = &$.resultType|raw${}
726
720
err = c.GetClient().Put().
727
721
$if .namespaced$Namespace(c.GetNamespace()).$end$
@@ -737,8 +731,8 @@ func (c *$.type|privatePlural$) Update(ctx $.context|raw$, $.type|private$Name s
737
731
`
738
732
739
733
var updateTemplate = `
740
- // 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.
741
- func (c *$.type|privatePlural$) Update (ctx $.context|raw$, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) {
734
+ // $.verb$ 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.
735
+ func (c *$.type|privatePlural$) $.verb$ (ctx $.context|raw$, $.inputType|private$ *$.inputType|raw$, opts $.UpdateOptions|raw$) (result *$.resultType|raw$, err error) {
742
736
result = &$.resultType|raw${}
743
737
err = c.GetClient().Put().
744
738
$if .namespaced$Namespace(c.GetNamespace()).$end$
@@ -753,8 +747,8 @@ func (c *$.type|privatePlural$) Update(ctx $.context|raw$, $.inputType|private$
753
747
`
754
748
755
749
var watchTemplate = `
756
- // Watch returns a $.watchInterface|raw$ that watches the requested $.type|privatePlural$.
757
- func (c *$.type|privatePlural$) Watch (ctx $.context|raw$, opts $.ListOptions|raw$) ($.watchInterface|raw$, error) {
750
+ // $.verb$ returns a $.watchInterface|raw$ that watches the requested $.type|privatePlural$.
751
+ func (c *$.type|privatePlural$) $.verb$ (ctx $.context|raw$, opts $.ListOptions|raw$) ($.watchInterface|raw$, error) {
758
752
var timeout time.Duration
759
753
if opts.TimeoutSeconds != nil{
760
754
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
@@ -788,8 +782,8 @@ func (c *$.type|privatePlural$) watchList(ctx $.context|raw$, opts $.ListOptions
788
782
`
789
783
790
784
var patchTemplate = `
791
- // Patch applies the patch and returns the patched $.resultType|private$.
792
- func (c *$.type|privatePlural$) Patch (ctx $.context|raw$, name string, pt $.PatchType|raw$, data []byte, opts $.PatchOptions|raw$, subresources ...string) (result *$.resultType|raw$, err error) {
785
+ // $.verb$ applies the patch and returns the patched $.resultType|private$.
786
+ func (c *$.type|privatePlural$) $.verb$ (ctx $.context|raw$, name string, pt $.PatchType|raw$, data []byte, opts $.PatchOptions|raw$, subresources ...string) (result *$.resultType|raw$, err error) {
793
787
result = &$.resultType|raw${}
794
788
err = c.GetClient().Patch(pt).
795
789
$if .namespaced$Namespace(c.GetNamespace()).$end$
@@ -805,10 +799,10 @@ func (c *$.type|privatePlural$) Patch(ctx $.context|raw$, name string, pt $.Patc
805
799
`
806
800
807
801
var applyTemplate = `
808
- // Apply takes the given apply declarative configuration, applies it and returns the applied $.resultType|private$.
809
- func (c *$.type|privatePlural$) Apply (ctx $.context|raw$, $.inputType|private$ *$.inputApplyConfig|raw$, opts $.ApplyOptions|raw$) (result *$.resultType|raw$, err error) {
802
+ // $.verb$ takes the given apply declarative configuration, applies it and returns the applied $.resultType|private$.
803
+ func (c *$.type|privatePlural$) $.verb$ (ctx $.context|raw$, $.inputType|private$ *$.inputApplyConfig|raw$, opts $.ApplyOptions|raw$) (result *$.resultType|raw$, err error) {
810
804
if $.inputType|private$ == nil {
811
- return nil, $.fmtErrorf|raw$("$.inputType|private$ provided to Apply must not be nil")
805
+ return nil, $.fmtErrorf|raw$("$.inputType|private$ provided to $.verb$ must not be nil")
812
806
}
813
807
patchOpts := opts.ToPatchOptions()
814
808
data, err := $.jsonMarshal|raw$($.inputType|private$)
@@ -817,7 +811,7 @@ func (c *$.type|privatePlural$) Apply(ctx $.context|raw$, $.inputType|private$ *
817
811
}
818
812
name := $.inputType|private$.Name
819
813
if name == nil {
820
- return nil, $.fmtErrorf|raw$("$.inputType|private$.Name must be provided to Apply ")
814
+ return nil, $.fmtErrorf|raw$("$.inputType|private$.Name must be provided to $.verb$ ")
821
815
}
822
816
result = &$.resultType|raw${}
823
817
err = c.GetClient().Patch($.ApplyPatchType|raw$).
@@ -833,11 +827,11 @@ func (c *$.type|privatePlural$) Apply(ctx $.context|raw$, $.inputType|private$ *
833
827
`
834
828
835
829
var applySubresourceTemplate = `
836
- // Apply takes top resource name and the apply declarative configuration for $.subresourcePath$,
830
+ // $.verb$ takes top resource name and the apply declarative configuration for $.subresourcePath$,
837
831
// applies it and returns the applied $.resultType|private$, and an error, if there is any.
838
- func (c *$.type|privatePlural$) Apply (ctx $.context|raw$, $.type|private$Name string, $.inputType|private$ *$.inputApplyConfig|raw$, opts $.ApplyOptions|raw$) (result *$.resultType|raw$, err error) {
832
+ func (c *$.type|privatePlural$) $.verb$ (ctx $.context|raw$, $.type|private$Name string, $.inputType|private$ *$.inputApplyConfig|raw$, opts $.ApplyOptions|raw$) (result *$.resultType|raw$, err error) {
839
833
if $.inputType|private$ == nil {
840
- return nil, $.fmtErrorf|raw$("$.inputType|private$ provided to Apply must not be nil")
834
+ return nil, $.fmtErrorf|raw$("$.inputType|private$ provided to $.verb$ must not be nil")
841
835
}
842
836
patchOpts := opts.ToPatchOptions()
843
837
data, err := $.jsonMarshal|raw$($.inputType|private$)
0 commit comments