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
8d859f42
Commit
8d859f42
authored
Nov 04, 2014
by
Claire Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor PodFitsPorts
parent
1dddcea2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
16 deletions
+52
-16
predicates.go
pkg/scheduler/predicates.go
+15
-16
predicates_test.go
pkg/scheduler/predicates_test.go
+37
-0
No files found.
pkg/scheduler/predicates.go
View file @
8d859f42
...
...
@@ -163,30 +163,29 @@ func (n *NodeSelector) PodSelectorMatches(pod api.Pod, existingPods []api.Pod, n
}
func
PodFitsPorts
(
pod
api
.
Pod
,
existingPods
[]
api
.
Pod
,
node
string
)
(
bool
,
error
)
{
for
_
,
scheduledPod
:=
range
existingPods
{
for
_
,
container
:=
range
pod
.
DesiredState
.
Manifest
.
Containers
{
for
_
,
port
:=
range
container
.
Ports
{
if
port
.
HostPort
==
0
{
continue
}
if
containsPort
(
scheduledPod
,
port
)
{
return
false
,
nil
}
}
existingPorts
:=
getUsedPorts
(
existingPods
...
)
wantPorts
:=
getUsedPorts
(
pod
)
for
wport
:=
range
wantPorts
{
if
wport
==
0
{
continue
}
if
existingPorts
[
wport
]
{
return
false
,
nil
}
}
return
true
,
nil
}
func
containsPort
(
pod
api
.
Pod
,
port
api
.
Port
)
bool
{
for
_
,
container
:=
range
pod
.
DesiredState
.
Manifest
.
Containers
{
for
_
,
podPort
:=
range
container
.
Ports
{
if
podPort
.
HostPort
==
port
.
HostPort
{
return
true
func
getUsedPorts
(
pods
...
api
.
Pod
)
map
[
int
]
bool
{
ports
:=
make
(
map
[
int
]
bool
)
for
_
,
pod
:=
range
pods
{
for
_
,
container
:=
range
pod
.
DesiredState
.
Manifest
.
Containers
{
for
_
,
podPort
:=
range
container
.
Ports
{
ports
[
podPort
.
HostPort
]
=
true
}
}
}
return
false
return
ports
}
// MapPodsToMachines obtains a list of pods and pivots that list into a map where the keys are host names
...
...
pkg/scheduler/predicates_test.go
View file @
8d859f42
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
scheduler
import
(
"reflect"
"testing"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
...
...
@@ -182,6 +183,42 @@ func TestPodFitsPorts(t *testing.T) {
}
}
func
TestGetUsedPorts
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
pods
[]
api
.
Pod
ports
map
[
int
]
bool
}{
{
[]
api
.
Pod
{
newPod
(
"m1"
,
9090
),
},
map
[
int
]
bool
{
9090
:
true
},
},
{
[]
api
.
Pod
{
newPod
(
"m1"
,
9090
),
newPod
(
"m1"
,
9091
),
},
map
[
int
]
bool
{
9090
:
true
,
9091
:
true
},
},
{
[]
api
.
Pod
{
newPod
(
"m1"
,
9090
),
newPod
(
"m2"
,
9091
),
},
map
[
int
]
bool
{
9090
:
true
,
9091
:
true
},
},
}
for
_
,
test
:=
range
tests
{
ports
:=
getUsedPorts
(
test
.
pods
...
)
if
!
reflect
.
DeepEqual
(
test
.
ports
,
ports
)
{
t
.
Errorf
(
"expect %v, got %v"
,
test
.
ports
,
ports
)
}
}
}
func
TestDiskConflicts
(
t
*
testing
.
T
)
{
volState
:=
api
.
PodState
{
Manifest
:
api
.
ContainerManifest
{
...
...
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