Skip to content

Commit

Permalink
Invert CNI result order for UDN
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Rozet <trozet@redhat.com>
  • Loading branch information
trozet committed Oct 11, 2024
1 parent 7432f67 commit 7ae9d3b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
13 changes: 7 additions & 6 deletions go-controller/pkg/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,17 @@ func (pr *PodRequest) cmdAddWithGetCNIResultFunc(kubeAuth *KubeAPIAuth, clientse
return nil, err
}

response.Result.Routes = append(primaryUDNResult.Routes, response.Result.Routes...)
response.Result.Interfaces = append(primaryUDNResult.Interfaces, response.Result.Interfaces...)
response.Result.IPs = append(primaryUDNResult.IPs, response.Result.IPs...)
response.Result.Routes = append(response.Result.Routes, primaryUDNResult.Routes...)
numOfInitialIPs := len(response.Result.IPs)
numOfInitiialIfaces := len(response.Result.Interfaces)
response.Result.Interfaces = append(response.Result.Interfaces, primaryUDNResult.Interfaces...)
response.Result.IPs = append(response.Result.IPs, primaryUDNResult.IPs...)

// Offset the index of the default network IPs to correctly point to the default network interfaces
numOfPrimaryIfaces := len(primaryUDNResult.Interfaces)
for i := len(primaryUDNResult.IPs); i < len(response.Result.IPs); i++ {
for i := numOfInitialIPs; i < len(response.Result.IPs); i++ {
ifaceIPConfig := response.Result.IPs[i].Copy()
if response.Result.IPs[i].Interface != nil {
response.Result.IPs[i].Interface = current.Int(*ifaceIPConfig.Interface + numOfPrimaryIfaces)
response.Result.IPs[i].Interface = current.Int(*ifaceIPConfig.Interface + numOfInitiialIfaces)
}
}
}
Expand Down
35 changes: 18 additions & 17 deletions go-controller/pkg/cni/cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,58 +252,59 @@ var _ = Describe("Network Segmentation", func() {
// 1: pod side primary UDN
// 2: host side default network
// 3: pod side default network
podDefaultClusterNetIfaceIDX := 3
podUDNIfaceIDX := 1
podDefaultClusterNetIfaceIDX := 1
podUDNIfaceIDX := 3
Expect(response.Result).To(Equal(
&current.Result{
CNIVersion: "0.3.1",
Interfaces: []*current.Interface{
{
Name: "host_ovn-udn1",
Name: "host_eth0",
Mac: dummyMACHostSide,
},
{
Name: "ovn-udn1",
Mac: "02:03:04:05:06:07",
Name: "eth0",
Mac: "0a:58:fd:98:00:01",
Sandbox: "bobloblaw",
}, {
Name: "host_eth0",
},
{
Name: "host_ovn-udn1",
Mac: dummyMACHostSide,
},
{
Name: "eth0",
Mac: "0a:58:fd:98:00:01",
Name: "ovn-udn1",
Mac: "02:03:04:05:06:07",
Sandbox: "bobloblaw",
},
},
IPs: []*current.IPConfig{
{
Address: net.IPNet{
IP: net.ParseIP("10.10.10.30"),
IP: net.ParseIP("100.10.10.3"),
Mask: net.CIDRMask(24, 32),
},
Interface: &podUDNIfaceIDX,
Interface: &podDefaultClusterNetIfaceIDX,
},
{
Address: net.IPNet{
IP: net.ParseIP("fd10::3"),
IP: net.ParseIP("fd44::33"),
Mask: net.CIDRMask(64, 128),
},
Interface: &podUDNIfaceIDX,
Interface: &podDefaultClusterNetIfaceIDX,
},
{
Address: net.IPNet{
IP: net.ParseIP("100.10.10.3"),
IP: net.ParseIP("10.10.10.30"),
Mask: net.CIDRMask(24, 32),
},
Interface: &podDefaultClusterNetIfaceIDX,
Interface: &podUDNIfaceIDX,
},
{
Address: net.IPNet{
IP: net.ParseIP("fd44::33"),
IP: net.ParseIP("fd10::3"),
Mask: net.CIDRMask(64, 128),
},
Interface: &podDefaultClusterNetIfaceIDX,
Interface: &podUDNIfaceIDX,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/network_segmentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var _ = Describe("Network Segmentation", func() {
ovnUDNInterface = "ovn-udn1"
)
Expect(udnNetStat).To(HaveLen(expectedDefaultNetStatusLen))
Expect(udnNetStat[0].Interface).To(Equal(ovnUDNInterface))
Expect(udnNetStat[1].Interface).To(Equal(ovnUDNInterface))

cidrs := strings.Split(netConfig.cidr, ",")
for i, serverIP := range udnNetStat[0].IPs {
Expand Down

0 comments on commit 7ae9d3b

Please sign in to comment.