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
fe8658b0
Commit
fe8658b0
authored
Nov 08, 2015
by
Ravi L R
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix ports mapping in case of discontinuous port ranges in mesos offer
update elements in wildports directly instead of copy of the value from wildports.
parent
eb89df9b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
4 deletions
+43
-4
port_mapping.go
contrib/mesos/pkg/scheduler/podtask/port_mapping.go
+4
-4
port_mapping_test.go
contrib/mesos/pkg/scheduler/podtask/port_mapping_test.go
+39
-0
No files found.
contrib/mesos/pkg/scheduler/podtask/port_mapping.go
View file @
fe8658b0
...
@@ -99,16 +99,16 @@ func wildcardHostPortMapping(t *T, offer *mesos.Offer) ([]HostPortMapping, error
...
@@ -99,16 +99,16 @@ func wildcardHostPortMapping(t *T, offer *mesos.Offer) ([]HostPortMapping, error
remaining
:=
len
(
wildports
)
remaining
:=
len
(
wildports
)
foreachRange
(
offer
,
"ports"
,
func
(
bp
,
ep
uint64
)
{
foreachRange
(
offer
,
"ports"
,
func
(
bp
,
ep
uint64
)
{
log
.
V
(
3
)
.
Infof
(
"Searching for wildcard port in range {%d:%d}"
,
bp
,
ep
)
log
.
V
(
3
)
.
Infof
(
"Searching for wildcard port in range {%d:%d}"
,
bp
,
ep
)
for
_
,
entry
:=
range
wildports
{
for
i
:=
range
wildports
{
if
entry
.
OfferPort
!=
0
{
if
wildports
[
i
]
.
OfferPort
!=
0
{
continue
continue
}
}
for
port
:=
bp
;
port
<=
ep
&&
remaining
>
0
;
port
++
{
for
port
:=
bp
;
port
<=
ep
&&
remaining
>
0
;
port
++
{
if
_
,
inuse
:=
taken
[
port
];
inuse
{
if
_
,
inuse
:=
taken
[
port
];
inuse
{
continue
continue
}
}
entry
.
OfferPort
=
port
wildports
[
i
]
.
OfferPort
=
port
mapping
=
append
(
mapping
,
entry
)
mapping
=
append
(
mapping
,
wildports
[
i
]
)
remaining
--
remaining
--
taken
[
port
]
=
struct
{}{}
taken
[
port
]
=
struct
{}{}
break
break
...
...
contrib/mesos/pkg/scheduler/podtask/port_mapping_test.go
View file @
fe8658b0
...
@@ -20,6 +20,7 @@ import (
...
@@ -20,6 +20,7 @@ import (
"testing"
"testing"
mesos
"github.com/mesos/mesos-go/mesosproto"
mesos
"github.com/mesos/mesos-go/mesosproto"
"github.com/mesos/mesos-go/mesosutil"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
)
)
...
@@ -178,6 +179,44 @@ func TestWildcardHostPortMatching(t *testing.T) {
...
@@ -178,6 +179,44 @@ func TestWildcardHostPortMatching(t *testing.T) {
if
valid
<
2
{
if
valid
<
2
{
t
.
Fatalf
(
"Expected 2 valid port mappings, not %d"
,
valid
)
t
.
Fatalf
(
"Expected 2 valid port mappings, not %d"
,
valid
)
}
}
//-- port mapping in case of multiple discontinuous port ranges in mesos offer
pod
.
Spec
=
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{{
Ports
:
[]
api
.
ContainerPort
{{
HostPort
:
0
,
},
{
HostPort
:
0
,
}},
}},
}
task
,
err
=
New
(
api
.
NewDefaultContext
(),
""
,
*
pod
,
&
mesos
.
ExecutorInfo
{})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
offer
=
&
mesos
.
Offer
{
Resources
:
[]
*
mesos
.
Resource
{
mesosutil
.
NewRangesResource
(
"ports"
,
[]
*
mesos
.
Value_Range
{
mesosutil
.
NewValueRange
(
1
,
1
),
mesosutil
.
NewValueRange
(
3
,
5
)}),
},
}
mapping
,
err
=
wildcardHostPortMapping
(
task
,
offer
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
else
if
len
(
mapping
)
!=
2
{
t
.
Fatal
(
"Expected both ports allocated"
)
}
valid
=
0
for
_
,
entry
:=
range
mapping
{
if
entry
.
ContainerIdx
==
0
&&
entry
.
PortIdx
==
0
&&
entry
.
OfferPort
==
1
{
valid
++
}
if
entry
.
ContainerIdx
==
0
&&
entry
.
PortIdx
==
1
&&
entry
.
OfferPort
==
3
{
valid
++
}
}
if
valid
<
2
{
t
.
Fatalf
(
"Expected 2 valid port mappings, not %d"
,
valid
)
}
}
}
func
TestMappingTypeForPod
(
t
*
testing
.
T
)
{
func
TestMappingTypeForPod
(
t
*
testing
.
T
)
{
...
...
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