// ListResourceUsingInformerFunc returns a listing function based on the shared informer factory for the specified resource.
func ListResourceUsingInformerFunc(f informers.SharedInformerFactory, groupResource unversioned.GroupResource) ListFuncByNamespace {
	return func(namespace string, options api.ListOptions) ([]runtime.Object, error) {
		informer, err := f.ForResource(groupResource)
		if err != nil {
			return nil, err
		}
		return informer.Lister().ByNamespace(namespace).List(options.LabelSelector)
	}
}
// controllerFor returns a replenishment controller for the specified group resource.
func controllerFor(
	groupResource schema.GroupResource,
	f informers.SharedInformerFactory,
	handlerFuncs cache.ResourceEventHandlerFuncs) (cache.ControllerInterface, error) {
	genericInformer, err := f.ForResource(groupResource)
	if err != nil {
		return nil, err
	}
	informer := genericInformer.Informer()
	informer.AddEventHandler(handlerFuncs)
	return informer.GetController(), nil
}
示例#3
0
// ListResourceUsingInformerFunc returns a listing function based on the shared informer factory for the specified resource.
func ListResourceUsingInformerFunc(f informers.SharedInformerFactory, groupResource schema.GroupResource) ListFuncByNamespace {
	return func(namespace string, options v1.ListOptions) ([]runtime.Object, error) {
		labelSelector, err := labels.Parse(options.LabelSelector)
		if err != nil {
			return nil, err
		}
		informer, err := f.ForResource(groupResource)
		if err != nil {
			return nil, err
		}
		return informer.Lister().ByNamespace(namespace).List(labelSelector)
	}
}