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
e9d5be62
Commit
e9d5be62
authored
Aug 19, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't validate selector that is already validated
parent
42aee3ac
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
18 additions
and
20 deletions
+18
-20
listers.go
pkg/client/cache/listers.go
+3
-4
listers_test.go
pkg/client/cache/listers_test.go
+4
-4
controller_utils.go
pkg/controller/controller_utils.go
+1
-1
endpoints_controller.go
pkg/controller/endpoint/endpoints_controller.go
+1
-1
replica_set.go
pkg/controller/replicaset/replica_set.go
+1
-1
replication_controller.go
pkg/controller/replication/replication_controller.go
+5
-6
labels.go
pkg/labels/labels.go
+1
-1
listers.go
plugin/pkg/scheduler/algorithm/listers.go
+2
-2
No files found.
pkg/client/cache/listers.go
View file @
e9d5be62
...
...
@@ -269,11 +269,10 @@ func (s *StoreToReplicationControllerLister) GetPodControllers(pod *api.Pod) (co
for
_
,
m
:=
range
items
{
rc
=
*
m
.
(
*
api
.
ReplicationController
)
labelSet
:=
labels
.
Set
(
rc
.
Spec
.
Selector
)
selector
=
labels
.
Set
(
rc
.
Spec
.
Selector
)
.
AsSelector
()
selector
=
labels
.
Set
(
rc
.
Spec
.
Selector
)
.
AsSelectorPreValidated
()
// If an rc with a nil or empty selector creeps in, it should match nothing, not everything.
if
labelSet
.
AsSelector
()
.
Empty
()
||
!
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
if
selector
.
Empty
()
||
!
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
continue
}
controllers
=
append
(
controllers
,
rc
)
...
...
@@ -513,7 +512,7 @@ func (s *StoreToServiceLister) GetPodServices(pod *api.Pod) (services []api.Serv
// services with nil selectors match nothing, not everything.
continue
}
selector
=
labels
.
Set
(
service
.
Spec
.
Selector
)
.
AsSelector
()
selector
=
labels
.
Set
(
service
.
Spec
.
Selector
)
.
AsSelector
PreValidated
()
if
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
services
=
append
(
services
,
service
)
}
...
...
pkg/client/cache/listers_test.go
View file @
e9d5be62
...
...
@@ -143,7 +143,7 @@ func TestStoreToReplicationControllerLister(t *testing.T) {
},
},
list
:
func
(
lister
StoreToReplicationControllerLister
)
([]
api
.
ReplicationController
,
error
)
{
return
lister
.
ReplicationControllers
(
api
.
NamespaceAll
)
.
List
(
labels
.
Set
{}
.
AsSelector
())
return
lister
.
ReplicationControllers
(
api
.
NamespaceAll
)
.
List
(
labels
.
Set
{}
.
AsSelector
PreValidated
())
},
outRCNames
:
sets
.
NewString
(
"hmm"
,
"foo"
),
},
...
...
@@ -158,7 +158,7 @@ func TestStoreToReplicationControllerLister(t *testing.T) {
},
},
list
:
func
(
lister
StoreToReplicationControllerLister
)
([]
api
.
ReplicationController
,
error
)
{
return
lister
.
ReplicationControllers
(
"hmm"
)
.
List
(
labels
.
Set
{}
.
AsSelector
())
return
lister
.
ReplicationControllers
(
"hmm"
)
.
List
(
labels
.
Set
{}
.
AsSelector
PreValidated
())
},
outRCNames
:
sets
.
NewString
(
"hmm"
),
},
...
...
@@ -715,7 +715,7 @@ func TestStoreToPodLister(t *testing.T) {
spl
:=
StoreToPodLister
{
store
}
// Verify that we can always look up by Namespace.
defaultPods
,
err
:=
spl
.
Pods
(
api
.
NamespaceDefault
)
.
List
(
labels
.
Set
{}
.
AsSelector
())
defaultPods
,
err
:=
spl
.
Pods
(
api
.
NamespaceDefault
)
.
List
(
labels
.
Set
{}
.
AsSelector
PreValidated
())
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
}
else
if
e
,
a
:=
1
,
len
(
defaultPods
);
e
!=
a
{
...
...
@@ -725,7 +725,7 @@ func TestStoreToPodLister(t *testing.T) {
}
for
_
,
id
:=
range
ids
{
got
,
err
:=
spl
.
List
(
labels
.
Set
{
"name"
:
id
}
.
AsSelector
())
got
,
err
:=
spl
.
List
(
labels
.
Set
{
"name"
:
id
}
.
AsSelector
PreValidated
())
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
continue
...
...
pkg/controller/controller_utils.go
View file @
e9d5be62
...
...
@@ -472,7 +472,7 @@ func (r RealPodControl) createPods(nodeName, namespace string, template *api.Pod
if
len
(
nodeName
)
!=
0
{
pod
.
Spec
.
NodeName
=
nodeName
}
if
labels
.
Set
(
pod
.
Labels
)
.
AsSelector
()
.
Empty
()
{
if
labels
.
Set
(
pod
.
Labels
)
.
AsSelector
PreValidated
()
.
Empty
()
{
return
fmt
.
Errorf
(
"unable to create pods, no labels"
)
}
if
newPod
,
err
:=
r
.
KubeClient
.
Core
()
.
Pods
(
namespace
)
.
Create
(
pod
);
err
!=
nil
{
...
...
pkg/controller/endpoint/endpoints_controller.go
View file @
e9d5be62
...
...
@@ -358,7 +358,7 @@ func (e *EndpointController) syncService(key string) {
}
glog
.
V
(
5
)
.
Infof
(
"About to update endpoints for service %q"
,
key
)
pods
,
err
:=
e
.
podStore
.
Pods
(
service
.
Namespace
)
.
List
(
labels
.
Set
(
service
.
Spec
.
Selector
)
.
AsSelector
())
pods
,
err
:=
e
.
podStore
.
Pods
(
service
.
Namespace
)
.
List
(
labels
.
Set
(
service
.
Spec
.
Selector
)
.
AsSelector
PreValidated
())
if
err
!=
nil
{
// Since we're getting stuff from a local cache, it is
// basically impossible to get this error.
...
...
pkg/controller/replicaset/replica_set.go
View file @
e9d5be62
...
...
@@ -659,7 +659,7 @@ func (rsc *ReplicaSetController) syncReplicaSet(key string) error {
// part of the filteredPods.
fullyLabeledReplicasCount
:=
0
readyReplicasCount
:=
0
templateLabel
:=
labels
.
Set
(
rs
.
Spec
.
Template
.
Labels
)
.
AsSelector
()
templateLabel
:=
labels
.
Set
(
rs
.
Spec
.
Template
.
Labels
)
.
AsSelector
PreValidated
()
for
_
,
pod
:=
range
filteredPods
{
if
templateLabel
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
fullyLabeledReplicasCount
++
...
...
pkg/controller/replication/replication_controller.go
View file @
e9d5be62
...
...
@@ -291,11 +291,10 @@ func isControllerMatch(pod *api.Pod, rc *api.ReplicationController) bool {
if
rc
.
Namespace
!=
pod
.
Namespace
{
return
false
}
labelSet
:=
labels
.
Set
(
rc
.
Spec
.
Selector
)
selector
:=
labels
.
Set
(
rc
.
Spec
.
Selector
)
.
AsSelector
()
selector
:=
labels
.
Set
(
rc
.
Spec
.
Selector
)
.
AsSelectorPreValidated
()
// If an rc with a nil or empty selector creeps in, it should match nothing, not everything.
if
labelSet
.
AsSelector
()
.
Empty
()
||
!
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
if
selector
.
Empty
()
||
!
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
return
false
}
return
true
...
...
@@ -662,7 +661,7 @@ func (rm *ReplicationManager) syncReplicationController(key string) error {
rm
.
queue
.
Add
(
key
)
return
err
}
cm
:=
controller
.
NewPodControllerRefManager
(
rm
.
podControl
,
rc
.
ObjectMeta
,
labels
.
Set
(
rc
.
Spec
.
Selector
)
.
AsSelector
(),
getRCKind
())
cm
:=
controller
.
NewPodControllerRefManager
(
rm
.
podControl
,
rc
.
ObjectMeta
,
labels
.
Set
(
rc
.
Spec
.
Selector
)
.
AsSelector
PreValidated
(),
getRCKind
())
matchesAndControlled
,
matchesNeedsController
,
controlledDoesNotMatch
:=
cm
.
Classify
(
pods
)
for
_
,
pod
:=
range
matchesNeedsController
{
err
:=
cm
.
AdoptPod
(
pod
)
...
...
@@ -694,7 +693,7 @@ func (rm *ReplicationManager) syncReplicationController(key string) error {
return
aggregate
}
}
else
{
pods
,
err
:=
rm
.
podStore
.
Pods
(
rc
.
Namespace
)
.
List
(
labels
.
Set
(
rc
.
Spec
.
Selector
)
.
AsSelector
())
pods
,
err
:=
rm
.
podStore
.
Pods
(
rc
.
Namespace
)
.
List
(
labels
.
Set
(
rc
.
Spec
.
Selector
)
.
AsSelector
PreValidated
())
if
err
!=
nil
{
glog
.
Errorf
(
"Error getting pods for rc %q: %v"
,
key
,
err
)
rm
.
queue
.
Add
(
key
)
...
...
@@ -716,7 +715,7 @@ func (rm *ReplicationManager) syncReplicationController(key string) error {
// matching pods must be part of the filteredPods.
fullyLabeledReplicasCount
:=
0
readyReplicasCount
:=
0
templateLabel
:=
labels
.
Set
(
rc
.
Spec
.
Template
.
Labels
)
.
AsSelector
()
templateLabel
:=
labels
.
Set
(
rc
.
Spec
.
Template
.
Labels
)
.
AsSelector
PreValidated
()
for
_
,
pod
:=
range
filteredPods
{
if
templateLabel
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
fullyLabeledReplicasCount
++
...
...
pkg/labels/labels.go
View file @
e9d5be62
...
...
@@ -61,7 +61,7 @@ func (ls Set) AsSelector() Selector {
return
SelectorFromSet
(
ls
)
}
//
ValidatedAsSelector
converts labels into a selector, but
//
AsSelectorPreValidated
converts labels into a selector, but
// assumes that labels are already validated and thus don't
// preform any validation.
// According to our measurements this is significantly faster
...
...
plugin/pkg/scheduler/algorithm/listers.go
View file @
e9d5be62
...
...
@@ -85,7 +85,7 @@ func (f FakeServiceLister) GetPodServices(pod *api.Pod) (services []api.Service,
if
service
.
Namespace
!=
pod
.
Namespace
{
continue
}
selector
=
labels
.
Set
(
service
.
Spec
.
Selector
)
.
AsSelector
()
selector
=
labels
.
Set
(
service
.
Spec
.
Selector
)
.
AsSelector
PreValidated
()
if
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
services
=
append
(
services
,
service
)
}
...
...
@@ -134,7 +134,7 @@ func (f FakeControllerLister) GetPodControllers(pod *api.Pod) (controllers []api
if
controller
.
Namespace
!=
pod
.
Namespace
{
continue
}
selector
=
labels
.
Set
(
controller
.
Spec
.
Selector
)
.
AsSelector
()
selector
=
labels
.
Set
(
controller
.
Spec
.
Selector
)
.
AsSelector
PreValidated
()
if
selector
.
Matches
(
labels
.
Set
(
pod
.
Labels
))
{
controllers
=
append
(
controllers
,
controller
)
}
...
...
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