diff --git a/generator/controller_template.go b/generator/controller_template.go index 7e0fda9c..5fc32748 100644 --- a/generator/controller_template.go +++ b/generator/controller_template.go @@ -91,6 +91,7 @@ type {{.schema.CodeName}}Interface interface { Delete(name string, options *metav1.DeleteOptions) error DeleteNamespaced(namespace, name string, options *metav1.DeleteOptions) error List(opts metav1.ListOptions) (*{{.schema.CodeName}}List, error) + ListNamespaced(namespace string, opts metav1.ListOptions) (*{{.schema.CodeName}}List, error) Watch(opts metav1.ListOptions) (watch.Interface, error) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error Controller() {{.schema.CodeName}}Controller @@ -279,6 +280,11 @@ func (s *{{.schema.ID}}Client) List(opts metav1.ListOptions) (*{{.schema.CodeNam return obj.(*{{.schema.CodeName}}List), err } +func (s *{{.schema.ID}}Client) ListNamespaced(namespace string, opts metav1.ListOptions) (*{{.schema.CodeName}}List, error) { + obj, err := s.objectClient.ListNamespaced(namespace, opts) + return obj.(*{{.schema.CodeName}}List), err +} + func (s *{{.schema.ID}}Client) Watch(opts metav1.ListOptions) (watch.Interface, error) { return s.objectClient.Watch(opts) } diff --git a/objectclient/object_client.go b/objectclient/object_client.go index d3c21489..2798befc 100644 --- a/objectclient/object_client.go +++ b/objectclient/object_client.go @@ -48,6 +48,7 @@ type GenericClient interface { DeleteNamespaced(namespace, name string, opts *metav1.DeleteOptions) error Delete(name string, opts *metav1.DeleteOptions) error List(opts metav1.ListOptions) (runtime.Object, error) + ListNamespaced(namespace string, opts metav1.ListOptions) (runtime.Object, error) Watch(opts metav1.ListOptions) (watch.Interface, error) DeleteCollection(deleteOptions *metav1.DeleteOptions, listOptions metav1.ListOptions) error Patch(name string, o runtime.Object, patchType types.PatchType, data []byte, subresources ...string) (runtime.Object, error) @@ -228,6 +229,18 @@ func (p *ObjectClient) List(opts metav1.ListOptions) (runtime.Object, error) { Into(result) } +func (p *ObjectClient) ListNamespaced(namespace string, opts metav1.ListOptions) (runtime.Object, error) { + result := p.Factory.List() + logrus.Debugf("REST LIST %s/%s/%s/%s/%s", p.getAPIPrefix(), p.gvk.Group, p.gvk.Version, namespace, p.resource.Name) + return result, p.restClient.Get(). + Prefix(p.getAPIPrefix(), p.gvk.Group, p.gvk.Version). + NamespaceIfScoped(namespace, p.resource.Namespaced). + Resource(p.resource.Name). + VersionedParams(&opts, metav1.ParameterCodec). + Do(). + Into(result) +} + func (p *ObjectClient) Watch(opts metav1.ListOptions) (watch.Interface, error) { restClient := p.restClient if watchClient, ok := restClient.(restwatch.WatchClient); ok {