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
711fa2f2
Commit
711fa2f2
authored
May 19, 2015
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
c7bf373d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
10 deletions
+12
-10
validation.go
pkg/api/validation/validation.go
+9
-9
kubelet.go
pkg/kubelet/kubelet.go
+3
-1
No files found.
pkg/api/validation/validation.go
View file @
711fa2f2
...
...
@@ -673,9 +673,9 @@ func validateProbe(probe *api.Probe) errs.ValidationErrorList {
return
allErrs
}
//
accumulateUniquePorts runs an extraction function on each
Port of each Container,
//
AccumulateUniqueHostPorts extracts each Host
Port of each Container,
// accumulating the results and returning an error if any ports conflict.
func
accumulateUniqueHostPorts
(
containers
[]
api
.
Container
,
accumulator
map
[
string
]
bool
)
errs
.
ValidationErrorList
{
func
AccumulateUniqueHostPorts
(
containers
[]
api
.
Container
,
accumulator
*
util
.
StringSet
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
for
ci
,
ctr
:=
range
containers
{
...
...
@@ -686,10 +686,10 @@ func accumulateUniqueHostPorts(containers []api.Container, accumulator map[strin
continue
}
str
:=
fmt
.
Sprintf
(
"%d/%s"
,
port
,
ctr
.
Ports
[
pi
]
.
Protocol
)
if
accumulator
[
str
]
{
if
accumulator
.
Has
(
str
)
{
cErrs
=
append
(
cErrs
,
errs
.
NewFieldDuplicate
(
"port"
,
str
))
}
else
{
accumulator
[
str
]
=
true
accumulator
.
Insert
(
str
)
}
}
allErrs
=
append
(
allErrs
,
cErrs
.
PrefixIndex
(
ci
)
...
)
...
...
@@ -697,11 +697,11 @@ func accumulateUniqueHostPorts(containers []api.Container, accumulator map[strin
return
allErrs
}
//
ValidateHostPor
ts checks for colliding Port.HostPort values across
//
checkHostPortConflic
ts checks for colliding Port.HostPort values across
// a slice of containers.
func
ValidateHostPor
ts
(
containers
[]
api
.
Container
)
errs
.
ValidationErrorList
{
allPorts
:=
map
[
string
]
bool
{}
return
accumulateUniqueHostPorts
(
containers
,
allPorts
)
func
checkHostPortConflic
ts
(
containers
[]
api
.
Container
)
errs
.
ValidationErrorList
{
allPorts
:=
util
.
StringSet
{}
return
AccumulateUniqueHostPorts
(
containers
,
&
allPorts
)
}
func
validateExecAction
(
exec
*
api
.
ExecAction
)
errs
.
ValidationErrorList
{
...
...
@@ -818,7 +818,7 @@ func validateContainers(containers []api.Container, volumes util.StringSet) errs
allErrs
=
append
(
allErrs
,
cErrs
.
PrefixIndex
(
i
)
...
)
}
// Check for colliding ports across all containers.
allErrs
=
append
(
allErrs
,
ValidateHostPor
ts
(
containers
)
...
)
allErrs
=
append
(
allErrs
,
checkHostPortConflic
ts
(
containers
)
...
)
return
allErrs
}
...
...
pkg/kubelet/kubelet.go
View file @
711fa2f2
...
...
@@ -1354,11 +1354,13 @@ func (s podsByCreationTime) Less(i, j int) bool {
// checkHostPortConflicts detects pods with conflicted host ports.
func
checkHostPortConflicts
(
pods
[]
*
api
.
Pod
)
(
fitting
[]
*
api
.
Pod
,
notFitting
[]
*
api
.
Pod
)
{
ports
:=
util
.
StringSet
{}
// Respect the pod creation order when resolving conflicts.
sort
.
Sort
(
podsByCreationTime
(
pods
))
for
_
,
pod
:=
range
pods
{
if
errs
:=
validation
.
ValidateHostPorts
(
pod
.
Spec
.
Container
s
);
len
(
errs
)
!=
0
{
if
errs
:=
validation
.
AccumulateUniqueHostPorts
(
pod
.
Spec
.
Containers
,
&
port
s
);
len
(
errs
)
!=
0
{
glog
.
Errorf
(
"Pod %q: HostPort is already allocated, ignoring: %v"
,
kubecontainer
.
GetPodFullName
(
pod
),
errs
)
notFitting
=
append
(
notFitting
,
pod
)
continue
...
...
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