mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 19:23:40 +00:00
proxy: cleanup UpdateServiceMapResult
Signed-off-by: Daman Arora <aroradaman@gmail.com>
This commit is contained in:
parent
c398af07fa
commit
6657d220d3
@ -2966,16 +2966,11 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
|
||||
for i := range services {
|
||||
fp.OnServiceAdd(services[i])
|
||||
}
|
||||
result := fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 10 {
|
||||
t.Errorf("expected service map length 10, got %v", fp.svcPortMap)
|
||||
}
|
||||
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
// Services only added, so nothing stale yet
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
|
||||
// The only-local-loadbalancer ones get added
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 1 {
|
||||
@ -3000,24 +2995,11 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
|
||||
fp.OnServiceDelete(services[2])
|
||||
fp.OnServiceDelete(services[3])
|
||||
|
||||
result = fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 1 {
|
||||
t.Errorf("expected service map length 1, got %v", fp.svcPortMap)
|
||||
}
|
||||
|
||||
// All services but one were deleted. While you'd expect only the ClusterIPs
|
||||
// from the three deleted services here, we still have the ClusterIP for
|
||||
// the not-deleted service, because one of it's ServicePorts was deleted.
|
||||
expectedStaleUDPServices := []string{"172.30.55.10", "172.30.55.4", "172.30.55.11", "172.30.55.12"}
|
||||
if len(result.DeletedUDPClusterIPs) != len(expectedStaleUDPServices) {
|
||||
t.Errorf("expected stale UDP services length %d, got %v", len(expectedStaleUDPServices), result.DeletedUDPClusterIPs.UnsortedList())
|
||||
}
|
||||
for _, ip := range expectedStaleUDPServices {
|
||||
if !result.DeletedUDPClusterIPs.Has(ip) {
|
||||
t.Errorf("expected stale UDP service service %s", ip)
|
||||
}
|
||||
}
|
||||
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
t.Errorf("expected 0 healthcheck ports, got %v", healthCheckNodePorts)
|
||||
@ -3041,15 +3023,11 @@ func TestBuildServiceMapServiceHeadless(t *testing.T) {
|
||||
)
|
||||
|
||||
// Headless service should be ignored
|
||||
result := fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 0 {
|
||||
t.Errorf("expected service map length 0, got %d", len(fp.svcPortMap))
|
||||
}
|
||||
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
|
||||
// No proxied services, so no healthchecks
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
@ -3070,13 +3048,10 @@ func TestBuildServiceMapServiceTypeExternalName(t *testing.T) {
|
||||
}),
|
||||
)
|
||||
|
||||
result := fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 0 {
|
||||
t.Errorf("expected service map length 0, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs)
|
||||
}
|
||||
// No proxied services, so no healthchecks
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
@ -3111,14 +3086,10 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
|
||||
fp.OnServiceAdd(servicev1)
|
||||
|
||||
result := fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 2 {
|
||||
t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
// Services only added, so nothing stale yet
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
t.Errorf("expected healthcheck ports length 0, got %v", healthCheckNodePorts)
|
||||
@ -3126,13 +3097,10 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
|
||||
// Change service to load-balancer
|
||||
fp.OnServiceUpdate(servicev1, servicev2)
|
||||
result = fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 2 {
|
||||
t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs.UnsortedList())
|
||||
}
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 1 {
|
||||
t.Errorf("expected healthcheck ports length 1, got %v", healthCheckNodePorts)
|
||||
@ -3141,13 +3109,10 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
// No change; make sure the service map stays the same and there are
|
||||
// no health-check changes
|
||||
fp.OnServiceUpdate(servicev2, servicev2)
|
||||
result = fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 2 {
|
||||
t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs.UnsortedList())
|
||||
}
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 1 {
|
||||
t.Errorf("expected healthcheck ports length 1, got %v", healthCheckNodePorts)
|
||||
@ -3155,14 +3120,10 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
|
||||
// And back to ClusterIP
|
||||
fp.OnServiceUpdate(servicev2, servicev1)
|
||||
result = fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 2 {
|
||||
t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
// Services only added, so nothing stale yet
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
t.Errorf("expected healthcheck ports length 0, got %v", healthCheckNodePorts)
|
||||
|
@ -2517,16 +2517,11 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
|
||||
for i := range services {
|
||||
fp.OnServiceAdd(services[i])
|
||||
}
|
||||
result := fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 12 {
|
||||
t.Errorf("expected service map length 12, got %v", fp.svcPortMap)
|
||||
}
|
||||
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
// Services only added, so nothing stale yet
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
|
||||
// The only-local-loadbalancer ones get added
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 1 {
|
||||
@ -2551,24 +2546,10 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
|
||||
fp.OnServiceDelete(services[2])
|
||||
fp.OnServiceDelete(services[3])
|
||||
|
||||
result = fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 1 {
|
||||
t.Errorf("expected service map length 1, got %v", fp.svcPortMap)
|
||||
}
|
||||
|
||||
// All services but one were deleted. While you'd expect only the ClusterIPs
|
||||
// from the three deleted services here, we still have the ClusterIP for
|
||||
// the not-deleted service, because one of it's ServicePorts was deleted.
|
||||
expectedStaleUDPServices := []string{"172.16.55.10", "172.16.55.4", "172.16.55.11", "172.16.55.12"}
|
||||
if len(result.DeletedUDPClusterIPs) != len(expectedStaleUDPServices) {
|
||||
t.Errorf("expected stale UDP services length %d, got %v", len(expectedStaleUDPServices), result.DeletedUDPClusterIPs.UnsortedList())
|
||||
}
|
||||
for _, ip := range expectedStaleUDPServices {
|
||||
if !result.DeletedUDPClusterIPs.Has(ip) {
|
||||
t.Errorf("expected stale UDP service service %s", ip)
|
||||
}
|
||||
}
|
||||
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
t.Errorf("expected 0 healthcheck ports, got %v", healthCheckNodePorts)
|
||||
@ -2600,15 +2581,11 @@ func TestBuildServiceMapServiceHeadless(t *testing.T) {
|
||||
)
|
||||
|
||||
// Headless service should be ignored
|
||||
result := fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 0 {
|
||||
t.Errorf("expected service map length 0, got %d", len(fp.svcPortMap))
|
||||
}
|
||||
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
|
||||
// No proxied services, so no healthchecks
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
@ -2632,13 +2609,10 @@ func TestBuildServiceMapServiceTypeExternalName(t *testing.T) {
|
||||
}),
|
||||
)
|
||||
|
||||
result := fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 0 {
|
||||
t.Errorf("expected service map length 0, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs)
|
||||
}
|
||||
|
||||
// No proxied services, so no healthchecks
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
@ -2677,15 +2651,10 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
|
||||
fp.OnServiceAdd(servicev1)
|
||||
|
||||
result := fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 2 {
|
||||
t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
// Services only added, so nothing stale yet
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
t.Errorf("expected healthcheck ports length 0, got %v", healthCheckNodePorts)
|
||||
@ -2693,13 +2662,10 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
|
||||
// Change service to load-balancer
|
||||
fp.OnServiceUpdate(servicev1, servicev2)
|
||||
result = fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 2 {
|
||||
t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs.UnsortedList())
|
||||
}
|
||||
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 1 {
|
||||
@ -2709,13 +2675,10 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
// No change; make sure the service map stays the same and there are
|
||||
// no health-check changes
|
||||
fp.OnServiceUpdate(servicev2, servicev2)
|
||||
result = fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 2 {
|
||||
t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs.UnsortedList())
|
||||
}
|
||||
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 1 {
|
||||
@ -2724,14 +2687,10 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
|
||||
// And back to ClusterIP
|
||||
fp.OnServiceUpdate(servicev2, servicev1)
|
||||
result = fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 2 {
|
||||
t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
// Services only added, so nothing stale yet
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
|
@ -1374,16 +1374,11 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
|
||||
for i := range services {
|
||||
fp.OnServiceAdd(services[i])
|
||||
}
|
||||
result := fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 10 {
|
||||
t.Errorf("expected service map length 10, got %v", fp.svcPortMap)
|
||||
}
|
||||
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
// Services only added, so nothing stale yet
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
|
||||
// The only-local-loadbalancer ones get added
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 1 {
|
||||
@ -1408,24 +1403,11 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
|
||||
fp.OnServiceDelete(services[2])
|
||||
fp.OnServiceDelete(services[3])
|
||||
|
||||
result = fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 1 {
|
||||
t.Errorf("expected service map length 1, got %v", fp.svcPortMap)
|
||||
}
|
||||
|
||||
// All services but one were deleted. While you'd expect only the ClusterIPs
|
||||
// from the three deleted services here, we still have the ClusterIP for
|
||||
// the not-deleted service, because one of it's ServicePorts was deleted.
|
||||
expectedStaleUDPServices := []string{"172.30.55.10", "172.30.55.4", "172.30.55.11", "172.30.55.12"}
|
||||
if len(result.DeletedUDPClusterIPs) != len(expectedStaleUDPServices) {
|
||||
t.Errorf("expected stale UDP services length %d, got %v", len(expectedStaleUDPServices), result.DeletedUDPClusterIPs.UnsortedList())
|
||||
}
|
||||
for _, ip := range expectedStaleUDPServices {
|
||||
if !result.DeletedUDPClusterIPs.Has(ip) {
|
||||
t.Errorf("expected stale UDP service service %s", ip)
|
||||
}
|
||||
}
|
||||
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
t.Errorf("expected 0 healthcheck ports, got %v", healthCheckNodePorts)
|
||||
@ -1448,15 +1430,11 @@ func TestBuildServiceMapServiceHeadless(t *testing.T) {
|
||||
)
|
||||
|
||||
// Headless service should be ignored
|
||||
result := fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 0 {
|
||||
t.Errorf("expected service map length 0, got %d", len(fp.svcPortMap))
|
||||
}
|
||||
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
|
||||
// No proxied services, so no healthchecks
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
@ -1476,13 +1454,10 @@ func TestBuildServiceMapServiceTypeExternalName(t *testing.T) {
|
||||
}),
|
||||
)
|
||||
|
||||
result := fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 0 {
|
||||
t.Errorf("expected service map length 0, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs)
|
||||
}
|
||||
// No proxied services, so no healthchecks
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
@ -1516,14 +1491,10 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
|
||||
fp.OnServiceAdd(servicev1)
|
||||
|
||||
result := fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 2 {
|
||||
t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
// Services only added, so nothing stale yet
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
t.Errorf("expected healthcheck ports length 0, got %v", healthCheckNodePorts)
|
||||
@ -1531,13 +1502,10 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
|
||||
// Change service to load-balancer
|
||||
fp.OnServiceUpdate(servicev1, servicev2)
|
||||
result = fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 2 {
|
||||
t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs.UnsortedList())
|
||||
}
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 1 {
|
||||
t.Errorf("expected healthcheck ports length 1, got %v", healthCheckNodePorts)
|
||||
@ -1546,13 +1514,10 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
// No change; make sure the service map stays the same and there are
|
||||
// no health-check changes
|
||||
fp.OnServiceUpdate(servicev2, servicev2)
|
||||
result = fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 2 {
|
||||
t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs.UnsortedList())
|
||||
}
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 1 {
|
||||
t.Errorf("expected healthcheck ports length 1, got %v", healthCheckNodePorts)
|
||||
@ -1560,14 +1525,10 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
|
||||
// And back to ClusterIP
|
||||
fp.OnServiceUpdate(servicev2, servicev1)
|
||||
result = fp.svcPortMap.Update(fp.serviceChanges)
|
||||
fp.svcPortMap.Update(fp.serviceChanges)
|
||||
if len(fp.svcPortMap) != 2 {
|
||||
t.Errorf("expected service map length 2, got %v", fp.svcPortMap)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
// Services only added, so nothing stale yet
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
t.Errorf("expected healthcheck ports length 0, got %v", healthCheckNodePorts)
|
||||
|
@ -117,11 +117,6 @@ type UpdateServiceMapResult struct {
|
||||
// UpdatedServices lists the names of all services added/updated/deleted since the
|
||||
// last Update.
|
||||
UpdatedServices sets.Set[types.NamespacedName]
|
||||
|
||||
// DeletedUDPClusterIPs holds stale (no longer assigned to a Service) Service IPs
|
||||
// that had UDP ports. Callers can use this to abort timeout-waits or clear
|
||||
// connection-tracking information.
|
||||
DeletedUDPClusterIPs sets.Set[string]
|
||||
}
|
||||
|
||||
// HealthCheckNodePorts returns a map of Service names to HealthCheckNodePort values
|
||||
@ -178,8 +173,7 @@ func (sm ServicePortMap) Update(sct *ServiceChangeTracker) UpdateServiceMapResul
|
||||
defer sct.lock.Unlock()
|
||||
|
||||
result := UpdateServiceMapResult{
|
||||
UpdatedServices: sets.New[types.NamespacedName](),
|
||||
DeletedUDPClusterIPs: sets.New[string](),
|
||||
UpdatedServices: sets.New[types.NamespacedName](),
|
||||
}
|
||||
|
||||
for nn, change := range sct.items {
|
||||
@ -192,7 +186,7 @@ func (sm ServicePortMap) Update(sct *ServiceChangeTracker) UpdateServiceMapResul
|
||||
// filter out the Update event of current changes from previous changes
|
||||
// before calling unmerge() so that can skip deleting the Update events.
|
||||
change.previous.filter(change.current)
|
||||
sm.unmerge(change.previous, result.DeletedUDPClusterIPs)
|
||||
sm.unmerge(change.previous)
|
||||
}
|
||||
// clear changes after applying them to ServicePortMap.
|
||||
sct.items = make(map[types.NamespacedName]*serviceChange)
|
||||
@ -226,16 +220,12 @@ func (sm *ServicePortMap) filter(other ServicePortMap) {
|
||||
}
|
||||
}
|
||||
|
||||
// unmerge deletes all other ServicePortMap's elements from current ServicePortMap and
|
||||
// updates deletedUDPClusterIPs with all of the newly-deleted UDP cluster IPs.
|
||||
func (sm *ServicePortMap) unmerge(other ServicePortMap, deletedUDPClusterIPs sets.Set[string]) {
|
||||
// unmerge deletes all other ServicePortMap's elements from current ServicePortMap.
|
||||
func (sm *ServicePortMap) unmerge(other ServicePortMap) {
|
||||
for svcPortName := range other {
|
||||
info, exists := (*sm)[svcPortName]
|
||||
_, exists := (*sm)[svcPortName]
|
||||
if exists {
|
||||
klog.V(4).InfoS("Removing service port", "portName", svcPortName)
|
||||
if info.Protocol() == v1.ProtocolUDP {
|
||||
deletedUDPClusterIPs.Insert(info.ClusterIP().String())
|
||||
}
|
||||
delete(*sm, svcPortName)
|
||||
} else {
|
||||
klog.ErrorS(nil, "Service port does not exists", "portName", svcPortName)
|
||||
|
@ -680,9 +680,6 @@ func TestServiceMapUpdateHeadless(t *testing.T) {
|
||||
if len(result.UpdatedServices) != 0 {
|
||||
t.Errorf("expected 0 updated services, got %d", len(result.UpdatedServices))
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
|
||||
// No proxied services, so no healthchecks
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
@ -710,9 +707,6 @@ func TestUpdateServiceTypeExternalName(t *testing.T) {
|
||||
if len(result.UpdatedServices) != 0 {
|
||||
t.Errorf("expected 0 updated services, got %v", result.UpdatedServices)
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs)
|
||||
}
|
||||
|
||||
// No proxied services, so no healthchecks
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
@ -782,10 +776,6 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
|
||||
if len(result.UpdatedServices) != len(services) {
|
||||
t.Errorf("expected %d updated services, got %d", len(services), len(result.UpdatedServices))
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
// Services only added, so nothing stale yet
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
|
||||
// The only-local-loadbalancer ones get added
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
@ -823,19 +813,6 @@ func TestBuildServiceMapAddRemove(t *testing.T) {
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
t.Errorf("expected 0 healthcheck ports, got %v", healthCheckNodePorts)
|
||||
}
|
||||
|
||||
// All services but one were deleted. While you'd expect only the ClusterIPs
|
||||
// from the three deleted services here, we still have the ClusterIP for
|
||||
// the not-deleted service, because one of it's ServicePorts was deleted.
|
||||
expectedDeletedUDPClusterIPs := []string{"172.16.55.10", "172.16.55.4", "172.16.55.11", "172.16.55.12"}
|
||||
if len(result.DeletedUDPClusterIPs) != len(expectedDeletedUDPClusterIPs) {
|
||||
t.Errorf("expected stale UDP services length %d, got %v", len(expectedDeletedUDPClusterIPs), result.DeletedUDPClusterIPs.UnsortedList())
|
||||
}
|
||||
for _, ip := range expectedDeletedUDPClusterIPs {
|
||||
if !result.DeletedUDPClusterIPs.Has(ip) {
|
||||
t.Errorf("expected stale UDP service service %s", ip)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
@ -871,10 +848,6 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
if len(result.UpdatedServices) != 1 {
|
||||
t.Errorf("expected 1 updated service, got %d", len(result.UpdatedServices))
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
// Services only added, so nothing stale yet
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
|
||||
healthCheckNodePorts := fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
@ -890,9 +863,6 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
if len(result.UpdatedServices) != 1 {
|
||||
t.Errorf("expected 1 updated service, got %d", len(result.UpdatedServices))
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs.UnsortedList())
|
||||
}
|
||||
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 1 {
|
||||
@ -909,9 +879,6 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
if len(result.UpdatedServices) != 0 {
|
||||
t.Errorf("expected 0 updated services, got %d", len(result.UpdatedServices))
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
t.Errorf("expected stale UDP services length 0, got %v", result.DeletedUDPClusterIPs.UnsortedList())
|
||||
}
|
||||
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 1 {
|
||||
@ -927,10 +894,6 @@ func TestBuildServiceMapServiceUpdate(t *testing.T) {
|
||||
if len(result.UpdatedServices) != 1 {
|
||||
t.Errorf("expected 1 updated service, got %d", len(result.UpdatedServices))
|
||||
}
|
||||
if len(result.DeletedUDPClusterIPs) != 0 {
|
||||
// Services only added, so nothing stale yet
|
||||
t.Errorf("expected stale UDP services length 0, got %d", len(result.DeletedUDPClusterIPs))
|
||||
}
|
||||
|
||||
healthCheckNodePorts = fp.svcPortMap.HealthCheckNodePorts()
|
||||
if len(healthCheckNodePorts) != 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user