Skip to content

Commit

Permalink
Merge pull request #384 from ibuildthecloud/master
Browse files Browse the repository at this point in the history
Ensure namespaced scoped listers default to the correct namespace
  • Loading branch information
ibuildthecloud authored Aug 27, 2020
2 parents e3b087c + 1f8e537 commit aae987b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions generator/controller_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,14 @@ type {{.schema.CodeName}}Interface interface {
}
type {{.schema.ID}}Lister struct {
ns string
controller *{{.schema.ID}}Controller
}
func (l *{{.schema.ID}}Lister) List(namespace string, selector labels.Selector) (ret []*{{.prefix}}{{.schema.CodeName}}, err error) {
if namespace == "" {
namespace = l.ns
}
err = cache.ListAllByNamespace(l.controller.Informer().GetIndexer(), namespace, selector, func(obj interface{}) {
ret = append(ret, obj.(*{{.prefix}}{{.schema.CodeName}}))
})
Expand Down Expand Up @@ -142,6 +146,7 @@ func (l *{{.schema.ID}}Lister) Get(namespace, name string) (*{{.prefix}}{{.schem
}
type {{.schema.ID}}Controller struct {
ns string
controller.GenericController
}
Expand All @@ -151,6 +156,7 @@ func (c *{{.schema.ID}}Controller) Generic() controller.GenericController {
func (c *{{.schema.ID}}Controller) Lister() {{.schema.CodeName}}Lister {
return &{{.schema.ID}}Lister{
ns: c.ns,
controller: c,
}
}
Expand Down Expand Up @@ -224,6 +230,7 @@ func (s *{{.schema.ID}}Client) Controller() {{.schema.CodeName}}Controller {
s.client.controllerFactory.ForResourceKind({{.schema.CodeName}}GroupVersionResource, {{.schema.CodeName}}GroupVersionKind.Kind, {{.schema | namespaced}}))
return &{{.schema.ID}}Controller{
ns: s.ns,
GenericController: genericController,
}
}
Expand Down

0 comments on commit aae987b

Please sign in to comment.