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
18c5fa1a
Commit
18c5fa1a
authored
Feb 05, 2015
by
Jerzy Szczepkowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Applied comments.
parent
0010e021
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
17 deletions
+20
-17
constraint.go
pkg/constraint/constraint.go
+5
-4
constraint_test.go
pkg/constraint/constraint_test.go
+6
-6
ports.go
pkg/constraint/ports.go
+7
-5
etcd.go
pkg/registry/etcd/etcd.go
+2
-2
No files found.
pkg/constraint/constraint.go
View file @
18c5fa1a
...
@@ -24,9 +24,10 @@ import (
...
@@ -24,9 +24,10 @@ import (
// Allowed returns true if pods is a collection of bound pods
// Allowed returns true if pods is a collection of bound pods
// which can run without conflict on a single minion.
// which can run without conflict on a single minion.
func
Allowed
(
pods
[]
api
.
BoundPod
)
error
{
func
Allowed
(
pods
[]
api
.
BoundPod
)
[]
error
{
if
PortsConflict
(
pods
)
{
errors
:=
[]
error
{}
return
fmt
.
Errorf
(
"conflicting ports"
)
for
_
,
port
:=
range
hostPortsConflict
(
pods
)
{
errors
=
append
(
errors
,
fmt
.
Errorf
(
"host port %v is already in use"
,
port
))
}
}
return
nil
return
errors
}
}
pkg/constraint/constraint_test.go
View file @
18c5fa1a
...
@@ -41,11 +41,11 @@ func podWithContainers(containers ...api.Container) api.BoundPod {
...
@@ -41,11 +41,11 @@ func podWithContainers(containers ...api.Container) api.BoundPod {
func
TestAllowed
(
t
*
testing
.
T
)
{
func
TestAllowed
(
t
*
testing
.
T
)
{
table
:=
[]
struct
{
table
:=
[]
struct
{
err
error
err
string
pods
[]
api
.
BoundPod
pods
[]
api
.
BoundPod
}{
}{
{
{
err
:
nil
,
err
:
"[]"
,
pods
:
[]
api
.
BoundPod
{
pods
:
[]
api
.
BoundPod
{
podWithContainers
(
podWithContainers
(
containerWithHostPorts
(
1
,
2
,
3
),
containerWithHostPorts
(
1
,
2
,
3
),
...
@@ -58,7 +58,7 @@ func TestAllowed(t *testing.T) {
...
@@ -58,7 +58,7 @@ func TestAllowed(t *testing.T) {
},
},
},
},
{
{
err
:
nil
,
err
:
"[]"
,
pods
:
[]
api
.
BoundPod
{
pods
:
[]
api
.
BoundPod
{
podWithContainers
(
podWithContainers
(
containerWithHostPorts
(
0
,
0
),
containerWithHostPorts
(
0
,
0
),
...
@@ -71,7 +71,7 @@ func TestAllowed(t *testing.T) {
...
@@ -71,7 +71,7 @@ func TestAllowed(t *testing.T) {
},
},
},
},
{
{
err
:
fmt
.
Errorf
(
"conflicting ports"
)
,
err
:
"[host port 3 is already in use]"
,
pods
:
[]
api
.
BoundPod
{
pods
:
[]
api
.
BoundPod
{
podWithContainers
(
podWithContainers
(
containerWithHostPorts
(
3
,
3
),
containerWithHostPorts
(
3
,
3
),
...
@@ -79,7 +79,7 @@ func TestAllowed(t *testing.T) {
...
@@ -79,7 +79,7 @@ func TestAllowed(t *testing.T) {
},
},
},
},
{
{
err
:
fmt
.
Errorf
(
"conflicting ports"
)
,
err
:
"[host port 6 is already in use]"
,
pods
:
[]
api
.
BoundPod
{
pods
:
[]
api
.
BoundPod
{
podWithContainers
(
podWithContainers
(
containerWithHostPorts
(
6
),
containerWithHostPorts
(
6
),
...
@@ -92,7 +92,7 @@ func TestAllowed(t *testing.T) {
...
@@ -92,7 +92,7 @@ func TestAllowed(t *testing.T) {
}
}
for
_
,
item
:=
range
table
{
for
_
,
item
:=
range
table
{
if
e
,
a
:=
item
.
err
,
Allowed
(
item
.
pods
);
e
!=
a
&&
e
.
Error
()
!=
a
.
Error
(
)
{
if
e
,
a
:=
item
.
err
,
Allowed
(
item
.
pods
);
e
!=
fmt
.
Sprintf
(
"%v"
,
a
)
{
t
.
Errorf
(
"Expected %v, got %v:
\n
%v
\v
"
,
e
,
a
,
item
.
pods
)
t
.
Errorf
(
"Expected %v, got %v:
\n
%v
\v
"
,
e
,
a
,
item
.
pods
)
}
}
}
}
...
...
pkg/constraint/ports.go
View file @
18c5fa1a
...
@@ -20,10 +20,12 @@ import (
...
@@ -20,10 +20,12 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
)
// PortsConflict returns true iff two containers attempt to expose
// hostPortsConflict returns an array of host ports that at least two
// the same host port.
// containers attempt to expose. The array is empty if no such port
func
PortsConflict
(
pods
[]
api
.
BoundPod
)
bool
{
// exists.
func
hostPortsConflict
(
pods
[]
api
.
BoundPod
)
[]
int
{
hostPorts
:=
map
[
int
]
struct
{}{}
hostPorts
:=
map
[
int
]
struct
{}{}
conflictingPorts
:=
[]
int
{}
for
_
,
pod
:=
range
pods
{
for
_
,
pod
:=
range
pods
{
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
for
_
,
port
:=
range
container
.
Ports
{
for
_
,
port
:=
range
container
.
Ports
{
...
@@ -31,11 +33,11 @@ func PortsConflict(pods []api.BoundPod) bool {
...
@@ -31,11 +33,11 @@ func PortsConflict(pods []api.BoundPod) bool {
continue
continue
}
}
if
_
,
exists
:=
hostPorts
[
port
.
HostPort
];
exists
{
if
_
,
exists
:=
hostPorts
[
port
.
HostPort
];
exists
{
return
true
conflictingPorts
=
append
(
conflictingPorts
,
port
.
HostPort
)
}
}
hostPorts
[
port
.
HostPort
]
=
struct
{}{}
hostPorts
[
port
.
HostPort
]
=
struct
{}{}
}
}
}
}
}
}
return
false
return
conflictingPorts
}
}
pkg/registry/etcd/etcd.go
View file @
18c5fa1a
...
@@ -214,8 +214,8 @@ func (r *Registry) assignPod(ctx api.Context, podID string, machine string) erro
...
@@ -214,8 +214,8 @@ func (r *Registry) assignPod(ctx api.Context, podID string, machine string) erro
err
=
r
.
AtomicUpdate
(
contKey
,
&
api
.
BoundPods
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
err
=
r
.
AtomicUpdate
(
contKey
,
&
api
.
BoundPods
{},
func
(
in
runtime
.
Object
)
(
runtime
.
Object
,
error
)
{
boundPodList
:=
in
.
(
*
api
.
BoundPods
)
boundPodList
:=
in
.
(
*
api
.
BoundPods
)
boundPodList
.
Items
=
append
(
boundPodList
.
Items
,
*
boundPod
)
boundPodList
.
Items
=
append
(
boundPodList
.
Items
,
*
boundPod
)
if
e
:=
constraint
.
Allowed
(
boundPodList
.
Items
);
e
!=
nil
{
if
e
rrors
:=
constraint
.
Allowed
(
boundPodList
.
Items
);
len
(
errors
)
>
0
{
return
nil
,
fmt
.
Errorf
(
"the assignment would cause the following constraint
violation: %v"
,
e
)
return
nil
,
fmt
.
Errorf
(
"the assignment would cause the following constraint
s violation: %v"
,
errors
)
}
}
return
boundPodList
,
nil
return
boundPodList
,
nil
})
})
...
...
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