Skip to content

Commit

Permalink
support running container with network id
Browse files Browse the repository at this point in the history
Signed-off-by: fahed dorgaa <[email protected]>
  • Loading branch information
fahedouch committed Oct 27, 2023
1 parent 2becba6 commit 792a0cb
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 792a0cb

Please sign in to comment.