mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
Merge pull request #9739 from hashicorp/b-alloc-netmode-ports
Use port's to value when building service address under 'alloc' addr_mode
This commit is contained in:
@@ -1547,7 +1547,7 @@ func getAddress(addrMode, portLabel string, networks structs.Networks, driverNet
|
||||
|
||||
return driverNet.IP, port, nil
|
||||
|
||||
case "alloc":
|
||||
case structs.AddressModeAlloc:
|
||||
if netStatus == nil {
|
||||
return "", 0, fmt.Errorf(`cannot use address_mode="alloc": no allocation network status reported`)
|
||||
}
|
||||
@@ -1559,6 +1559,10 @@ func getAddress(addrMode, portLabel string, networks structs.Networks, driverNet
|
||||
|
||||
// If port is a label and is found then return it
|
||||
if port, ok := ports.Get(portLabel); ok {
|
||||
// Use port.To value unless not set
|
||||
if port.To > 0 {
|
||||
return netStatus.Address, port.To, nil
|
||||
}
|
||||
return netStatus.Address, port.Value, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1632,6 +1632,24 @@ func TestGetAddress(t *testing.T) {
|
||||
Address: "172.26.0.1",
|
||||
},
|
||||
ExpectedIP: "172.26.0.1",
|
||||
ExpectedPort: 6379,
|
||||
},
|
||||
{
|
||||
Name: "Alloc no to value",
|
||||
Mode: structs.AddressModeAlloc,
|
||||
PortLabel: "db",
|
||||
Ports: []structs.AllocatedPortMapping{
|
||||
{
|
||||
Label: "db",
|
||||
Value: 12345,
|
||||
HostIP: HostIP,
|
||||
},
|
||||
},
|
||||
Status: &structs.AllocNetworkStatus{
|
||||
InterfaceName: "eth0",
|
||||
Address: "172.26.0.1",
|
||||
},
|
||||
ExpectedIP: "172.26.0.1",
|
||||
ExpectedPort: 12345,
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user