Example #1
0
func getListWatch(kind string, getter cache.Getter, selector labels.Selector) *cache.ListWatch {
	return &cache.ListWatch{
		ListFunc: func(options api.ListOptions) (runtime.Object, error) {
			logger.Debugf("Running ListFunc for %q", kind)
			req := getter.Get().Namespace(api.NamespaceAll).Resource(kind).
				LabelsSelectorParam(selector).FieldsSelectorParam(fields.Everything())
			logger.Debugf("Request URL: %v", req.URL())
			obj, er := req.Do().Get()
			if er != nil {
				logger.Debugf("Got error: %v", er)
			}
			return obj, er
		},
		WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
			logger.Debugf("Running WatchFunc for %q", kind)
			req := getter.Get().Prefix("watch").Namespace(api.NamespaceAll).Resource(kind).
				LabelsSelectorParam(selector).FieldsSelectorParam(fields.Everything()).
				Param("resourceVersion", options.ResourceVersion)
			logger.Debugf("Request URL: %v", req.URL())
			w, er := req.Watch()
			if er != nil {
				logger.Debugf("Got error: %v", er)
			} else {
				logger.Debugf("Set watch for %q", kind)
			}
			return w, er
		},
	}
}
// copied (with slight modifications) from: k8s.io/kubernetes/pkg/client/cache NewListWatchFromClient
func newListWatchFromClient(c kubeCache.Getter, resource string, namespace string, labelSelector kubeLabels.Selector, fieldSelector kubeFields.Selector) *kubeCache.ListWatch {
	listFunc := func() (kubeRuntime.Object, error) {
		return c.Get().
			Namespace(namespace).
			Resource(resource).
			LabelsSelectorParam(labelSelector).
			FieldsSelectorParam(fieldSelector).
			Do().
			Get()
	}
	watchFunc := func(resourceVersion string) (kubeWatch.Interface, error) {
		return c.Get().
			Prefix("watch").
			Namespace(namespace).
			Resource(resource).
			LabelsSelectorParam(labelSelector).
			FieldsSelectorParam(fieldSelector).
			Param("resourceVersion", resourceVersion).
			Watch()
	}
	return &kubeCache.ListWatch{ListFunc: listFunc, WatchFunc: watchFunc}
}