Skip to content

Commit

Permalink
allocrunner: prevent panic on network manager (#16921)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgfa29 committed Apr 18, 2023
1 parent 44e5cb5 commit 3f7143f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/16921.txt
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 1 addition & 1 deletion client/allocrunner/network_manager_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions client/allocrunner/network_manager_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3f7143f

Please sign in to comment.