allocrunner: prevent panic on network manager (#16921)

This commit is contained in:
Luiz Aoqui 2023-04-18 13:39:13 -07:00 committed by GitHub
parent a5967b1bad
commit fb588fcbb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 1 deletions

3
.changelog/16921.txt Normal file
View File

@ -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
```

View File

@ -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

View File

@ -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)