Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cache ListWatch field label selectors at opts
All instance for a same resources are being cached by controller-runtime, for some use cases this consumes a lot of memory and CPU. This change add a option to the cache so resources can be selected by field and label. Signed-off-by: Quique Llorente <ellorent@redhat.com>
- Loading branch information
Showing
5 changed files
with
75 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package selector | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/fields" | ||
"k8s.io/apimachinery/pkg/labels" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
// SelectorsByGroupResource associate a GroupResource to a field/label selector | ||
type SelectorsByGroupResource map[schema.GroupResource]Selector | ||
|
||
// Selector specify the label/field selector to fill in ListOptions | ||
type Selector struct { | ||
Label labels.Selector | ||
Field fields.Selector | ||
} | ||
|
||
// FillInListOpts fill in ListOptions LabelSelector and FieldSelector if needed | ||
func (s Selector) FillInListOpts(listOpts *metav1.ListOptions) { | ||
if s.Label != nil { | ||
listOpts.LabelSelector = s.Label.String() | ||
} | ||
if s.Field != nil { | ||
listOpts.FieldSelector = s.Field.String() | ||
} | ||
} | ||
|
||
// FindByGR use the GVR group and resource to find the field/label selector | ||
func (s SelectorsByGroupResource) FindByGR(gvr schema.GroupVersionResource) Selector { | ||
return s[schema.GroupResource{Group: gvr.Group, Resource: gvr.Resource}] | ||
} |