@@ -140,7 +140,8 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
140
140
"UpdateOptions" : c .Universe .Type (types.Name {Package : "k8s.io/apimachinery/pkg/apis/meta/v1" , Name : "UpdateOptions" }),
141
141
"ApplyOptions" : c .Universe .Type (types.Name {Package : "k8s.io/apimachinery/pkg/apis/meta/v1" , Name : "ApplyOptions" }),
142
142
"PatchType" : c .Universe .Type (types.Name {Package : "k8s.io/apimachinery/pkg/types" , Name : "PatchType" }),
143
- "jsonMarshal" : c .Universe .Type (types.Name {Package : "encoding/json" , Name : "Marshal" }),
143
+ "PatchOptions" : c .Universe .Type (types.Name {Package : "k8s.io/apimachinery/pkg/apis/meta/v1" , Name : "PatchOptions" }),
144
+ "jsonMarshal" : c .Universe .Function (types.Name {Package : "encoding/json" , Name : "Marshal" }),
144
145
"context" : c .Universe .Type (types.Name {Package : "context" , Name : "Context" }),
145
146
},
146
147
}
@@ -173,9 +174,12 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
173
174
"watchInterface" : c .Universe .Type (types.Name {Package : "k8s.io/apimachinery/pkg/watch" , Name : "Interface" }),
174
175
"RESTClientInterface" : c .Universe .Type (types.Name {Package : "k8s.io/client-go/rest" , Name : "Interface" }),
175
176
"schemeParameterCodec" : c .Universe .Variable (types.Name {Package : path .Join (g .clientsetPackage , "scheme" ), Name : "ParameterCodec" }),
176
- "jsonMarshal" : c .Universe .Type (types.Name {Package : "encoding/json" , Name : "Marshal" }),
177
- "fmtErrorf" : c .Universe .Type (types.Name {Package : "fmt" , Name : "Errorf" }),
177
+ "jsonMarshal" : c .Universe .Function (types.Name {Package : "encoding/json" , Name : "Marshal" }),
178
+ "fmtErrorf" : c .Universe .Function (types.Name {Package : "fmt" , Name : "Errorf" }),
179
+ "klogWarningf" : c .Universe .Function (types.Name {Package : "k8s.io/klog/v2" , Name : "Warningf" }),
178
180
"context" : c .Universe .Type (types.Name {Package : "context" , Name : "Context" }),
181
+ "timeDuration" : c .Universe .Type (types.Name {Package : "time" , Name : "Duration" }),
182
+ "timeSecond" : c .Universe .Type (types.Name {Package : "time" , Name : "Second" }),
179
183
"resourceVersionMatchNotOlderThan" : c .Universe .Type (types.Name {Package : "k8s.io/apimachinery/pkg/apis/meta/v1" , Name : "ResourceVersionMatchNotOlderThan" }),
180
184
"CheckListFromCacheDataConsistencyIfRequested" : c .Universe .Function (types.Name {Package : "k8s.io/client-go/util/consistencydetector" , Name : "CheckListFromCacheDataConsistencyIfRequested" }),
181
185
"CheckWatchListFromCacheDataConsistencyIfRequested" : c .Universe .Function (types.Name {Package : "k8s.io/client-go/util/consistencydetector" , Name : "CheckWatchListFromCacheDataConsistencyIfRequested" }),
@@ -580,14 +584,14 @@ var listTemplate = `
580
584
// $.verb$ takes label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
581
585
func (c *$.type|privatePlural$) $.verb$(ctx $.context|raw$, opts $.ListOptions|raw$) (*$.resultType|raw$List, error) {
582
586
if watchListOptions, hasWatchListOptionsPrepared, watchListOptionsErr := $.PrepareWatchListOptionsFromListOptions|raw$(opts); watchListOptionsErr != nil {
583
- klog.Warningf ("Failed preparing watchlist options for $.type|resource$, falling back to the standard LIST semantics, err = %v", watchListOptionsErr )
587
+ $.klogWarningf|raw$ ("Failed preparing watchlist options for $.type|resource$, falling back to the standard LIST semantics, err = %v", watchListOptionsErr )
584
588
} else if hasWatchListOptionsPrepared {
585
589
result, err := c.watchList(ctx, watchListOptions)
586
590
if err == nil {
587
591
$.CheckWatchListFromCacheDataConsistencyIfRequested|raw$(ctx, "watchlist request for $.type|resource$", c.list, opts, result)
588
592
return result, nil
589
593
}
590
- klog.Warningf ("The watchlist request for $.type|resource$ ended with an error, falling back to the standard LIST semantics, err = %v", err)
594
+ $.klogWarningf|raw$ ("The watchlist request for $.type|resource$ ended with an error, falling back to the standard LIST semantics, err = %v", err)
591
595
}
592
596
result, err := c.list(ctx, opts)
593
597
if err == nil {
@@ -600,9 +604,9 @@ func (c *$.type|privatePlural$) $.verb$(ctx $.context|raw$, opts $.ListOptions|r
600
604
var privateListTemplate = `
601
605
// list takes label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
602
606
func (c *$.type|privatePlural$) list(ctx $.context|raw$, opts $.ListOptions|raw$) (result *$.resultType|raw$List, err error) {
603
- var timeout time.Duration
607
+ var timeout $.timeDuration|raw$
604
608
if opts.TimeoutSeconds != nil{
605
- timeout = time.Duration (*opts.TimeoutSeconds) * time.Second
609
+ timeout = $.timeDuration|raw$ (*opts.TimeoutSeconds) * $.timeSecond|raw$
606
610
}
607
611
result = &$.resultType|raw$List{}
608
612
err = c.GetClient().Get().
@@ -619,9 +623,9 @@ func (c *$.type|privatePlural$) list(ctx $.context|raw$, opts $.ListOptions|raw$
619
623
var listSubresourceTemplate = `
620
624
// $.verb$ takes $.type|raw$ name, label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
621
625
func (c *$.type|privatePlural$) $.verb$(ctx $.context|raw$, $.type|private$Name string, opts $.ListOptions|raw$) (result *$.resultType|raw$List, err error) {
622
- var timeout time.Duration
626
+ var timeout $.timeDuration|raw$
623
627
if opts.TimeoutSeconds != nil{
624
- timeout = time.Duration (*opts.TimeoutSeconds) * time.Second
628
+ timeout = $.timeDuration|raw$ (*opts.TimeoutSeconds) * $.timeSecond|raw$
625
629
}
626
630
result = &$.resultType|raw$List{}
627
631
err = c.GetClient().Get().
@@ -749,9 +753,9 @@ func (c *$.type|privatePlural$) $.verb$(ctx $.context|raw$, $.inputType|private$
749
753
var watchTemplate = `
750
754
// $.verb$ returns a $.watchInterface|raw$ that watches the requested $.type|privatePlural$.
751
755
func (c *$.type|privatePlural$) $.verb$(ctx $.context|raw$, opts $.ListOptions|raw$) ($.watchInterface|raw$, error) {
752
- var timeout time.Duration
756
+ var timeout $.timeDuration|raw$
753
757
if opts.TimeoutSeconds != nil{
754
- timeout = time.Duration (*opts.TimeoutSeconds) * time.Second
758
+ timeout = $.timeDuration|raw$ (*opts.TimeoutSeconds) * $.timeSecond|raw$
755
759
}
756
760
opts.Watch = true
757
761
return c.GetClient().Get().
@@ -765,13 +769,13 @@ func (c *$.type|privatePlural$) $.verb$(ctx $.context|raw$, opts $.ListOptions|r
765
769
var watchListTemplate = `
766
770
// watchList establishes a watch stream with the server and returns the list of $.resultType|publicPlural$
767
771
func (c *$.type|privatePlural$) watchList(ctx $.context|raw$, opts $.ListOptions|raw$) (result *$.resultType|raw$List, err error) {
768
- var timeout time.Duration
772
+ var timeout $.timeDuration|raw$
769
773
if opts.TimeoutSeconds != nil{
770
- timeout = time.Duration (*opts.TimeoutSeconds) * time.Second
774
+ timeout = $.timeDuration|raw$ (*opts.TimeoutSeconds) * $.timeSecond|raw$
771
775
}
772
776
result = &$.resultType|raw$List{}
773
- err = c.client .Get().
774
- $if .namespaced$Namespace(c.ns ).$end$
777
+ err = c.GetClient() .Get().
778
+ $if .namespaced$Namespace(c.GetNamespace() ).$end$
775
779
Resource("$.type|resource$").
776
780
VersionedParams(&opts, $.schemeParameterCodec|raw$).
777
781
Timeout(timeout).
0 commit comments