Skip to content

Commit

Permalink
Merge pull request #71 from maiqueb/account-for-sandbox-ifaces-when-c…
Browse files Browse the repository at this point in the history
…hoosing-default

Accont for non-sandbox interfaces when specifying the default network
  • Loading branch information
dougbtv authored Sep 13, 2024
2 parents d23f60f + d8782ff commit 506cfda
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pkg/utils/net-attach-def.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ func CreateNetworkStatuses(r cnitypes.Result, networkName string, defaultNetwork

// Initialize NetworkStatus for each container interface (e.g. with sandbox present)
indexOfFoundPodInterface := 0
foundFirstSandboxIface := false
for i, iface := range result.Interfaces {
if iface.Sandbox != "" {
ns := &v1.NetworkStatus{
Name: networkName,
Default: defaultNetwork && i == 0,
Default: defaultNetwork && !foundFirstSandboxIface,
Interface: iface.Name,
Mac: iface.Mac,
Mtu: iface.Mtu,
Expand All @@ -166,6 +167,7 @@ func CreateNetworkStatuses(r cnitypes.Result, networkName string, defaultNetwork
// Map original index to the new slice index
indexMap[i] = indexOfFoundPodInterface
indexOfFoundPodInterface++
foundFirstSandboxIface = true
}
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/utils/net-attach-def_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,16 @@ var _ = Describe("Netwok Attachment Definition manipulations", func() {
cniResult = &cni100.Result{
CNIVersion: "1.1.0",
Interfaces: []*cni100.Interface{
{
Name: "foo",
Mac: "00:AA:BB:CC:DD:33",
},
{
Name: "example0",
Mac: "00:AA:BB:CC:DD:01",
Sandbox: "/path/to/network/namespace",
Mtu: 1500,
},
{
Name: "foo",
Mac: "00:AA:BB:CC:DD:33",
},
{
Name: "example1",
Mac: "00:AA:BB:CC:DD:02",
Expand All @@ -252,11 +252,11 @@ var _ = Describe("Netwok Attachment Definition manipulations", func() {
IPs: []*cni100.IPConfig{
{
Address: *EnsureCIDR("192.0.2.1/24"),
Interface: &[]int{0}[0],
Interface: &[]int{1}[0],
},
{
Address: *EnsureCIDR("192.0.2.2/24"),
Interface: &[]int{0}[0],
Interface: &[]int{1}[0],
},
{
Address: *EnsureCIDR("192.0.2.3/24"),
Expand Down

0 comments on commit 506cfda

Please sign in to comment.