Skip to content

Commit

Permalink
Accont for non-sandbox interfaces when specifying the default network
Browse files Browse the repository at this point in the history
We only account for the sandox interfaces when reporting the interfaces
in the network-status annotation; in case the `CreateNetworkStatuses`
clients invoke it with a CNI result featuring non-sandbox interfaces
*before*, the existing criteria would not work, and we would fail to
report **any** inteface as the default one.

Signed-off-by: Miguel Duarte Barroso <mdbarroso@redhat.com>
  • Loading branch information
maiqueb committed Sep 13, 2024
1 parent d23f60f commit d8782ff
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 d8782ff

Please sign in to comment.