示例#1
0
// List obtains a list of Deployments that match selector.
func (s *storage) ListDeployments(ctx api.Context, label labels.Selector, field fields.Selector) (*experimental.DeploymentList, error) {
	if !field.Empty() {
		return nil, fmt.Errorf("field selector not supported yet")
	}
	obj, err := s.List(ctx, label, field)
	if err != nil {
		return nil, err
	}
	return obj.(*experimental.DeploymentList), err
}
示例#2
0
func (s *storage) ListJobs(ctx api.Context, label labels.Selector, field fields.Selector) (*extensions.JobList, error) {
	if !field.Empty() {
		return nil, fmt.Errorf("field selector not supported yet")
	}
	obj, err := s.List(ctx, label, field)
	if err != nil {
		return nil, err
	}
	return obj.(*extensions.JobList), err
}
示例#3
0
// List obtains a list of ReplicationControllers that match selector.
func (s *storage) ListControllers(ctx api.Context, label labels.Selector, field fields.Selector) (*api.ReplicationControllerList, error) {
	if !field.Empty() {
		return nil, fmt.Errorf("field selector not supported yet")
	}
	obj, err := s.List(ctx, label, field)
	if err != nil {
		return nil, err
	}
	return obj.(*api.ReplicationControllerList), err
}
示例#4
0
// MatchPod returns a generic matcher for a given label and field selector.
func MatchPod(label labels.Selector, field fields.Selector) generic.Matcher {
	return &generic.SelectionPredicate{
		Label: label,
		Field: field,
		GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) {
			pod, ok := obj.(*api.Pod)
			if !ok {
				return nil, nil, fmt.Errorf("not a pod")
			}

			// podLabels is already sitting there ready to be used.
			// podFields is not available directly and requires allocation of a map.
			// Only bother if the fields might be useful to determining the match.
			// One common case is for a replication controller to set up a watch
			// based on labels alone; in that case we can avoid allocating the field map.
			// This is especially important in the apiserver.
			podLabels := labels.Set(pod.ObjectMeta.Labels)
			var podFields fields.Set
			if !field.Empty() && label.Matches(podLabels) {
				podFields = PodToSelectableFields(pod)
			}
			return podLabels, podFields, nil
		},
		IndexFields: []string{"spec.nodeName"},
	}
}
示例#5
0
// FieldsSelectorParam adds the given selector as a query parameter with the name paramName.
func (r *Request) FieldsSelectorParam(s fields.Selector) *Request {
	if r.err != nil {
		return r
	}
	if s == nil {
		return r
	}
	if s.Empty() {
		return r
	}
	s2, err := s.Transform(func(field, value string) (newField, newValue string, err error) {
		return fieldMappings.filterField(r.content.GroupVersion, r.resource, field, value)
	})
	if err != nil {
		r.err = err
		return r
	}
	return r.setParam(unversioned.FieldSelectorQueryParam(r.content.GroupVersion.String()), s2.String())
}
示例#6
0
// WatchServices begins watching for new, changed, or deleted service configurations.
func (r *Registry) WatchServices(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
	version, err := storage.ParseWatchResourceVersion(resourceVersion, "service")
	if err != nil {
		return nil, err
	}
	if !label.Empty() {
		return nil, fmt.Errorf("label selectors are not supported on services")
	}
	if value, found := field.RequiresExactMatch("name"); found {
		key, err := makeServiceKey(ctx, value)
		if err != nil {
			return nil, err
		}
		// TODO: use generic.SelectionPredicate
		return r.Watch(key, version, storage.Everything)
	}
	if field.Empty() {
		return r.WatchList(makeServiceListKey(ctx), version, storage.Everything)
	}
	return nil, fmt.Errorf("only the 'name' and default (everything) field selectors are supported")
}
示例#7
0
文件: etcd.go 项目: Tlacenka/origin
// WatchRoutes begins watching for new, changed, or deleted route configurations.
func (registry *Etcd) WatchRoutes(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
	if !label.Empty() {
		return nil, fmt.Errorf("label selectors are not supported on routes yet")
	}

	version, err := storage.ParseWatchResourceVersion(resourceVersion, "pod")
	if err != nil {
		return nil, err
	}

	if value, found := field.RequiresExactMatch("ID"); found {
		key, err := makeRouteKey(ctx, value)
		if err != nil {
			return nil, err
		}
		return registry.Watch(key, version, storage.Everything)
	}

	if field.Empty() {
		key := kubeetcd.MakeEtcdListKey(ctx, RoutePath)
		return registry.WatchList(key, version, storage.Everything)
	}
	return nil, fmt.Errorf("only the 'ID' and default (everything) field selectors are supported")
}
// MatchEndpoints returns a generic matcher for a given label and field selector.
func MatchEndpoints(label labels.Selector, field fields.Selector) pkgstorage.SelectionPredicate {
	return pkgstorage.SelectionPredicate{
		Label: label,
		Field: field,
		GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) {
			endpoints, ok := obj.(*api.Endpoints)
			if !ok {
				return nil, nil, fmt.Errorf("invalid object type %#v", obj)
			}

			// Compute fields only if field selectors is non-empty
			// (otherwise those won't be used).
			// Those are generally also not needed if label selector does
			// not match labels, but additional computation of it is expensive.
			var endpointsFields fields.Set
			if !field.Empty() {
				endpointsFields = EndpointsToSelectableFields(endpoints)
			}
			return endpoints.Labels, endpointsFields, nil
		},
	}
}
示例#9
0
// MatchNode returns a generic matcher for a given label and field selector.
func MatchNode(label labels.Selector, field fields.Selector) pkgstorage.SelectionPredicate {
	return pkgstorage.SelectionPredicate{
		Label: label,
		Field: field,
		GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) {
			nodeObj, ok := obj.(*api.Node)
			if !ok {
				return nil, nil, fmt.Errorf("not a node")
			}

			// Compute fields only if field selectors is non-empty
			// (otherwise those won't be used).
			// Those are generally also not needed if label selector does
			// not match labels, but additional computation of it is expensive.
			var nodeFields fields.Set
			if !field.Empty() {
				nodeFields = NodeToSelectableFields(nodeObj)
			}
			return labels.Set(nodeObj.ObjectMeta.Labels), nodeFields, nil
		},
		IndexFields: []string{"metadata.name"},
	}
}
// MatchPod returns a generic matcher for a given label and field selector.
func MatchPod(label labels.Selector, field fields.Selector) storage.SelectionPredicate {
	return storage.SelectionPredicate{
		Label: label,
		Field: field,
		GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) {
			pod, ok := obj.(*api.Pod)
			if !ok {
				return nil, nil, fmt.Errorf("not a pod")
			}

			// Compute fields only if field selectors is non-empty
			// (otherwise those won't be used).
			// Those are generally also not needed if label selector does
			// not match labels, but additional computation of it is expensive.
			var podFields fields.Set
			if !field.Empty() {
				podFields = PodToSelectableFields(pod)
			}
			return labels.Set(pod.ObjectMeta.Labels), podFields, nil
		},
		IndexFields: []string{"spec.nodeName"},
	}
}
示例#11
0
文件: etcd.go 项目: ncantor/origin
// Watch begins watching for new, changed, or deleted images.
func (r *REST) Watch(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
	if !field.Empty() {
		return nil, errors.New("field selectors are not supported on images")
	}
	return r.store.WatchPredicate(ctx, image.MatchImage(label, field), resourceVersion)
}