-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multi-interface network support #8208
Changes from all commits
ad8ced3
588b0c2
b9b4406
6a2a956
18ed6a7
12595a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,16 +58,22 @@ func (f *CNIFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintR | |
} | ||
|
||
var nodeNetworks structs.Networks | ||
var newNodeNetworks []*structs.NodeNetworkResource | ||
|
||
for name := range networks { | ||
mode := fmt.Sprintf("cni/%s", name) | ||
nodeNetworks = append(nodeNetworks, &structs.NetworkResource{ | ||
Mode: fmt.Sprintf("cni/%s", name), | ||
Mode: mode, | ||
}) | ||
newNodeNetworks = append(newNodeNetworks, &structs.NodeNetworkResource{ | ||
Mode: mode, | ||
}) | ||
f.logger.Debug("detected CNI network", "name", name) | ||
} | ||
|
||
resp.NodeResources = &structs.NodeResources{ | ||
Networks: nodeNetworks, | ||
Networks: nodeNetworks, | ||
NodeNetworks: newNodeNetworks, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: maybe rename |
||
} | ||
|
||
resp.Detected = true | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"os" | ||
"testing" | ||
|
||
"github.com/davecgh/go-spew/spew" | ||
"github.com/hashicorp/nomad/client/config" | ||
"github.com/hashicorp/nomad/helper/testlog" | ||
"github.com/hashicorp/nomad/nomad/structs" | ||
|
@@ -197,6 +198,8 @@ func TestNetworkFingerprint_basic(t *testing.T) { | |
t.Fatalf("err: %v", err) | ||
} | ||
|
||
spew.Dump(response) | ||
os.Exit(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some leftover debugging?
Comment on lines
+201
to
+202
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left in some debugging code |
||
if !response.Detected { | ||
t.Fatalf("expected response to be applicable") | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,15 +70,21 @@ const ( | |
// The ip:port are always the host's. | ||
AddrPrefix = "NOMAD_ADDR_" | ||
|
||
HostAddrPrefix = "NOMAD_HOST_ADDR_" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of these need comments. |
||
|
||
// IpPrefix is the prefix for passing the host IP of a port allocation | ||
// to a task. | ||
IpPrefix = "NOMAD_IP_" | ||
|
||
HostIpPrefix = "NOMAD_HOST_IP_" | ||
|
||
// PortPrefix is the prefix for passing the port allocation to a task. | ||
// It will be the task's port if a port map is specified. Task's should | ||
// bind to this port. | ||
PortPrefix = "NOMAD_PORT_" | ||
|
||
AllocPortPrefix = "NOMAD_ALLOC_PORT_" | ||
|
||
// HostPortPrefix is the prefix for passing the host port when a port | ||
// map is specified. | ||
HostPortPrefix = "NOMAD_HOST_PORT_" | ||
|
@@ -620,6 +626,7 @@ func (b *Builder) setAlloc(alloc *structs.Allocation) *Builder { | |
} | ||
} | ||
|
||
// COMPAT(1.0): remove in 1.0 when AllocatedPorts can be used exclusively | ||
// Add ports from other tasks | ||
for taskName, resources := range alloc.AllocatedResources.Tasks { | ||
// Add ports from other tasks | ||
|
@@ -637,6 +644,7 @@ func (b *Builder) setAlloc(alloc *structs.Allocation) *Builder { | |
} | ||
} | ||
|
||
// COMPAT(1.0): remove in 1.0 when AllocatedPorts can be used exclusively | ||
// Add ports from group networks | ||
//TODO Expose IPs but possibly only via variable interpolation | ||
for _, nw := range alloc.AllocatedResources.Shared.Networks { | ||
|
@@ -647,6 +655,11 @@ func (b *Builder) setAlloc(alloc *structs.Allocation) *Builder { | |
addGroupPort(b.otherPorts, p) | ||
} | ||
} | ||
|
||
// Add any allocated host ports | ||
if alloc.AllocatedResources.Shared.Ports != nil { | ||
addPorts(b.otherPorts, alloc.AllocatedResources.Shared.Ports) | ||
} | ||
} | ||
|
||
upstreams := []structs.ConsulUpstream{} | ||
|
@@ -857,3 +870,23 @@ func addGroupPort(m map[string]string, port structs.Port) { | |
|
||
m[HostPortPrefix+port.Label] = strconv.Itoa(port.Value) | ||
} | ||
|
||
func addPorts(m map[string]string, ports structs.AllocatedPorts) { | ||
for _, p := range ports { | ||
m[AddrPrefix+p.Label] = fmt.Sprintf("%s:%d", p.HostIP, p.Value) | ||
m[HostAddrPrefix+p.Label] = fmt.Sprintf("%s:%d", p.HostIP, p.Value) | ||
m[IpPrefix+p.Label] = p.HostIP | ||
m[HostIpPrefix+p.Label] = p.HostIP | ||
if p.To > 0 { | ||
val := strconv.Itoa(p.To) | ||
m[PortPrefix+p.Label] = val | ||
m[AllocPortPrefix+p.Label] = val | ||
} else { | ||
val := strconv.Itoa(p.Value) | ||
m[PortPrefix+p.Label] = val | ||
m[AllocPortPrefix+p.Label] = val | ||
} | ||
|
||
m[HostPortPrefix+p.Label] = strconv.Itoa(p.Value) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is safe -
append
may or may not re-allocate the underlying array of the first slice which gets confusing if it's also being indexed elsewhere (at which point each slice pointer is pointing to different arrays even though they were supposed to always be the same).Very unlikely to be a problem since I don't think we modify these after they're created, but I'd rather error on safety by creating a copy first