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
c7bf373d
Commit
c7bf373d
authored
May 18, 2015
by
Tim Hockin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow same-hostport-different-protocol
parent
dc81fe1f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
19 deletions
+22
-19
validation.go
pkg/api/validation/validation.go
+12
-15
validation_test.go
pkg/api/validation/validation_test.go
+9
-0
kubelet.go
pkg/kubelet/kubelet.go
+1
-4
No files found.
pkg/api/validation/validation.go
View file @
c7bf373d
...
...
@@ -673,22 +673,23 @@ func validateProbe(probe *api.Probe) errs.ValidationErrorList {
return
allErrs
}
//
A
ccumulateUniquePorts runs an extraction function on each Port of each Container,
//
a
ccumulateUniquePorts runs an extraction function on each Port of each Container,
// accumulating the results and returning an error if any ports conflict.
func
AccumulateUniquePorts
(
containers
[]
api
.
Container
,
accumulator
map
[
int
]
bool
,
extract
func
(
*
api
.
ContainerPort
)
int
)
errs
.
ValidationErrorList
{
func
accumulateUniqueHostPorts
(
containers
[]
api
.
Container
,
accumulator
map
[
string
]
bool
)
errs
.
ValidationErrorList
{
allErrs
:=
errs
.
ValidationErrorList
{}
for
ci
,
ctr
:=
range
containers
{
cErrs
:=
errs
.
ValidationErrorList
{}
for
pi
:=
range
ctr
.
Ports
{
port
:=
extract
(
&
ctr
.
Ports
[
pi
])
port
:=
ctr
.
Ports
[
pi
]
.
HostPort
if
port
==
0
{
continue
}
if
accumulator
[
port
]
{
cErrs
=
append
(
cErrs
,
errs
.
NewFieldDuplicate
(
"port"
,
port
))
str
:=
fmt
.
Sprintf
(
"%d/%s"
,
port
,
ctr
.
Ports
[
pi
]
.
Protocol
)
if
accumulator
[
str
]
{
cErrs
=
append
(
cErrs
,
errs
.
NewFieldDuplicate
(
"port"
,
str
))
}
else
{
accumulator
[
port
]
=
true
accumulator
[
str
]
=
true
}
}
allErrs
=
append
(
allErrs
,
cErrs
.
PrefixIndex
(
ci
)
...
)
...
...
@@ -696,11 +697,11 @@ func AccumulateUniquePorts(containers []api.Container, accumulator map[int]bool,
return
allErrs
}
//
checkHostPortConflic
ts checks for colliding Port.HostPort values across
//
ValidateHostPor
ts checks for colliding Port.HostPort values across
// a slice of containers.
func
checkHostPortConflic
ts
(
containers
[]
api
.
Container
)
errs
.
ValidationErrorList
{
allPorts
:=
map
[
int
]
bool
{}
return
AccumulateUniquePorts
(
containers
,
allPorts
,
func
(
p
*
api
.
ContainerPort
)
int
{
return
p
.
HostPort
}
)
func
ValidateHostPor
ts
(
containers
[]
api
.
Container
)
errs
.
ValidationErrorList
{
allPorts
:=
map
[
string
]
bool
{}
return
accumulateUniqueHostPorts
(
containers
,
allPorts
)
}
func
validateExecAction
(
exec
*
api
.
ExecAction
)
errs
.
ValidationErrorList
{
...
...
@@ -817,11 +818,7 @@ func validateContainers(containers []api.Container, volumes util.StringSet) errs
allErrs
=
append
(
allErrs
,
cErrs
.
PrefixIndex
(
i
)
...
)
}
// Check for colliding ports across all containers.
// TODO(thockin): This really is dependent on the network config of the host (IP per pod?)
// and the config of the new manifest. But we have not specced that out yet, so we'll just
// make some assumptions for now. As of now, pods share a network namespace, which means that
// every Port.HostPort across the whole pod must be unique.
allErrs
=
append
(
allErrs
,
checkHostPortConflicts
(
containers
)
...
)
allErrs
=
append
(
allErrs
,
ValidateHostPorts
(
containers
)
...
)
return
allErrs
}
...
...
pkg/api/validation/validation_test.go
View file @
c7bf373d
...
...
@@ -785,6 +785,15 @@ func TestValidateContainers(t *testing.T) {
},
ImagePullPolicy
:
"IfNotPresent"
,
},
{
Name
:
"same-host-port-different-protocol"
,
Image
:
"image"
,
Ports
:
[]
api
.
ContainerPort
{
{
ContainerPort
:
80
,
HostPort
:
80
,
Protocol
:
"TCP"
},
{
ContainerPort
:
80
,
HostPort
:
80
,
Protocol
:
"UDP"
},
},
ImagePullPolicy
:
"IfNotPresent"
,
},
{
Name
:
"abc-1234"
,
Image
:
"image"
,
ImagePullPolicy
:
"IfNotPresent"
,
SecurityContext
:
fakeValidSecurityContext
(
true
)},
}
if
errs
:=
validateContainers
(
successCase
,
volumes
);
len
(
errs
)
!=
0
{
...
...
pkg/kubelet/kubelet.go
View file @
c7bf373d
...
...
@@ -1354,14 +1354,11 @@ 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
:=
map
[
int
]
bool
{}
extract
:=
func
(
p
*
api
.
ContainerPort
)
int
{
return
p
.
HostPort
}
// Respect the pod creation order when resolving conflicts.
sort
.
Sort
(
podsByCreationTime
(
pods
))
for
_
,
pod
:=
range
pods
{
if
errs
:=
validation
.
AccumulateUniquePorts
(
pod
.
Spec
.
Containers
,
ports
,
extract
);
len
(
errs
)
!=
0
{
if
errs
:=
validation
.
ValidateHostPorts
(
pod
.
Spec
.
Containers
);
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