mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
Merge pull request #5641 from hashicorp/b-task-networks-ports
client: handle 0.8 server network resources
This commit is contained in:
@@ -544,15 +544,9 @@ func (b *Builder) setTask(task *structs.Task) *Builder {
|
||||
if task.Resources == nil {
|
||||
b.memLimit = 0
|
||||
b.cpuLimit = 0
|
||||
b.networks = []*structs.NetworkResource{}
|
||||
} else {
|
||||
b.memLimit = int64(task.Resources.MemoryMB)
|
||||
b.cpuLimit = int64(task.Resources.CPU)
|
||||
// Copy networks to prevent sharing
|
||||
b.networks = make([]*structs.NetworkResource, len(task.Resources.Networks))
|
||||
for i, n := range task.Resources.Networks {
|
||||
b.networks[i] = n.Copy()
|
||||
}
|
||||
}
|
||||
return b
|
||||
}
|
||||
@@ -622,6 +616,15 @@ func (b *Builder) setAlloc(alloc *structs.Allocation) *Builder {
|
||||
}
|
||||
}
|
||||
} else if alloc.TaskResources != nil {
|
||||
if tr, ok := alloc.TaskResources[b.taskName]; ok {
|
||||
// Copy networks to prevent sharing
|
||||
b.networks = make([]*structs.NetworkResource, len(tr.Networks))
|
||||
for i, n := range tr.Networks {
|
||||
b.networks[i] = n.Copy()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for taskName, resources := range alloc.TaskResources {
|
||||
// Add ports from other tasks
|
||||
if taskName == b.taskName {
|
||||
|
||||
@@ -228,12 +228,11 @@ func TestEnvironment_AsList_Old(t *testing.T) {
|
||||
Device: "eth0",
|
||||
IP: "192.168.0.100",
|
||||
ReservedPorts: []structs.Port{
|
||||
{Label: "admin", Value: 5000},
|
||||
{Label: "ssh", Value: 22},
|
||||
{Label: "other", Value: 1234},
|
||||
},
|
||||
MBits: 50,
|
||||
DynamicPorts: []structs.Port{{Label: "http"}},
|
||||
DynamicPorts: []structs.Port{{Label: "http", Value: 2000}},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -244,10 +243,10 @@ func TestEnvironment_AsList_Old(t *testing.T) {
|
||||
Networks: []*structs.NetworkResource{
|
||||
{
|
||||
Device: "eth0",
|
||||
IP: "192.168.0.100",
|
||||
ReservedPorts: []structs.Port{{Label: "admin", Value: 5000}},
|
||||
IP: "127.0.0.1",
|
||||
ReservedPorts: []structs.Port{{Label: "https", Value: 8080}},
|
||||
MBits: 50,
|
||||
DynamicPorts: []structs.Port{{Label: "http", Value: 2000}},
|
||||
DynamicPorts: []structs.Port{{Label: "http", Value: 80}},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -270,10 +269,11 @@ func TestEnvironment_AsList_Old(t *testing.T) {
|
||||
"taskEnvKey": "taskEnvVal",
|
||||
}
|
||||
task.Resources.Networks = []*structs.NetworkResource{
|
||||
// Nomad 0.8 didn't fully populate the fields in task Resource Networks
|
||||
{
|
||||
IP: "127.0.0.1",
|
||||
ReservedPorts: []structs.Port{{Label: "http", Value: 80}},
|
||||
DynamicPorts: []structs.Port{{Label: "https", Value: 8080}},
|
||||
IP: "",
|
||||
ReservedPorts: []structs.Port{{Label: "https"}},
|
||||
DynamicPorts: []structs.Port{{Label: "http"}},
|
||||
},
|
||||
}
|
||||
env := NewBuilder(n, a, task, "global").SetDriverNetwork(
|
||||
|
||||
Reference in New Issue
Block a user