Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
dbafff3e
Commit
dbafff3e
authored
Jun 06, 2017
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Optimize selector for single-matching items"
This reverts commit
f93a270e
.
parent
4a01f44b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
38 deletions
+3
-38
store.go
...c/k8s.io/apiserver/pkg/registry/generic/registry/store.go
+1
-10
selection_predicate.go
...g/src/k8s.io/apiserver/pkg/storage/selection_predicate.go
+2
-28
No files found.
staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go
View file @
dbafff3e
...
@@ -1135,16 +1135,7 @@ func (e *Store) Watch(ctx genericapirequest.Context, options *metainternalversio
...
@@ -1135,16 +1135,7 @@ func (e *Store) Watch(ctx genericapirequest.Context, options *metainternalversio
func
(
e
*
Store
)
WatchPredicate
(
ctx
genericapirequest
.
Context
,
p
storage
.
SelectionPredicate
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
func
(
e
*
Store
)
WatchPredicate
(
ctx
genericapirequest
.
Context
,
p
storage
.
SelectionPredicate
,
resourceVersion
string
)
(
watch
.
Interface
,
error
)
{
if
name
,
ok
:=
p
.
MatchesSingle
();
ok
{
if
name
,
ok
:=
p
.
MatchesSingle
();
ok
{
if
key
,
err
:=
e
.
KeyFunc
(
ctx
,
name
);
err
==
nil
{
if
key
,
err
:=
e
.
KeyFunc
(
ctx
,
name
);
err
==
nil
{
// For performance reasons, we can optimize the further computations of
w
,
err
:=
e
.
Storage
.
Watch
(
ctx
,
key
,
resourceVersion
,
p
)
// selector, by removing then "matches-single" fields, because they are
// already satisfied by choosing appropriate key.
sp
,
err
:=
p
.
RemoveMatchesSingleRequirements
()
if
err
!=
nil
{
glog
.
Warningf
(
"Couldn't remove matches-single requirements: %v"
,
err
)
// Since we couldn't optimize selector, reset to the original one.
sp
=
p
}
w
,
err
:=
e
.
Storage
.
Watch
(
ctx
,
key
,
resourceVersion
,
sp
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
staging/src/k8s.io/apiserver/pkg/storage/selection_predicate.go
View file @
dbafff3e
...
@@ -72,42 +72,16 @@ func (s *SelectionPredicate) MatchesObjectAttributes(l labels.Set, f fields.Set,
...
@@ -72,42 +72,16 @@ func (s *SelectionPredicate) MatchesObjectAttributes(l labels.Set, f fields.Set,
return
matched
return
matched
}
}
const
matchesSingleField
=
"metadata.name"
func
removeMatchesSingleField
(
field
,
value
string
)
(
string
,
string
,
error
)
{
if
field
==
matchesSingleField
{
return
""
,
""
,
nil
}
return
field
,
value
,
nil
}
// MatchesSingle will return (name, true) if and only if s.Field matches on the object's
// MatchesSingle will return (name, true) if and only if s.Field matches on the object's
// name.
// name.
func
(
s
*
SelectionPredicate
)
MatchesSingle
()
(
string
,
bool
)
{
func
(
s
*
SelectionPredicate
)
MatchesSingle
()
(
string
,
bool
)
{
if
name
,
ok
:=
s
.
Field
.
RequiresExactMatch
(
matchesSingleField
);
ok
{
// TODO: should be namespace.name
if
name
,
ok
:=
s
.
Field
.
RequiresExactMatch
(
"metadata.name"
);
ok
{
return
name
,
true
return
name
,
true
}
}
return
""
,
false
return
""
,
false
}
}
func
(
s
*
SelectionPredicate
)
RemoveMatchesSingleRequirements
()
(
SelectionPredicate
,
error
)
{
var
fieldsSelector
fields
.
Selector
if
s
.
Field
!=
nil
{
var
err
error
fieldsSelector
,
err
=
s
.
Field
.
Transform
(
removeMatchesSingleField
)
if
err
!=
nil
{
return
SelectionPredicate
{},
err
}
}
return
SelectionPredicate
{
Label
:
s
.
Label
,
Field
:
fieldsSelector
,
IncludeUninitialized
:
s
.
IncludeUninitialized
,
GetAttrs
:
s
.
GetAttrs
,
IndexFields
:
s
.
IndexFields
,
},
nil
}
// For any index defined by IndexFields, if a matcher can match only (a subset)
// For any index defined by IndexFields, if a matcher can match only (a subset)
// of objects that return <value> for a given index, a pair (<index name>, <value>)
// of objects that return <value> for a given index, a pair (<index name>, <value>)
// wil be returned.
// wil be returned.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment