mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Only detecting stale connections for UDP ports in kube-proxy.
The detectStaleConnections function in kube-proxy is very expensive in terms of CPU utilization. The results of this function are only actually used for UDP ports. This adds a protocol attribute to ServicePortName to make it simple to only run this function for UDP connections. For clusters with primarily TCP connections this can improve kube-proxy performance by 2x.
This commit is contained in:
@@ -279,6 +279,7 @@ func TestDeleteEndpointConnections(t *testing.T) {
|
||||
svc := proxy.ServicePortName{
|
||||
NamespacedName: types.NamespacedName{Namespace: "ns1", Name: tc.svcName},
|
||||
Port: "p80",
|
||||
Protocol: tc.protocol,
|
||||
}
|
||||
input := []proxy.ServiceEndpoint{
|
||||
{
|
||||
@@ -627,6 +628,7 @@ func TestClusterIPEndpointsJump(t *testing.T) {
|
||||
svcPortName := proxy.ServicePortName{
|
||||
NamespacedName: makeNSN("ns1", "svc1"),
|
||||
Port: "p80",
|
||||
Protocol: v1.ProtocolTCP,
|
||||
}
|
||||
|
||||
makeServiceMap(fp,
|
||||
@@ -648,8 +650,9 @@ func TestClusterIPEndpointsJump(t *testing.T) {
|
||||
IP: epIP,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: svcPortName.Port,
|
||||
Port: int32(svcPort),
|
||||
Name: svcPortName.Port,
|
||||
Port: int32(svcPort),
|
||||
Protocol: v1.ProtocolTCP,
|
||||
}},
|
||||
}}
|
||||
}),
|
||||
@@ -686,6 +689,7 @@ func TestLoadBalancer(t *testing.T) {
|
||||
svcPortName := proxy.ServicePortName{
|
||||
NamespacedName: makeNSN("ns1", "svc1"),
|
||||
Port: "p80",
|
||||
Protocol: v1.ProtocolTCP,
|
||||
}
|
||||
|
||||
makeServiceMap(fp,
|
||||
@@ -712,8 +716,9 @@ func TestLoadBalancer(t *testing.T) {
|
||||
IP: epIP,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: svcPortName.Port,
|
||||
Port: int32(svcPort),
|
||||
Name: svcPortName.Port,
|
||||
Port: int32(svcPort),
|
||||
Protocol: v1.ProtocolTCP,
|
||||
}},
|
||||
}}
|
||||
}),
|
||||
@@ -745,6 +750,7 @@ func TestNodePort(t *testing.T) {
|
||||
svcPortName := proxy.ServicePortName{
|
||||
NamespacedName: makeNSN("ns1", "svc1"),
|
||||
Port: "p80",
|
||||
Protocol: v1.ProtocolTCP,
|
||||
}
|
||||
|
||||
makeServiceMap(fp,
|
||||
@@ -768,8 +774,9 @@ func TestNodePort(t *testing.T) {
|
||||
IP: epIP,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: svcPortName.Port,
|
||||
Port: int32(svcPort),
|
||||
Name: svcPortName.Port,
|
||||
Port: int32(svcPort),
|
||||
Protocol: v1.ProtocolTCP,
|
||||
}},
|
||||
}}
|
||||
}),
|
||||
@@ -890,6 +897,7 @@ func TestOnlyLocalLoadBalancing(t *testing.T) {
|
||||
svcPortName := proxy.ServicePortName{
|
||||
NamespacedName: makeNSN("ns1", "svc1"),
|
||||
Port: "p80",
|
||||
Protocol: v1.ProtocolTCP,
|
||||
}
|
||||
svcSessionAffinityTimeout := int32(10800)
|
||||
|
||||
@@ -929,8 +937,9 @@ func TestOnlyLocalLoadBalancing(t *testing.T) {
|
||||
NodeName: utilpointer.StringPtr(testHostname),
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: svcPortName.Port,
|
||||
Port: int32(svcPort),
|
||||
Name: svcPortName.Port,
|
||||
Port: int32(svcPort),
|
||||
Protocol: v1.ProtocolTCP,
|
||||
}},
|
||||
}}
|
||||
}),
|
||||
@@ -991,6 +1000,7 @@ func onlyLocalNodePorts(t *testing.T, fp *Proxier, ipt *iptablestest.FakeIPTable
|
||||
svcPortName := proxy.ServicePortName{
|
||||
NamespacedName: makeNSN("ns1", "svc1"),
|
||||
Port: "p80",
|
||||
Protocol: v1.ProtocolTCP,
|
||||
}
|
||||
|
||||
makeServiceMap(fp,
|
||||
@@ -1022,8 +1032,9 @@ func onlyLocalNodePorts(t *testing.T, fp *Proxier, ipt *iptablestest.FakeIPTable
|
||||
NodeName: utilpointer.StringPtr(testHostname),
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: svcPortName.Port,
|
||||
Port: int32(svcPort),
|
||||
Name: svcPortName.Port,
|
||||
Port: int32(svcPort),
|
||||
Protocol: v1.ProtocolTCP,
|
||||
}},
|
||||
}}
|
||||
}),
|
||||
@@ -1363,10 +1374,11 @@ func makeNSN(namespace, name string) types.NamespacedName {
|
||||
return types.NamespacedName{Namespace: namespace, Name: name}
|
||||
}
|
||||
|
||||
func makeServicePortName(ns, name, port string) proxy.ServicePortName {
|
||||
func makeServicePortName(ns, name, port string, protocol v1.Protocol) proxy.ServicePortName {
|
||||
return proxy.ServicePortName{
|
||||
NamespacedName: makeNSN(ns, name),
|
||||
Port: port,
|
||||
Protocol: protocol,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1417,7 +1429,8 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
IP: "1.1.1.1",
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Port: 11,
|
||||
Port: 11,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1428,7 +1441,8 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
NodeName: &nodeName,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Port: 11,
|
||||
Port: 11,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1439,8 +1453,9 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
NodeName: &nodeName,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1450,8 +1465,9 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
IP: "1.1.1.1",
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1461,8 +1477,9 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
IP: "1.1.1.1",
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p11-2",
|
||||
Port: 11,
|
||||
Name: "p11-2",
|
||||
Port: 11,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1472,8 +1489,9 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
IP: "1.1.1.1",
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p11",
|
||||
Port: 22,
|
||||
Name: "p11",
|
||||
Port: 22,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1486,11 +1504,13 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
NodeName: &nodeName,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}, {
|
||||
Name: "p12",
|
||||
Port: 12,
|
||||
Name: "p12",
|
||||
Port: 12,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1500,16 +1520,18 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
IP: "1.1.1.1",
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}, {
|
||||
Addresses: []v1.EndpointAddress{{
|
||||
IP: "1.1.1.2",
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p12",
|
||||
Port: 12,
|
||||
Name: "p12",
|
||||
Port: 12,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1519,8 +1541,9 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
IP: "1.1.1.1",
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}, {
|
||||
Addresses: []v1.EndpointAddress{{
|
||||
@@ -1528,8 +1551,9 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
NodeName: &nodeName,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p12",
|
||||
Port: 12,
|
||||
Name: "p12",
|
||||
Port: 12,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1540,19 +1564,22 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
NodeName: &nodeName,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}, {
|
||||
Name: "p12",
|
||||
Port: 12,
|
||||
Name: "p12",
|
||||
Port: 12,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}, {
|
||||
Addresses: []v1.EndpointAddress{{
|
||||
IP: "1.1.1.3",
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p13",
|
||||
Port: 13,
|
||||
Name: "p13",
|
||||
Port: 13,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1565,11 +1592,13 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
NodeName: &nodeName,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}, {
|
||||
Name: "p12",
|
||||
Port: 12,
|
||||
Name: "p12",
|
||||
Port: 12,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}, {
|
||||
Addresses: []v1.EndpointAddress{{
|
||||
@@ -1579,11 +1608,13 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
NodeName: &nodeName,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p13",
|
||||
Port: 13,
|
||||
Name: "p13",
|
||||
Port: 13,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}, {
|
||||
Name: "p14",
|
||||
Port: 14,
|
||||
Name: "p14",
|
||||
Port: 14,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1596,11 +1627,13 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
NodeName: &nodeName,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p21",
|
||||
Port: 21,
|
||||
Name: "p21",
|
||||
Port: 21,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}, {
|
||||
Name: "p22",
|
||||
Port: 22,
|
||||
Name: "p22",
|
||||
Port: 22,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1610,8 +1643,9 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
IP: "1.1.1.1",
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1625,8 +1659,9 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
NodeName: &nodeName,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p22",
|
||||
Port: 22,
|
||||
Name: "p22",
|
||||
Port: 22,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}, {
|
||||
Addresses: []v1.EndpointAddress{{
|
||||
@@ -1634,8 +1669,9 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
NodeName: &nodeName,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p23",
|
||||
Port: 23,
|
||||
Name: "p23",
|
||||
Port: 23,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1649,8 +1685,9 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
NodeName: &nodeName,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p44",
|
||||
Port: 44,
|
||||
Name: "p44",
|
||||
Port: 44,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}, {
|
||||
Addresses: []v1.EndpointAddress{{
|
||||
@@ -1658,8 +1695,9 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
NodeName: &nodeName,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p45",
|
||||
Port: 45,
|
||||
Name: "p45",
|
||||
Port: 45,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1671,19 +1709,22 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
IP: "1.1.1.11",
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Name: "p11",
|
||||
Port: 11,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}, {
|
||||
Addresses: []v1.EndpointAddress{{
|
||||
IP: "1.1.1.2",
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p12",
|
||||
Port: 12,
|
||||
Name: "p12",
|
||||
Port: 12,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}, {
|
||||
Name: "p122",
|
||||
Port: 122,
|
||||
Name: "p122",
|
||||
Port: 122,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1693,8 +1734,9 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
IP: "3.3.3.3",
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p33",
|
||||
Port: 33,
|
||||
Name: "p33",
|
||||
Port: 33,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1705,8 +1747,9 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
NodeName: &nodeName,
|
||||
}},
|
||||
Ports: []v1.EndpointPort{{
|
||||
Name: "p44",
|
||||
Port: 44,
|
||||
Name: "p44",
|
||||
Port: 44,
|
||||
Protocol: v1.ProtocolUDP,
|
||||
}},
|
||||
}}
|
||||
}
|
||||
@@ -1738,12 +1781,12 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
makeTestEndpoints("ns1", "ep1", unnamedPort),
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", ""): {
|
||||
makeServicePortName("ns1", "ep1", "", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", ""): {
|
||||
makeServicePortName("ns1", "ep1", "", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
@@ -1759,12 +1802,12 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
makeTestEndpoints("ns1", "ep1", namedPortLocal),
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: true}},
|
||||
},
|
||||
},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: true}},
|
||||
},
|
||||
},
|
||||
@@ -1782,18 +1825,18 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
makeTestEndpoints("ns1", "ep1", multipleSubsets),
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.2:12", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.2:12", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
@@ -1809,24 +1852,24 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
makeTestEndpoints("ns1", "ep1", multipleSubsetsMultiplePortsLocal),
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:12", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p13"): {
|
||||
makeServicePortName("ns1", "ep1", "p13", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.3:13", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:12", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p13"): {
|
||||
makeServicePortName("ns1", "ep1", "p13", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.3:13", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
@@ -1846,53 +1889,53 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
makeTestEndpoints("ns2", "ep2", multipleSubsetsIPsPorts2),
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.2:11", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:12", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.2:12", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p13"): {
|
||||
makeServicePortName("ns1", "ep1", "p13", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.3:13", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.4:13", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p14"): {
|
||||
makeServicePortName("ns1", "ep1", "p14", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.3:14", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.4:14", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns2", "ep2", "p21"): {
|
||||
makeServicePortName("ns2", "ep2", "p21", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "2.2.2.1:21", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "2.2.2.2:21", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns2", "ep2", "p22"): {
|
||||
makeServicePortName("ns2", "ep2", "p22", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "2.2.2.1:22", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "2.2.2.2:22", IsLocal: true}},
|
||||
},
|
||||
},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.2:11", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:12", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.2:12", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p13"): {
|
||||
makeServicePortName("ns1", "ep1", "p13", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.3:13", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.4:13", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p14"): {
|
||||
makeServicePortName("ns1", "ep1", "p14", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.3:14", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.4:14", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns2", "ep2", "p21"): {
|
||||
makeServicePortName("ns2", "ep2", "p21", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "2.2.2.1:21", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "2.2.2.2:21", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns2", "ep2", "p22"): {
|
||||
makeServicePortName("ns2", "ep2", "p22", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "2.2.2.1:22", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "2.2.2.2:22", IsLocal: true}},
|
||||
},
|
||||
@@ -1913,13 +1956,13 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", ""): {
|
||||
makeServicePortName("ns1", "ep1", "", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: true}},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []proxy.ServiceEndpoint{},
|
||||
expectedStaleServiceNames: map[proxy.ServicePortName]bool{
|
||||
makeServicePortName("ns1", "ep1", ""): true,
|
||||
makeServicePortName("ns1", "ep1", "", v1.ProtocolUDP): true,
|
||||
},
|
||||
expectedHealthchecks: map[types.NamespacedName]int{
|
||||
makeNSN("ns1", "ep1"): 1,
|
||||
@@ -1933,14 +1976,14 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
nil,
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", ""): {
|
||||
makeServicePortName("ns1", "ep1", "", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: true}},
|
||||
},
|
||||
},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{},
|
||||
expectedStaleEndpoints: []proxy.ServiceEndpoint{{
|
||||
Endpoint: "1.1.1.1:11",
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", ""),
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", "", v1.ProtocolUDP),
|
||||
}},
|
||||
expectedStaleServiceNames: map[proxy.ServicePortName]bool{},
|
||||
expectedHealthchecks: map[types.NamespacedName]int{},
|
||||
@@ -1953,23 +1996,23 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
makeTestEndpoints("ns1", "ep1", namedPortsLocalNoLocal),
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.2:11", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:12", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.2:12", IsLocal: true}},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []proxy.ServiceEndpoint{},
|
||||
expectedStaleServiceNames: map[proxy.ServicePortName]bool{
|
||||
makeServicePortName("ns1", "ep1", "p12"): true,
|
||||
makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP): true,
|
||||
},
|
||||
expectedHealthchecks: map[types.NamespacedName]int{
|
||||
makeNSN("ns1", "ep1"): 1,
|
||||
@@ -1983,29 +2026,29 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
makeTestEndpoints("ns1", "ep1", namedPort),
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.2:11", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:12", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.2:12", IsLocal: true}},
|
||||
},
|
||||
},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []proxy.ServiceEndpoint{{
|
||||
Endpoint: "1.1.1.2:11",
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", "p11"),
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP),
|
||||
}, {
|
||||
Endpoint: "1.1.1.1:12",
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", "p12"),
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP),
|
||||
}, {
|
||||
Endpoint: "1.1.1.2:12",
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", "p12"),
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP),
|
||||
}},
|
||||
expectedStaleServiceNames: map[proxy.ServicePortName]bool{},
|
||||
expectedHealthchecks: map[types.NamespacedName]int{},
|
||||
@@ -2018,21 +2061,21 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
makeTestEndpoints("ns1", "ep1", multipleSubsetsWithLocal),
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.2:12", IsLocal: true}},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []proxy.ServiceEndpoint{},
|
||||
expectedStaleServiceNames: map[proxy.ServicePortName]bool{
|
||||
makeServicePortName("ns1", "ep1", "p12"): true,
|
||||
makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP): true,
|
||||
},
|
||||
expectedHealthchecks: map[types.NamespacedName]int{
|
||||
makeNSN("ns1", "ep1"): 1,
|
||||
@@ -2046,21 +2089,21 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
makeTestEndpoints("ns1", "ep1", namedPort),
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.2:12", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []proxy.ServiceEndpoint{{
|
||||
Endpoint: "1.1.1.2:12",
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", "p12"),
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP),
|
||||
}},
|
||||
expectedStaleServiceNames: map[proxy.ServicePortName]bool{},
|
||||
expectedHealthchecks: map[types.NamespacedName]int{},
|
||||
@@ -2073,21 +2116,21 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
makeTestEndpoints("ns1", "ep1", namedPortRenamed),
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11-2"): {
|
||||
makeServicePortName("ns1", "ep1", "p11-2", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []proxy.ServiceEndpoint{{
|
||||
Endpoint: "1.1.1.1:11",
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", "p11"),
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP),
|
||||
}},
|
||||
expectedStaleServiceNames: map[proxy.ServicePortName]bool{
|
||||
makeServicePortName("ns1", "ep1", "p11-2"): true,
|
||||
makeServicePortName("ns1", "ep1", "p11-2", v1.ProtocolUDP): true,
|
||||
},
|
||||
expectedHealthchecks: map[types.NamespacedName]int{},
|
||||
}, {
|
||||
@@ -2099,18 +2142,18 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
makeTestEndpoints("ns1", "ep1", namedPortRenumbered),
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:22", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []proxy.ServiceEndpoint{{
|
||||
Endpoint: "1.1.1.1:11",
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", "p11"),
|
||||
ServicePortName: makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP),
|
||||
}},
|
||||
expectedStaleServiceNames: map[proxy.ServicePortName]bool{},
|
||||
expectedHealthchecks: map[types.NamespacedName]int{},
|
||||
@@ -2129,62 +2172,62 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
makeTestEndpoints("ns4", "ep4", complexAfter4),
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
makeServicePortName("ns2", "ep2", "p22"): {
|
||||
makeServicePortName("ns2", "ep2", "p22", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "2.2.2.2:22", IsLocal: true}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "2.2.2.22:22", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns2", "ep2", "p23"): {
|
||||
makeServicePortName("ns2", "ep2", "p23", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "2.2.2.3:23", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns4", "ep4", "p44"): {
|
||||
makeServicePortName("ns4", "ep4", "p44", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "4.4.4.4:44", IsLocal: true}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "4.4.4.5:44", IsLocal: true}},
|
||||
},
|
||||
makeServicePortName("ns4", "ep4", "p45"): {
|
||||
makeServicePortName("ns4", "ep4", "p45", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "4.4.4.6:45", IsLocal: true}},
|
||||
},
|
||||
},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", "p11"): {
|
||||
makeServicePortName("ns1", "ep1", "p11", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.11:11", IsLocal: false}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p12"): {
|
||||
makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.2:12", IsLocal: false}},
|
||||
},
|
||||
makeServicePortName("ns1", "ep1", "p122"): {
|
||||
makeServicePortName("ns1", "ep1", "p122", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.2:122", IsLocal: false}},
|
||||
},
|
||||
makeServicePortName("ns3", "ep3", "p33"): {
|
||||
makeServicePortName("ns3", "ep3", "p33", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "3.3.3.3:33", IsLocal: false}},
|
||||
},
|
||||
makeServicePortName("ns4", "ep4", "p44"): {
|
||||
makeServicePortName("ns4", "ep4", "p44", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "4.4.4.4:44", IsLocal: true}},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []proxy.ServiceEndpoint{{
|
||||
Endpoint: "2.2.2.2:22",
|
||||
ServicePortName: makeServicePortName("ns2", "ep2", "p22"),
|
||||
ServicePortName: makeServicePortName("ns2", "ep2", "p22", v1.ProtocolUDP),
|
||||
}, {
|
||||
Endpoint: "2.2.2.22:22",
|
||||
ServicePortName: makeServicePortName("ns2", "ep2", "p22"),
|
||||
ServicePortName: makeServicePortName("ns2", "ep2", "p22", v1.ProtocolUDP),
|
||||
}, {
|
||||
Endpoint: "2.2.2.3:23",
|
||||
ServicePortName: makeServicePortName("ns2", "ep2", "p23"),
|
||||
ServicePortName: makeServicePortName("ns2", "ep2", "p23", v1.ProtocolUDP),
|
||||
}, {
|
||||
Endpoint: "4.4.4.5:44",
|
||||
ServicePortName: makeServicePortName("ns4", "ep4", "p44"),
|
||||
ServicePortName: makeServicePortName("ns4", "ep4", "p44", v1.ProtocolUDP),
|
||||
}, {
|
||||
Endpoint: "4.4.4.6:45",
|
||||
ServicePortName: makeServicePortName("ns4", "ep4", "p45"),
|
||||
ServicePortName: makeServicePortName("ns4", "ep4", "p45", v1.ProtocolUDP),
|
||||
}},
|
||||
expectedStaleServiceNames: map[proxy.ServicePortName]bool{
|
||||
makeServicePortName("ns1", "ep1", "p12"): true,
|
||||
makeServicePortName("ns1", "ep1", "p122"): true,
|
||||
makeServicePortName("ns3", "ep3", "p33"): true,
|
||||
makeServicePortName("ns1", "ep1", "p12", v1.ProtocolUDP): true,
|
||||
makeServicePortName("ns1", "ep1", "p122", v1.ProtocolUDP): true,
|
||||
makeServicePortName("ns3", "ep3", "p33", v1.ProtocolUDP): true,
|
||||
},
|
||||
expectedHealthchecks: map[types.NamespacedName]int{
|
||||
makeNSN("ns4", "ep4"): 1,
|
||||
@@ -2199,13 +2242,13 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
},
|
||||
oldEndpoints: map[proxy.ServicePortName][]*endpointsInfo{},
|
||||
expectedResult: map[proxy.ServicePortName][]*endpointsInfo{
|
||||
makeServicePortName("ns1", "ep1", ""): {
|
||||
makeServicePortName("ns1", "ep1", "", v1.ProtocolUDP): {
|
||||
{BaseEndpointInfo: &proxy.BaseEndpointInfo{Endpoint: "1.1.1.1:11", IsLocal: false}},
|
||||
},
|
||||
},
|
||||
expectedStaleEndpoints: []proxy.ServiceEndpoint{},
|
||||
expectedStaleServiceNames: map[proxy.ServicePortName]bool{
|
||||
makeServicePortName("ns1", "ep1", ""): true,
|
||||
makeServicePortName("ns1", "ep1", "", v1.ProtocolUDP): true,
|
||||
},
|
||||
expectedHealthchecks: map[types.NamespacedName]int{},
|
||||
},
|
||||
@@ -2285,29 +2328,6 @@ func Test_updateEndpointsMap(t *testing.T) {
|
||||
// the shared EndpointChangeTracker and EndpointSliceCache. This test ensures that the
|
||||
// iptables proxier supports translating EndpointSlices to iptables output.
|
||||
func TestEndpointSliceE2E(t *testing.T) {
|
||||
expectedIPTablesWithoutSlice := `*filter
|
||||
:KUBE-SERVICES - [0:0]
|
||||
:KUBE-EXTERNAL-SERVICES - [0:0]
|
||||
:KUBE-FORWARD - [0:0]
|
||||
-A KUBE-SERVICES -m comment --comment "ns1/svc1: has no endpoints" -m -p -d 172.20.1.1/32 --dport 0 -j REJECT
|
||||
-A KUBE-FORWARD -m conntrack --ctstate INVALID -j DROP
|
||||
-A KUBE-FORWARD -m comment --comment "kubernetes forwarding rules" -m mark --mark -j ACCEPT
|
||||
-A KUBE-FORWARD -s 10.0.0.0/24 -m comment --comment "kubernetes forwarding conntrack pod source rule" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||||
-A KUBE-FORWARD -m comment --comment "kubernetes forwarding conntrack pod destination rule" -d 10.0.0.0/24 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||||
COMMIT
|
||||
*nat
|
||||
:KUBE-SERVICES - [0:0]
|
||||
:KUBE-NODEPORTS - [0:0]
|
||||
:KUBE-POSTROUTING - [0:0]
|
||||
:KUBE-MARK-MASQ - [0:0]
|
||||
:KUBE-SVC-3WUAALNGPYZZAWAD - [0:0]
|
||||
-A KUBE-POSTROUTING -m comment --comment "kubernetes service traffic requiring SNAT" -m mark --mark -j MASQUERADE
|
||||
-A KUBE-MARK-MASQ -j MARK --set-xmark
|
||||
-X KUBE-SVC-3WUAALNGPYZZAWAD
|
||||
-A KUBE-SERVICES -m comment --comment "kubernetes service nodeports; NOTE: this must be the last rule in this chain" -m addrtype --dst-type LOCAL -j KUBE-NODEPORTS
|
||||
COMMIT
|
||||
`
|
||||
|
||||
expectedIPTablesWithSlice := `*filter
|
||||
:KUBE-SERVICES - [0:0]
|
||||
:KUBE-EXTERNAL-SERVICES - [0:0]
|
||||
@@ -2322,23 +2342,23 @@ COMMIT
|
||||
:KUBE-NODEPORTS - [0:0]
|
||||
:KUBE-POSTROUTING - [0:0]
|
||||
:KUBE-MARK-MASQ - [0:0]
|
||||
:KUBE-SVC-3WUAALNGPYZZAWAD - [0:0]
|
||||
: - [0:0]
|
||||
: - [0:0]
|
||||
: - [0:0]
|
||||
:KUBE-SVC-AHZNAGK3SCETOS2T - [0:0]
|
||||
:KUBE-SEP-PXD6POUVGD2I37UY - [0:0]
|
||||
:KUBE-SEP-SOKZUIT7SCEVIP33 - [0:0]
|
||||
:KUBE-SEP-WVE3FAB34S7NZGDJ - [0:0]
|
||||
-A KUBE-POSTROUTING -m comment --comment "kubernetes service traffic requiring SNAT" -m mark --mark -j MASQUERADE
|
||||
-A KUBE-MARK-MASQ -j MARK --set-xmark
|
||||
-A KUBE-SERVICES -m comment --comment "ns1/svc1: cluster IP" -m -p -d 172.20.1.1/32 --dport 0 ! -s 10.0.0.0/24 -j KUBE-MARK-MASQ
|
||||
-A KUBE-SERVICES -m comment --comment "ns1/svc1: cluster IP" -m -p -d 172.20.1.1/32 --dport 0 -j KUBE-SVC-3WUAALNGPYZZAWAD
|
||||
-A KUBE-SVC-3WUAALNGPYZZAWAD -m statistic --mode random --probability 0.33333 -j
|
||||
-A -s 10.0.1.1/32 -j KUBE-MARK-MASQ
|
||||
-A -m -p -j DNAT --to-destination 10.0.1.1:80
|
||||
-A KUBE-SVC-3WUAALNGPYZZAWAD -m statistic --mode random --probability 0.50000 -j
|
||||
-A -s 10.0.1.2/32 -j KUBE-MARK-MASQ
|
||||
-A -m -p -j DNAT --to-destination 10.0.1.2:80
|
||||
-A KUBE-SVC-3WUAALNGPYZZAWAD -j
|
||||
-A -s 10.0.1.3/32 -j KUBE-MARK-MASQ
|
||||
-A -m -p -j DNAT --to-destination 10.0.1.3:80
|
||||
-A KUBE-SERVICES -m comment --comment "ns1/svc1: cluster IP" -m tcp -p tcp -d 172.20.1.1/32 --dport 0 ! -s 10.0.0.0/24 -j KUBE-MARK-MASQ
|
||||
-A KUBE-SERVICES -m comment --comment "ns1/svc1: cluster IP" -m tcp -p tcp -d 172.20.1.1/32 --dport 0 -j KUBE-SVC-AHZNAGK3SCETOS2T
|
||||
-A KUBE-SVC-AHZNAGK3SCETOS2T -m statistic --mode random --probability 0.33333 -j KUBE-SEP-PXD6POUVGD2I37UY
|
||||
-A KUBE-SEP-PXD6POUVGD2I37UY -s 10.0.1.1/32 -j KUBE-MARK-MASQ
|
||||
-A KUBE-SEP-PXD6POUVGD2I37UY -m tcp -p tcp -j DNAT --to-destination 10.0.1.1:80
|
||||
-A KUBE-SVC-AHZNAGK3SCETOS2T -m statistic --mode random --probability 0.50000 -j KUBE-SEP-SOKZUIT7SCEVIP33
|
||||
-A KUBE-SEP-SOKZUIT7SCEVIP33 -s 10.0.1.2/32 -j KUBE-MARK-MASQ
|
||||
-A KUBE-SEP-SOKZUIT7SCEVIP33 -m tcp -p tcp -j DNAT --to-destination 10.0.1.2:80
|
||||
-A KUBE-SVC-AHZNAGK3SCETOS2T -j KUBE-SEP-WVE3FAB34S7NZGDJ
|
||||
-A KUBE-SEP-WVE3FAB34S7NZGDJ -s 10.0.1.3/32 -j KUBE-MARK-MASQ
|
||||
-A KUBE-SEP-WVE3FAB34S7NZGDJ -m tcp -p tcp -j DNAT --to-destination 10.0.1.3:80
|
||||
-A KUBE-SERVICES -m comment --comment "kubernetes service nodeports; NOTE: this must be the last rule in this chain" -m addrtype --dst-type LOCAL -j KUBE-NODEPORTS
|
||||
COMMIT
|
||||
`
|
||||
@@ -2357,11 +2377,12 @@ COMMIT
|
||||
Spec: v1.ServiceSpec{
|
||||
ClusterIP: "172.20.1.1",
|
||||
Selector: map[string]string{"foo": "bar"},
|
||||
Ports: []v1.ServicePort{{Name: "", TargetPort: intstr.FromInt(80)}},
|
||||
Ports: []v1.ServicePort{{Name: "", TargetPort: intstr.FromInt(80), Protocol: v1.ProtocolTCP}},
|
||||
},
|
||||
})
|
||||
|
||||
ipAddressType := discovery.AddressTypeIP
|
||||
tcpProtocol := v1.ProtocolTCP
|
||||
endpointSlice := &discovery.EndpointSlice{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: fmt.Sprintf("%s-1", serviceName),
|
||||
@@ -2369,8 +2390,9 @@ COMMIT
|
||||
Labels: map[string]string{discovery.LabelServiceName: serviceName},
|
||||
},
|
||||
Ports: []discovery.EndpointPort{{
|
||||
Name: utilpointer.StringPtr(""),
|
||||
Port: utilpointer.Int32Ptr(80),
|
||||
Name: utilpointer.StringPtr(""),
|
||||
Port: utilpointer.Int32Ptr(80),
|
||||
Protocol: &tcpProtocol,
|
||||
}},
|
||||
AddressType: &ipAddressType,
|
||||
Endpoints: []discovery.Endpoint{{
|
||||
@@ -2394,7 +2416,7 @@ COMMIT
|
||||
|
||||
fp.OnEndpointSliceDelete(endpointSlice)
|
||||
fp.syncProxyRules()
|
||||
assert.Equal(t, expectedIPTablesWithoutSlice, fp.iptablesData.String())
|
||||
assert.NotEqual(t, expectedIPTablesWithSlice, fp.iptablesData.String())
|
||||
}
|
||||
|
||||
// TODO(thockin): add *more* tests for syncProxyRules() or break it down further and test the pieces.
|
||||
|
||||
Reference in New Issue
Block a user