Skip to content

Commit 7c03e37

Browse files
committed
client-gen: rework list and use CheckListFromCacheDataConsistencyIfRequested
1 parent 9e2075b commit 7c03e37

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
172172
"RESTClientInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Interface"}),
173173
"schemeParameterCodec": c.Universe.Variable(types.Name{Package: path.Join(g.clientsetPackage, "scheme"), Name: "ParameterCodec"}),
174174
"jsonMarshal": c.Universe.Type(types.Name{Package: "encoding/json", Name: "Marshal"}),
175+
"CheckListFromCacheDataConsistencyIfRequested": c.Universe.Function(types.Name{Package: "k8s.io/client-go/util/consistencydetector", Name: "CheckListFromCacheDataConsistencyIfRequested"}),
175176
}
176177

177178
if generateApply {
@@ -223,6 +224,7 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
223224
}
224225
if tags.HasVerb("list") {
225226
sw.Do(listTemplate, m)
227+
sw.Do(privateListTemplate, m)
226228
}
227229
if tags.HasVerb("watch") {
228230
sw.Do(watchTemplate, m)
@@ -298,6 +300,7 @@ func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w i
298300
sw.Do(adjustTemplate(e.VerbName, e.VerbType, listSubresourceTemplate), m)
299301
} else {
300302
sw.Do(adjustTemplate(e.VerbName, e.VerbType, listTemplate), m)
303+
sw.Do(adjustTemplate(e.VerbName, e.VerbType, privateListTemplate), m)
301304
}
302305
}
303306

@@ -459,6 +462,18 @@ func new$.type|publicPlural$(c *$.GroupGoName$$.Version$Client) *$.type|privateP
459462
var listTemplate = `
460463
// List takes label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
461464
func (c *$.type|privatePlural$) List(ctx context.Context, opts $.ListOptions|raw$) (result *$.resultType|raw$List, err error) {
465+
defer func() {
466+
if err == nil {
467+
$.CheckListFromCacheDataConsistencyIfRequested|raw$(ctx, "list request for $.type|resource$", c.list, opts, result)
468+
}
469+
}()
470+
return c.list(ctx, opts)
471+
}
472+
`
473+
474+
var privateListTemplate = `
475+
// list takes label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
476+
func (c *$.type|privatePlural$) list(ctx context.Context, opts $.ListOptions|raw$) (result *$.resultType|raw$List, err error) {
462477
var timeout time.Duration
463478
if opts.TimeoutSeconds != nil{
464479
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second

0 commit comments

Comments
 (0)