Skip to content

Commit

Permalink
Incorporate n3wscott review nits
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmoor committed Aug 17, 2021
1 parent d440747 commit de9dcc3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 7 additions & 3 deletions codegen/cmd/injection-gen/generators/filtered_informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func (g *filteredInjectionGenerator) GenerateType(c *generator.Context, t *types
Package: "context",
Name: "Context",
}),
"contextWithValue": c.Universe.Function(types.Name{
Package: "context",
Name: "WithValue",
}),
"schemaGVR": c.Universe.Type(types.Name{
Package: "k8s.io/apimachinery/pkg/runtime/schema",
Name: "GroupVersionResource",
Expand Down Expand Up @@ -173,7 +177,7 @@ func withInformer(ctx {{.contextContext|raw}}) ({{.contextContext|raw}}, []{{.co
for _, selector := range labelSelectors {
f := {{.factoryGet|raw}}(ctx, selector)
inf := f.{{.group}}().{{.version}}().{{.type|publicPlural}}()
ctx = context.WithValue(ctx, Key{Selector: selector}, inf)
ctx = {{ .contextWithValue|raw }}(ctx, Key{Selector: selector}, inf)
infs = append(infs, inf.Informer())
}
return ctx, infs
Expand All @@ -188,7 +192,7 @@ func withDynamicInformer(ctx {{.contextContext|raw}}) {{.contextContext|raw}} {
labelSelectors := untyped.([]string)
for _, selector := range labelSelectors {
inf := &wrapper{client: {{ .clientGet|raw }}(ctx), selector: selector}
ctx = context.WithValue(ctx, Key{Selector: selector}, inf)
ctx = {{ .contextWithValue|raw }}(ctx, Key{Selector: selector}, inf)
}
return ctx
}
Expand All @@ -208,7 +212,7 @@ type wrapper struct {
{{ if .Namespaced }}
namespace string
{{ end }}
selector string
selector string
}
var _ {{.informersTypedInformer|raw}} = (*wrapper)(nil)
Expand Down
8 changes: 6 additions & 2 deletions codegen/cmd/injection-gen/generators/informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ func (g *injectionGenerator) GenerateType(c *generator.Context, t *types.Type, w
Package: "context",
Name: "Context",
}),
"contextWithValue": c.Universe.Function(types.Name{
Package: "context",
Name: "WithValue",
}),
"schemaGVR": c.Universe.Type(types.Name{
Package: "k8s.io/apimachinery/pkg/runtime/schema",
Name: "GroupVersionResource",
Expand Down Expand Up @@ -158,12 +162,12 @@ type Key struct{}
func withInformer(ctx {{.contextContext|raw}}) ({{.contextContext|raw}}, {{.controllerInformer|raw}}) {
f := {{.factoryGet|raw}}(ctx)
inf := f.{{.groupGoName}}().{{.versionGoName}}().{{.type|publicPlural}}()
return context.WithValue(ctx, Key{}, inf), inf.Informer()
return {{ .contextWithValue|raw }}(ctx, Key{}, inf), inf.Informer()
}
func withDynamicInformer(ctx {{.contextContext|raw}}) {{.contextContext|raw}} {
inf := &wrapper{client: {{ .clientGet|raw }}(ctx)}
return context.WithValue(ctx, Key{}, inf)
return {{ .contextWithValue|raw }}(ctx, Key{}, inf)
}
// Get extracts the typed informer from the context.
Expand Down

0 comments on commit de9dcc3

Please sign in to comment.