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
e58d3dbf
Commit
e58d3dbf
authored
Apr 11, 2017
by
Kubernetes Submit Queue
Committed by
GitHub
Apr 11, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #40800 from k82cn/topology_compare
Automatic merge from submit-queue Empty label is equal for topologies. fixes #40799
parents
2fa1eb06
f88ebfad
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
150 additions
and
1 deletion
+150
-1
BUILD
plugin/pkg/scheduler/algorithm/priorities/util/BUILD
+12
-0
topologies.go
plugin/pkg/scheduler/algorithm/priorities/util/topologies.go
+14
-1
topologies_test.go
...kg/scheduler/algorithm/priorities/util/topologies_test.go
+124
-0
No files found.
plugin/pkg/scheduler/algorithm/priorities/util/BUILD
View file @
e58d3dbf
...
...
@@ -5,6 +5,7 @@ licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
...
...
@@ -37,3 +38,14 @@ filegroup(
srcs = [":package-srcs"],
tags = ["automanaged"],
)
go_test(
name = "go_default_test",
srcs = ["topologies_test.go"],
library = ":go_default_library",
tags = ["automanaged"],
deps = [
"//pkg/api/v1:go_default_library",
"//vendor:k8s.io/apimachinery/pkg/apis/meta/v1",
],
)
plugin/pkg/scheduler/algorithm/priorities/util/topologies.go
View file @
e58d3dbf
...
...
@@ -56,7 +56,20 @@ func NodesHaveSameTopologyKey(nodeA, nodeB *v1.Node, topologyKey string) bool {
if
len
(
topologyKey
)
==
0
{
return
false
}
return
nodeA
.
Labels
!=
nil
&&
nodeB
.
Labels
!=
nil
&&
len
(
nodeA
.
Labels
[
topologyKey
])
>
0
&&
nodeA
.
Labels
[
topologyKey
]
==
nodeB
.
Labels
[
topologyKey
]
if
nodeA
.
Labels
==
nil
||
nodeB
.
Labels
==
nil
{
return
false
}
nodeALabel
,
okA
:=
nodeA
.
Labels
[
topologyKey
]
nodeBLabel
,
okB
:=
nodeB
.
Labels
[
topologyKey
]
// If found label in both nodes, check the label
if
okB
&&
okA
{
return
nodeALabel
==
nodeBLabel
}
return
false
}
type
Topologies
struct
{
...
...
plugin/pkg/scheduler/algorithm/priorities/util/topologies_test.go
0 → 100644
View file @
e58d3dbf
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
util
import
(
"testing"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/api/v1"
)
func
TestNodesHaveSameTopologyKey
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
name
string
nodeA
,
nodeB
*
v1
.
Node
topologyKey
string
expected
bool
}{
{
name
:
"nodeA{'a':'a'} vs. empty label in nodeB"
,
nodeA
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"a"
:
"a"
,
},
},
},
nodeB
:
&
v1
.
Node
{},
expected
:
false
,
topologyKey
:
"a"
,
},
{
name
:
"nodeA{'a':'a'} vs. nodeB{'a':'a'}"
,
nodeA
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"a"
:
"a"
,
},
},
},
nodeB
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"a"
:
"a"
,
},
},
},
expected
:
true
,
topologyKey
:
"a"
,
},
{
name
:
"nodeA{'a':''} vs. empty label in nodeB"
,
nodeA
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"a"
:
""
,
},
},
},
nodeB
:
&
v1
.
Node
{},
expected
:
false
,
topologyKey
:
"a"
,
},
{
name
:
"nodeA{'a':''} vs. nodeB{'a':''}"
,
nodeA
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"a"
:
""
,
},
},
},
nodeB
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"a"
:
""
,
},
},
},
expected
:
true
,
topologyKey
:
"a"
,
},
{
name
:
"nodeA{'a':'a'} vs. nodeB{'a':'a'} by key{'b'}"
,
nodeA
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"a"
:
"a"
,
},
},
},
nodeB
:
&
v1
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"a"
:
"a"
,
},
},
},
expected
:
false
,
topologyKey
:
"b"
,
},
}
for
_
,
test
:=
range
tests
{
got
:=
NodesHaveSameTopologyKey
(
test
.
nodeA
,
test
.
nodeB
,
test
.
topologyKey
)
if
test
.
expected
!=
got
{
t
.
Errorf
(
"%v: expected %t, got %t"
,
test
.
name
,
test
.
expected
,
got
)
}
}
}
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