fix(host): ignore nil host_port of portmapping error (#21025)

This commit is contained in:
Zexi Li
2024-08-15 10:42:54 +08:00
committed by GitHub
parent ca8398dca3
commit 42e210861c
2 changed files with 7 additions and 4 deletions
+4 -1
View File
@@ -4,6 +4,7 @@ import (
"context"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/sets"
@@ -119,7 +120,9 @@ func (m *portMappingManager) getOtherGuestsUsedPorts(gst GuestRuntimeInstance) (
ps = sets.NewInt()
}
if pm.HostPort == nil {
return nil, errors.Errorf("portmap %s has nil host port", jsonutils.Marshal(pm))
//return nil, errors.Errorf("guest (%s/%s) portmap %s has nil host port", ins.GetId(), ins.GetName(), jsonutils.Marshal(pm))
log.Warningf("%s", errors.Errorf("guest (%s/%s) portmap %s has nil host port", ins.GetId(), ins.GetName(), jsonutils.Marshal(pm)))
continue
}
ps.Insert(*pm.HostPort)
ret[pm.Protocol] = ps
+3 -3
View File
@@ -21,7 +21,6 @@ import (
"strconv"
"strings"
"yunion.io/x/log"
"yunion.io/x/pkg/errors"
"yunion.io/x/pkg/util/sets"
)
@@ -119,6 +118,7 @@ func GetPortByRange(proto Protocol, start int, end int) (PortResult, error) {
}
func GetPortByRangeBySets(proto Protocol, start int, end int, usedPorts sets.Int) (PortResult, error) {
errs := []error{}
for i := start; i <= end; i++ {
rPort := rand.Intn(end-start) + start
if usedPorts.Has(rPort) {
@@ -127,7 +127,7 @@ func GetPortByRangeBySets(proto Protocol, start int, end int, usedPorts sets.Int
result, err := getPort(proto, "", rPort)
if err != nil {
usedPorts.Insert(rPort)
log.Debugf("check random port %d: %v", rPort, err)
errs = append(errs, errors.Wrapf(err, "check random port: %d", rPort))
} else {
return result, nil
}
@@ -135,7 +135,7 @@ func GetPortByRangeBySets(proto Protocol, start int, end int, usedPorts sets.Int
return PortResult{
IP: "",
Port: -1,
}, errors.Errorf("can't get free port in [%d, %d]", start, end)
}, errors.Wrapf(errors.NewAggregate(errs), "can't get free port in [%d, %d]", start, end)
}
// GetTcpPort gets a port for some random available address using either