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
f6659e45
Commit
f6659e45
authored
Aug 07, 2018
by
Ahmad Diaa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
further enhancements removing matchingTerms from metadata
parent
3fb6912d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
117 deletions
+102
-117
metadata.go
pkg/scheduler/algorithm/predicates/metadata.go
+38
-39
metadata_test.go
pkg/scheduler/algorithm/predicates/metadata_test.go
+16
-15
predicates.go
pkg/scheduler/algorithm/predicates/predicates.go
+48
-63
No files found.
pkg/scheduler/algorithm/predicates/metadata.go
View file @
f6659e45
...
...
@@ -38,6 +38,12 @@ type PredicateMetadataFactory struct {
podLister
algorithm
.
PodLister
}
// AntiAffinityTerm's topology key value used in predicate metadata
type
topologyPair
struct
{
key
string
value
string
}
// Note that predicateMetadata and matchingPodAntiAffinityTerm need to be declared in the same file
// due to the way declarations are processed in predicate declaration unit tests.
type
matchingPodAntiAffinityTerm
struct
{
...
...
@@ -52,11 +58,11 @@ type predicateMetadata struct {
podBestEffort
bool
podRequest
*
schedulercache
.
Resource
podPorts
[]
*
v1
.
ContainerPort
//key is a pod full name with the anti-affinity rules.
matchingAntiAffinityTerms
map
[
string
][]
matchingPodAntiAffinityTerm
// A map of antiffinity terms' topology ke values to the pods' names
// A map of antiffinity terms' topology pairs to the pods'
// that can potentially match the affinity rules of the pod
topologyValueToAntiAffinityPods
map
[
string
][]
string
topologyPairToAntiAffinityPods
map
[
topologyPair
][]
*
v1
.
Pod
// Reverse map for topologyPairToAntiAffinityPods to reduce deletion time
antiAffinityPodToTopologyPairs
map
[
string
][]
topologyPair
// A map of node name to a list of Pods on the node that can potentially match
// the affinity rules of the "pod".
nodeNameToMatchingAffinityPods
map
[
string
][]
*
v1
.
Pod
...
...
@@ -116,7 +122,7 @@ func (pfactory *PredicateMetadataFactory) GetMetadata(pod *v1.Pod, nodeNameToInf
if
pod
==
nil
{
return
nil
}
matchingTerms
,
topologyValues
,
err
:=
getMatchingAntiAffinityTerm
s
(
pod
,
nodeNameToInfoMap
)
podToTopolgyPair
,
topologyPairToPods
,
err
:=
getMatchingTopologyPair
s
(
pod
,
nodeNameToInfoMap
)
if
err
!=
nil
{
return
nil
}
...
...
@@ -130,10 +136,10 @@ func (pfactory *PredicateMetadataFactory) GetMetadata(pod *v1.Pod, nodeNameToInf
podBestEffort
:
isPodBestEffort
(
pod
),
podRequest
:
GetResourceRequest
(
pod
),
podPorts
:
schedutil
.
GetContainerPorts
(
pod
),
matchingAntiAffinityTerms
:
matchingTerms
,
nodeNameToMatchingAffinityPods
:
affinityPods
,
nodeNameToMatchingAntiAffinityPods
:
antiAffinityPods
,
topologyValueToAntiAffinityPods
:
topologyValues
,
topologyPairToAntiAffinityPods
:
topologyPairToPods
,
antiAffinityPodToTopologyPairs
:
podToTopolgyPair
,
}
for
predicateName
,
precomputeFunc
:=
range
predicateMetadataProducers
{
glog
.
V
(
10
)
.
Infof
(
"Precompute: %v"
,
predicateName
)
...
...
@@ -149,23 +155,22 @@ func (meta *predicateMetadata) RemovePod(deletedPod *v1.Pod) error {
if
deletedPodFullName
==
schedutil
.
GetPodFullName
(
meta
.
pod
)
{
return
fmt
.
Errorf
(
"deletedPod and meta.pod must not be the same"
)
}
// Delete pod from matching topology values map
for
_
,
term
:=
range
meta
.
matchingAntiAffinityTerms
[
deletedPodFullName
]
{
if
topologyValue
,
ok
:=
term
.
node
.
Labels
[
term
.
term
.
TopologyKey
];
ok
{
for
index
,
podName
:=
range
meta
.
topologyValueToAntiAffinityPods
[
topologyValue
]
{
if
podName
==
deletedPodFullName
{
podsList
:=
meta
.
topologyValueToAntiAffinityPods
[
topologyValue
]
meta
.
topologyValueToAntiAffinityPods
[
topologyValue
]
=
append
(
podsList
[
:
index
],
podsList
[
index
+
1
:
]
...
)
break
// Delete pod from matching topology pairs map
for
_
,
pair
:=
range
meta
.
antiAffinityPodToTopologyPairs
[
deletedPodFullName
]
{
for
index
,
pod
:=
range
meta
.
topologyPairToAntiAffinityPods
[
pair
]
{
if
schedutil
.
GetPodFullName
(
pod
)
==
deletedPodFullName
{
podsList
:=
meta
.
topologyPairToAntiAffinityPods
[
pair
]
podsList
[
index
]
=
podsList
[
len
(
podsList
)
-
1
]
if
len
(
podsList
)
<=
1
{
delete
(
meta
.
topologyPairToAntiAffinityPods
,
pair
)
}
else
{
meta
.
topologyPairToAntiAffinityPods
[
pair
]
=
podsList
[
:
len
(
podsList
)
-
1
]
}
break
}
}
}
// Delete any anti-affinity rule from the deletedPod.
delete
(
meta
.
matchingAntiAffinityTerms
,
deletedPodFullName
)
delete
(
meta
.
antiAffinityPodToTopologyPairs
,
deletedPodFullName
)
// Delete pod from the matching affinity or anti-affinity pods if exists.
affinity
:=
meta
.
pod
.
Spec
.
Affinity
podNodeName
:=
deletedPod
.
Spec
.
NodeName
...
...
@@ -222,21 +227,16 @@ func (meta *predicateMetadata) AddPod(addedPod *v1.Pod, nodeInfo *schedulercache
return
fmt
.
Errorf
(
"invalid node in nodeInfo"
)
}
// Add matching anti-affinity terms of the addedPod to the map.
podMatchingTerms
,
podTopologyValuesToMatchingPods
,
err
:=
getMatchingAntiAffinityTerm
sOfExistingPod
(
meta
.
pod
,
addedPod
,
nodeInfo
.
Node
())
matchingPodToTopologyPairs
,
podTopologyPairToMatchingPods
,
err
:=
getMatchingTopologyPair
sOfExistingPod
(
meta
.
pod
,
addedPod
,
nodeInfo
.
Node
())
if
err
!=
nil
{
return
err
}
if
len
(
podMatchingTerms
)
>
0
{
existingTerms
,
found
:=
meta
.
matchingAntiAffinityTerms
[
addedPodFullName
]
if
found
{
meta
.
matchingAntiAffinityTerms
[
addedPodFullName
]
=
append
(
existingTerms
,
podMatchingTerms
...
)
}
else
{
meta
.
matchingAntiAffinityTerms
[
addedPodFullName
]
=
podMatchingTerms
if
len
(
matchingPodToTopologyPairs
)
>
0
{
for
pair
,
pods
:=
range
podTopologyPairToMatchingPods
{
meta
.
topologyPairToAntiAffinityPods
[
pair
]
=
append
(
meta
.
topologyPairToAntiAffinityPods
[
pair
],
pods
...
)
}
for
topologyValue
,
pods
:=
range
podTopologyValuesToMatchingPods
{
meta
.
topologyValueToAntiAffinityPods
[
topologyValue
]
=
append
(
meta
.
topologyValueToAntiAffinityPods
[
topologyValue
],
pods
...
)
for
pod
,
pairs
:=
range
matchingPodToTopologyPairs
{
meta
.
antiAffinityPodToTopologyPairs
[
pod
]
=
append
(
meta
.
antiAffinityPodToTopologyPairs
[
pod
],
pairs
...
)
}
}
// Add the pod to nodeNameToMatchingAffinityPods and nodeNameToMatchingAntiAffinityPods if needed.
...
...
@@ -291,10 +291,6 @@ func (meta *predicateMetadata) ShallowCopy() algorithm.PredicateMetadata {
ignoredExtendedResources
:
meta
.
ignoredExtendedResources
,
}
newPredMeta
.
podPorts
=
append
([]
*
v1
.
ContainerPort
(
nil
),
meta
.
podPorts
...
)
newPredMeta
.
matchingAntiAffinityTerms
=
map
[
string
][]
matchingPodAntiAffinityTerm
{}
for
k
,
v
:=
range
meta
.
matchingAntiAffinityTerms
{
newPredMeta
.
matchingAntiAffinityTerms
[
k
]
=
append
([]
matchingPodAntiAffinityTerm
(
nil
),
v
...
)
}
newPredMeta
.
nodeNameToMatchingAffinityPods
=
make
(
map
[
string
][]
*
v1
.
Pod
)
for
k
,
v
:=
range
meta
.
nodeNameToMatchingAffinityPods
{
newPredMeta
.
nodeNameToMatchingAffinityPods
[
k
]
=
append
([]
*
v1
.
Pod
(
nil
),
v
...
)
...
...
@@ -303,15 +299,18 @@ func (meta *predicateMetadata) ShallowCopy() algorithm.PredicateMetadata {
for
k
,
v
:=
range
meta
.
nodeNameToMatchingAntiAffinityPods
{
newPredMeta
.
nodeNameToMatchingAntiAffinityPods
[
k
]
=
append
([]
*
v1
.
Pod
(
nil
),
v
...
)
}
newPredMeta
.
topologyValueToAntiAffinityPods
=
make
(
map
[
string
][]
string
)
for
k
,
v
:=
range
meta
.
topologyValueToAntiAffinityPods
{
newPredMeta
.
topologyValueToAntiAffinityPods
[
k
]
=
append
([]
string
(
nil
),
v
...
)
newPredMeta
.
topologyPairToAntiAffinityPods
=
make
(
map
[
topologyPair
][]
*
v1
.
Pod
)
for
k
,
v
:=
range
meta
.
topologyPairToAntiAffinityPods
{
newPredMeta
.
topologyPairToAntiAffinityPods
[
k
]
=
append
([]
*
v1
.
Pod
(
nil
),
v
...
)
}
newPredMeta
.
antiAffinityPodToTopologyPairs
=
make
(
map
[
string
][]
topologyPair
)
for
k
,
v
:=
range
meta
.
antiAffinityPodToTopologyPairs
{
newPredMeta
.
antiAffinityPodToTopologyPairs
[
k
]
=
append
([]
topologyPair
(
nil
),
v
...
)
}
newPredMeta
.
serviceAffinityMatchingPodServices
=
append
([]
*
v1
.
Service
(
nil
),
meta
.
serviceAffinityMatchingPodServices
...
)
newPredMeta
.
serviceAffinityMatchingPodList
=
append
([]
*
v1
.
Pod
(
nil
),
meta
.
serviceAffinityMatchingPodList
...
)
return
(
algorithm
.
PredicateMetadata
)(
newPredMeta
)
}
...
...
pkg/scheduler/algorithm/predicates/metadata_test.go
View file @
f6659e45
...
...
@@ -113,11 +113,6 @@ func predicateMetadataEquivalent(meta1, meta2 *predicateMetadata) error {
for
!
reflect
.
DeepEqual
(
meta1
.
podPorts
,
meta2
.
podPorts
)
{
return
fmt
.
Errorf
(
"podPorts are not equal"
)
}
sortAntiAffinityTerms
(
meta1
.
matchingAntiAffinityTerms
)
sortAntiAffinityTerms
(
meta2
.
matchingAntiAffinityTerms
)
if
!
reflect
.
DeepEqual
(
meta1
.
matchingAntiAffinityTerms
,
meta2
.
matchingAntiAffinityTerms
)
{
return
fmt
.
Errorf
(
"matchingAntiAffinityTerms are not euqal"
)
}
sortNodePodMap
(
meta1
.
nodeNameToMatchingAffinityPods
)
sortNodePodMap
(
meta2
.
nodeNameToMatchingAffinityPods
)
if
!
reflect
.
DeepEqual
(
meta1
.
nodeNameToMatchingAffinityPods
,
meta2
.
nodeNameToMatchingAffinityPods
)
{
...
...
@@ -465,19 +460,25 @@ func TestPredicateMetadata_ShallowCopy(t *testing.T) {
HostIP
:
"1.2.3.4"
,
},
},
matchingAntiAffinityTerms
:
map
[
string
][]
matchingPodAntiAffinityTerm
{
"term1"
:
{
{
term
:
&
v1
.
PodAffinityTerm
{
TopologyKey
:
"node"
},
node
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"machine1"
},
},
topologyPairToAntiAffinityPods
:
map
[
topologyPair
][]
*
v1
.
Pod
{
{
key
:
"name"
,
value
:
"machine1"
}
:
{
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"p2"
,
Labels
:
selector1
},
Spec
:
v1
.
PodSpec
{
NodeName
:
"nodeC"
},
},
},
{
key
:
"name"
,
value
:
"machine2"
}
:
{
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"p1"
,
Labels
:
selector1
},
Spec
:
v1
.
PodSpec
{
NodeName
:
"nodeA"
},
},
},
},
topologyValueToAntiAffinityPods
:
map
[
string
][]
string
{
"machine1"
:
{
"p1"
,
"p2"
},
"machine2"
:
{
"p3"
},
antiAffinityPodToTopologyPairs
:
map
[
string
][]
topologyPair
{
"p2"
:
{
topologyPair
{
key
:
"name"
,
value
:
"machine1"
},
},
"p1"
:
{
topologyPair
{
key
:
"name"
,
value
:
"machine2"
},
},
},
nodeNameToMatchingAffinityPods
:
map
[
string
][]
*
v1
.
Pod
{
"nodeA"
:
{
...
...
pkg/scheduler/algorithm/predicates/predicates.go
View file @
f6659e45
This diff is collapsed.
Click to expand it.
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