Skip to content

Commit 3157e85

Browse files
committed
test(NSC): fix two DSR service tests to create pods
1 parent ca6b644 commit 3157e85

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

pkg/controllers/proxy/network_services_controller_test.go

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,32 +1643,39 @@ func TestDSR_TwoDSRServicesSameIPDifferentPorts(t *testing.T) {
16431643
&intPolicyCluster, extPolicyCluster)
16441644

16451645
ipvsState := newMockIPVSState()
1646+
netlinkState := newMockNetlinkState()
1647+
1648+
// Mock the standalone routeVIPTrafficToDirector function
1649+
routeVIPTrafficToDirector = createMockRouteVIPTrafficToDirector(netlinkState)
1650+
16461651
mock := &LinuxNetworkingMock{
1647-
getKubeDummyInterfaceFunc: func() (netlink.Link, error) {
1648-
return netlink.LinkByName("lo")
1649-
},
1650-
ipAddrAddFunc: func(iface netlink.Link, ip string, nodeIP string, addRoute bool) error {
1651-
return nil
1652-
},
1653-
ipAddrDelFunc: func(iface netlink.Link, ip string, nodeIP string) error {
1654-
return nil
1655-
},
1652+
getKubeDummyInterfaceFunc: createMockGetKubeDummyInterface(netlinkState),
1653+
ipAddrAddFunc: createMockIPAddrAdd(netlinkState),
1654+
ipAddrDelFunc: createMockIPAddrDel(netlinkState),
1655+
setupPolicyRoutingForDSRFunc: createMockSetupPolicyRoutingForDSR(netlinkState),
1656+
setupRoutesForExternalIPForDSRFunc: createMockSetupRoutesForExternalIPForDSR(netlinkState),
1657+
configureContainerForDSRFunc: createMockConfigureContainerForDSR(netlinkState),
1658+
getContainerPidWithDockerFunc: createMockGetContainerPidWithDocker(netlinkState),
1659+
getContainerPidWithCRIFunc: createMockGetContainerPidWithCRI(netlinkState),
1660+
findIfaceLinkForPidFunc: createMockFindIfaceLinkForPid(netlinkState),
16561661
ipvsAddServerFunc: func(ipvsSvc *ipvs.Service, ipvsDst *ipvs.Destination) error {
16571662
return nil
16581663
},
16591664
ipvsAddServiceFunc: func(svcs []*ipvs.Service, vip net.IP, protocol uint16, port uint16,
16601665
persistent bool, persistentTimeout int32, scheduler string,
16611666
flags schedFlags) ([]*ipvs.Service, *ipvs.Service, error) {
1662-
svc := &ipvs.Service{Address: vip, Protocol: protocol, Port: port}
1667+
svc := &ipvs.Service{
1668+
Address: vip,
1669+
Protocol: protocol,
1670+
Port: port,
1671+
}
16631672
ipvsState.services = append(ipvsState.services, svc)
16641673
return svcs, svc, nil
16651674
},
16661675
ipvsAddFWMarkServiceFunc: func(svcs []*ipvs.Service, fwMark uint32, family uint16, protocol uint16,
16671676
port uint16, persistent bool, persistentTimeout int32, scheduler string,
16681677
flags schedFlags) (*ipvs.Service, error) {
1669-
svc := &ipvs.Service{FWMark: fwMark, Protocol: protocol, Port: port}
1670-
ipvsState.services = append(ipvsState.services, svc)
1671-
return svc, nil
1678+
return &ipvs.Service{FWMark: fwMark}, nil
16721679
},
16731680
ipvsDelServiceFunc: func(ipvsSvc *ipvs.Service) error {
16741681
return nil
@@ -1681,12 +1688,6 @@ func TestDSR_TwoDSRServicesSameIPDifferentPorts(t *testing.T) {
16811688
copy(svcsCopy, ipvsState.services)
16821689
return svcsCopy, nil
16831690
},
1684-
setupPolicyRoutingForDSRFunc: func(setupIPv4 bool, setupIPv6 bool) error {
1685-
return nil
1686-
},
1687-
setupRoutesForExternalIPForDSRFunc: func(serviceInfo serviceInfoMap, setupIPv4 bool, setupIPv6 bool) error {
1688-
return nil
1689-
},
16901691
}
16911692

16921693
clientset := fake.NewSimpleClientset()
@@ -1719,6 +1720,29 @@ func TestDSR_TwoDSRServicesSameIPDifferentPorts(t *testing.T) {
17191720
assert.NoError(t, err)
17201721
}
17211722

1723+
// Create pods for the endpoints (required for DSR container configuration)
1724+
for i := 1; i <= 2; i++ {
1725+
pod := &v1core.Pod{
1726+
ObjectMeta: metav1.ObjectMeta{
1727+
Name: fmt.Sprintf("pod-%d", i),
1728+
Namespace: "default",
1729+
},
1730+
Spec: v1core.PodSpec{
1731+
Containers: []v1core.Container{{Name: fmt.Sprintf("container-%d", i)}},
1732+
},
1733+
Status: v1core.PodStatus{
1734+
PodIP: fmt.Sprintf("172.20.1.%d", i),
1735+
PodIPs: []v1core.PodIP{{IP: fmt.Sprintf("172.20.1.%d", i)}},
1736+
HostIP: "10.0.0.1",
1737+
ContainerStatuses: []v1core.ContainerStatus{
1738+
{ContainerID: fmt.Sprintf("docker://container-%d-id", i)},
1739+
},
1740+
},
1741+
}
1742+
_, err = clientset.CoreV1().Pods("default").Create(context.Background(), pod, metav1.CreateOptions{})
1743+
assert.NoError(t, err)
1744+
}
1745+
17221746
krNode := &utils.LocalKRNode{KRNode: utils.KRNode{NodeName: "localnode-1", PrimaryIP: net.ParseIP("10.0.0.1")}}
17231747
ipv4Mock := &utils.IPTablesHandlerMock{
17241748
AppendUniqueFunc: func(table string, chain string, rulespec ...string) error { return nil },

0 commit comments

Comments
 (0)