mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
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.
This commit is contained in:
parent
eb89df9bb7
commit
fe8658b041
@ -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
|
||||||
|
@ -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) {
|
|||||||
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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user