本文整理匯總了Golang中github.com/GoogleCloudPlatform/kubernetes/pkg/labels.Selector.Empty方法的典型用法代碼示例。如果您正苦於以下問題:Golang Selector.Empty方法的具體用法?Golang Selector.Empty怎麽用?Golang Selector.Empty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/GoogleCloudPlatform/kubernetes/pkg/labels.Selector
的用法示例。
在下文中一共展示了Selector.Empty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ListPods
// ListPods obtains a list of pods that match selector.
func (k *KubernetesScheduler) ListPods(selector labels.Selector) ([]api.Pod, error) {
log.V(2).Infof("List pods for '%v'\n", selector)
k.RLock()
defer k.RUnlock()
var result []api.Pod
for _, task := range k.runningTasks {
pod := *(task.Pod)
var l labels.Set = pod.Labels
if selector.Matches(l) || selector.Empty() {
result = append(result, *(task.Pod))
}
}
// TODO(nnielsen): Refactor tasks append for the three lists.
for _, task := range k.pendingTasks {
pod := *(task.Pod)
var l labels.Set = pod.Labels
if selector.Matches(l) || selector.Empty() {
result = append(result, *(task.Pod))
}
}
// TODO(nnielsen): Wire up check in finished tasks
log.V(2).Infof("Returning pods: '%v'\n", result)
return result, nil
}
示例2: WatchControllers
// WatchControllers begins watching for new, changed, or deleted controllers.
func (registry *EtcdRegistry) WatchControllers(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
if !field.Empty() {
return nil, fmt.Errorf("no field selector implemented for controllers")
}
return registry.helper.WatchList("/registry/controllers", resourceVersion, func(obj interface{}) bool {
return label.Matches(labels.Set(obj.(*api.ReplicationController).Labels))
})
}
示例3: SelectorParam
// SelectorParam adds the given selector as a query parameter with the name paramName.
func (r *Request) SelectorParam(paramName string, s labels.Selector) *Request {
if r.err != nil {
return r
}
if s.Empty() {
return r
}
return r.setParam(paramName, s.String())
}
示例4: LabelsSelectorParam
// LabelsSelectorParam adds the given selector as a query parameter
func (r *Request) LabelsSelectorParam(s labels.Selector) *Request {
if r.err != nil {
return r
}
if s.Empty() {
return r
}
return r.setParam(api.LabelSelectorQueryParam(r.apiVersion), s.String())
}
示例5: WatchEndpoints
// WatchEndpoints begins watching for new, changed, or deleted endpoint configurations.
func (r *Registry) WatchEndpoints(label, field labels.Selector, resourceVersion uint64) (watch.Interface, error) {
if !label.Empty() {
return nil, fmt.Errorf("label selectors are not supported on endpoints")
}
if value, found := field.RequiresExactMatch("ID"); found {
return r.Watch(makeServiceEndpointsKey(value), resourceVersion)
}
if field.Empty() {
return r.WatchList("/registry/services/endpoints", resourceVersion, tools.Everything)
}
return nil, fmt.Errorf("only the 'ID' and default (everything) field selectors are supported")
}
示例6: Watch
// 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
}
示例7: List
func (a cachedServiceNamespacer) List(label labels.Selector) (*api.ServiceList, error) {
if !label.Empty() {
return nil, fmt.Errorf("label selection on the cache is not currently implemented")
}
items, err := a.accessor.store.Index("namespace", &api.Service{ObjectMeta: api.ObjectMeta{Namespace: a.namespace}})
if err != nil {
return nil, err
}
services := make([]api.Service, 0, len(items))
for i := range items {
services = append(services, *items[i].(*api.Service))
}
return &api.ServiceList{
// TODO: set ResourceVersion so that we can make watch work.
Items: services,
}, nil
}
示例8: List
// List obtains a list of ReplicationControllers that match selector.
func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Object, error) {
if !field.Empty() {
return nil, fmt.Errorf("field selector not supported yet")
}
controllers, err := rs.registry.ListControllers(ctx)
if err != nil {
return nil, err
}
filtered := []api.ReplicationController{}
for _, controller := range controllers.Items {
if label.Matches(labels.Set(controller.Labels)) {
rs.fillCurrentState(ctx, &controller)
filtered = append(filtered, controller)
}
}
controllers.Items = filtered
return controllers, err
}
示例9: WatchEndpoints
// WatchEndpoints begins watching for new, changed, or deleted endpoint configurations.
func (r *Registry) WatchEndpoints(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
version, err := tools.ParseWatchResourceVersion(resourceVersion, "endpoints")
if err != nil {
return nil, err
}
if !label.Empty() {
return nil, fmt.Errorf("label selectors are not supported on endpoints")
}
if value, found := field.RequiresExactMatch("name"); found {
key, err := makeServiceEndpointsKey(ctx, value)
if err != nil {
return nil, err
}
return r.Watch(key, version), nil
}
if field.Empty() {
return r.WatchList(makeServiceEndpointsListKey(ctx), version, tools.Everything)
}
return nil, fmt.Errorf("only the 'ID' and default (everything) field selectors are supported")
}
示例10: WatchServices
// 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")
}
示例11: Watch
// 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
}
示例12: WatchControllers
// WatchControllers begins watching for new, changed, or deleted controllers.
func (r *Registry) WatchControllers(ctx api.Context, label, field labels.Selector, resourceVersion string) (watch.Interface, error) {
if !field.Empty() {
return nil, fmt.Errorf("field selectors are not supported on replication controllers")
}
version, err := tools.ParseWatchResourceVersion(resourceVersion, "replicationControllers")
if err != nil {
return nil, err
}
key := makeControllerListKey(ctx)
return r.WatchList(key, version, func(obj runtime.Object) bool {
controller, ok := obj.(*api.ReplicationController)
if !ok {
// Must be an error: return true to propagate to upper level.
return true
}
match := label.Matches(labels.Set(controller.Labels))
if match {
pods, _ := r.ListPods(ctx, labels.Set(controller.Spec.Selector).AsSelector())
controller.Status.Replicas = len(pods.Items)
}
return match
})
}
示例13: WatchRoutes
// 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")
}
示例14: List
// List satisfies the RESTStorage interface.
func (rs *REST) List(ctx api.Context, label, field labels.Selector) (runtime.Object, error) {
if !label.Empty() || !field.Empty() {
return nil, errors.NewBadRequest("label/field selectors are not supported on endpoints")
}
return rs.registry.ListEndpoints(ctx)
}
示例15: List
// List satisfies the RESTStorage interface.
func (rs *Storage) List(selector labels.Selector) (interface{}, error) {
if !selector.Empty() {
return nil, errors.New("label selectors are not supported on endpoints")
}
return rs.registry.ListEndpoints()
}