本文整理汇总了Golang中k8s/io/kubernetes/pkg/registry/generic.SelectionPredicate类的典型用法代码示例。如果您正苦于以下问题:Golang SelectionPredicate类的具体用法?Golang SelectionPredicate怎么用?Golang SelectionPredicate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SelectionPredicate类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: WatchPredicate
// WatchPredicate starts a watch for the items that m matches.
func (e *Store) WatchPredicate(ctx api.Context, m *generic.SelectionPredicate, resourceVersion string) (watch.Interface, error) {
filter := e.createFilter(m)
if name, ok := m.MatchesSingle(); ok {
if key, err := e.KeyFunc(ctx, name); err == nil {
if err != nil {
return nil, err
}
w, err := e.Storage.Watch(ctx, key, resourceVersion, filter)
if err != nil {
return nil, err
}
if e.Decorator != nil {
return newDecoratedWatcher(w, e.Decorator), nil
}
return w, nil
}
// if we cannot extract a key based on the current context, the optimization is skipped
}
w, err := e.Storage.WatchList(ctx, e.KeyRootFunc(ctx), resourceVersion, filter)
if err != nil {
return nil, err
}
if e.Decorator != nil {
return newDecoratedWatcher(w, e.Decorator), nil
}
return w, nil
}
示例2: createFilter
func (e *Store) createFilter(m *generic.SelectionPredicate) storage.Filter {
filterFunc := func(obj runtime.Object) bool {
matches, err := m.Matches(obj)
if err != nil {
glog.Errorf("unable to match watch: %v", err)
return false
}
return matches
}
return storage.NewSimpleFilter(filterFunc, m.MatcherIndex)
}
示例3: ListPredicate
// ListPredicate returns a list of all the items matching m.
func (e *Store) ListPredicate(ctx api.Context, m *generic.SelectionPredicate, options *api.ListOptions) (runtime.Object, error) {
list := e.NewListFunc()
filter := e.createFilter(m)
if name, ok := m.MatchesSingle(); ok {
if key, err := e.KeyFunc(ctx, name); err == nil {
err := e.Storage.GetToList(ctx, key, filter, list)
return list, storeerr.InterpretListError(err, e.QualifiedResource)
}
// if we cannot extract a key based on the current context, the optimization is skipped
}
if options == nil {
options = &api.ListOptions{ResourceVersion: "0"}
}
err := e.Storage.List(ctx, e.KeyRootFunc(ctx), options.ResourceVersion, filter, list)
return list, storeerr.InterpretListError(err, e.QualifiedResource)
}