Skip to content

Commit

Permalink
Merge pull request #2589 from fahedouch/support-run-with-network-id
Browse files Browse the repository at this point in the history
Support run  container with network id
  • Loading branch information
AkihiroSuda committed Oct 28, 2023
2 parents ee09fd8 + 792a0cb commit e605881
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/nerdctl/container_run_network_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,20 @@ func TestRunInternetConnectivity(t *testing.T) {
type testCase struct {
args []string
}
customNetID := base.InspectNetwork(customNet).ID
testCases := []testCase{
{
args: []string{"--net", "bridge"},
},
{
args: []string{"--net", customNet},
},
{
args: []string{"--net", customNetID},
},
{
args: []string{"--net", customNetID[:12]},
},
{
args: []string{"--net", "host"},
},
Expand Down
8 changes: 8 additions & 0 deletions pkg/netutil/netutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ func (e *CNIEnv) NetworkMap() (map[string]*NetworkConfig, error) { //nolint:revi
log.L.Warnf("duplicate network name %q, %#v will get superseded by %#v", n.Name, original, n)
}
m[n.Name] = n
if n.NerdctlID != nil {
id := *n.NerdctlID
m[id] = n
if len(id) > 12 {
id = id[:12]
m[id] = n
}
}
}
return m, nil
}
Expand Down

0 comments on commit e605881

Please sign in to comment.