Cache fields for filtering in watchCache.

This commit is contained in:
Wojciech Tyczynski
2016-11-16 10:19:55 +01:00
parent e6c57c6569
commit 36e6cd19e1
78 changed files with 558 additions and 362 deletions

View File

@@ -43,6 +43,7 @@ func NewREST(opts generic.RESTOptions) *REST {
prefix,
configmap.Strategy,
newListFunc,
configmap.GetAttrs,
storage.NoTriggerPublisher)
store := &registry.Store{

View File

@@ -88,18 +88,20 @@ func ConfigMapToSelectableFields(cfg *api.ConfigMap) fields.Set {
return generic.ObjectMetaFieldsSet(&cfg.ObjectMeta, true)
}
// GetAttrs returns labels and fields of a given object for filtering purposes.
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
cfg, ok := obj.(*api.ConfigMap)
if !ok {
return nil, nil, fmt.Errorf("given object is not a ConfigMap")
}
return labels.Set(cfg.ObjectMeta.Labels), ConfigMapToSelectableFields(cfg), nil
}
// MatchConfigMap returns a generic matcher for a given label and field selector.
func MatchConfigMap(label labels.Selector, field fields.Selector) apistorage.SelectionPredicate {
return apistorage.SelectionPredicate{
Label: label,
Field: field,
GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) {
cfg, ok := obj.(*api.ConfigMap)
if !ok {
return nil, nil, fmt.Errorf("given object is not a ConfigMap")
}
return labels.Set(cfg.ObjectMeta.Labels), ConfigMapToSelectableFields(cfg), nil
},
Label: label,
Field: field,
GetAttrs: GetAttrs,
}
}