mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +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)
|
||||
foreachRange(offer, "ports", func(bp, ep uint64) {
|
||||
log.V(3).Infof("Searching for wildcard port in range {%d:%d}", bp, ep)
|
||||
for _, entry := range wildports {
|
||||
if entry.OfferPort != 0 {
|
||||
for i := range wildports {
|
||||
if wildports[i].OfferPort != 0 {
|
||||
continue
|
||||
}
|
||||
for port := bp; port <= ep && remaining > 0; port++ {
|
||||
if _, inuse := taken[port]; inuse {
|
||||
continue
|
||||
}
|
||||
entry.OfferPort = port
|
||||
mapping = append(mapping, entry)
|
||||
wildports[i].OfferPort = port
|
||||
mapping = append(mapping, wildports[i])
|
||||
remaining--
|
||||
taken[port] = struct{}{}
|
||||
break
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
"testing"
|
||||
|
||||
mesos "github.com/mesos/mesos-go/mesosproto"
|
||||
"github.com/mesos/mesos-go/mesosutil"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
)
|
||||
|
||||
@ -178,6 +179,44 @@ func TestWildcardHostPortMatching(t *testing.T) {
|
||||
if valid < 2 {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user