示例#1
0
func (r *HealthyRegistry) WatchMinions(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
	w, err := r.delegate.WatchMinions(ctx, label, field, resourceVersion)
	if err != nil {
		return nil, err
	}
	return watch.Filter(w, watch.FilterFunc(func(in watch.Event) (watch.Event, bool) {
		if node, ok := in.Object.(*api.Node); ok && node != nil {
			in.Object = r.checkMinion(node)
		}
		return in, true
	})), nil
}
示例#2
0
// Watch returns ReplicationController events via a watch.Interface.
// It implements apiserver.ResourceWatcher.
func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
	if !field.Empty() {
		return nil, fmt.Errorf("no field selector implemented for controllers")
	}
	incoming, err := rs.registry.WatchControllers(resourceVersion)
	if err != nil {
		return nil, err
	}
	return watch.Filter(incoming, func(e watch.Event) (watch.Event, bool) {
		repController := e.Object.(*api.ReplicationController)
		return e, label.Matches(labels.Set(repController.Labels))
	}), nil
}
示例#3
0
// Watch begins watching for new, changed, or deleted pods.
func (rs *RegistryStorage) Watch(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
	source, err := rs.registry.WatchPods(resourceVersion)
	if err != nil {
		return nil, err
	}
	return watch.Filter(source, func(e watch.Event) (watch.Event, bool) {
		pod := e.Object.(*api.Pod)
		fields := labels.Set{
			"ID": pod.ID,
			"DesiredState.Status": string(pod.CurrentState.Status),
			"DesiredState.Host":   pod.CurrentState.Host,
		}
		return e, label.Matches(labels.Set(pod.Labels)) && field.Matches(fields)
	}), nil
}
示例#4
0
// Watch returns ReplicationController events via a watch.Interface.
// It implements apiserver.ResourceWatcher.
func (rs *REST) Watch(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
	if !field.Empty() {
		return nil, fmt.Errorf("no field selector implemented for controllers")
	}
	incoming, err := rs.registry.WatchControllers(ctx, resourceVersion)
	if err != nil {
		return nil, err
	}
	// TODO(lavalamp): remove watch.Filter, which is broken. Implement consistent way of filtering.
	// TODO(lavalamp): this watch method needs a test.
	return watch.Filter(incoming, func(e watch.Event) (watch.Event, bool) {
		repController, ok := e.Object.(*api.ReplicationController)
		if !ok {
			// must be an error event-- pass it on
			return e, true
		}
		match := label.Matches(labels.Set(repController.Labels))
		if match {
			rs.fillCurrentState(ctx, repController)
		}
		return e, match
	}), nil
}