allocrunner: prevent panic on network manager (#16921)
This commit is contained in:
parent
a5967b1bad
commit
fb588fcbb8
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
client: Prevent a panic when an allocation has a legacy task-level bridge network and uses a driver that does not create a network namespace
|
||||
```
|
|
@ -93,7 +93,7 @@ func newNetworkManager(alloc *structs.Allocation, driverManager drivermanager.Ma
|
|||
|
||||
nm = netManager
|
||||
networkInitiator = task.Name
|
||||
} else if tg.Networks[0].Hostname != "" {
|
||||
} else if len(tg.Networks) > 0 && tg.Networks[0].Hostname != "" {
|
||||
// TODO jrasell: remove once the default linux network manager
|
||||
// supports setting the hostname in bridged mode. This currently
|
||||
// indicates only Docker supports this, which is true unless a
|
||||
|
|
|
@ -256,6 +256,32 @@ func TestNewNetworkManager(t *testing.T) {
|
|||
err: true,
|
||||
errContains: "hostname is not currently supported on driver group1",
|
||||
},
|
||||
{
|
||||
name: "legacy task network using exec and bridge",
|
||||
alloc: &structs.Allocation{
|
||||
TaskGroup: "group",
|
||||
Job: &structs.Job{
|
||||
TaskGroups: []*structs.TaskGroup{
|
||||
{
|
||||
Name: "group",
|
||||
Tasks: []*structs.Task{
|
||||
{
|
||||
Name: "task1",
|
||||
Driver: "group1",
|
||||
Resources: &structs.Resources{
|
||||
Networks: []*structs.NetworkResource{
|
||||
{Mode: "bridge"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
mustInit: false,
|
||||
err: false,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
|
Loading…
Reference in New Issue