mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-31 10:18:13 +00:00 
			
		
		
		
	Updating kube-proxy to ignore unready endpoints for Topology Hints
This commit is contained in:
		| @@ -68,6 +68,9 @@ func filterEndpointsWithHints(endpoints []Endpoint, hintsAnnotation string, node | ||||
| 	filteredEndpoints := []Endpoint{} | ||||
|  | ||||
| 	for _, endpoint := range endpoints { | ||||
| 		if !endpoint.IsReady() { | ||||
| 			continue | ||||
| 		} | ||||
| 		if endpoint.GetZoneHints().Len() == 0 { | ||||
| 			klog.InfoS("Skipping topology aware endpoint filtering since one or more endpoints is missing a zone hint") | ||||
| 			return endpoints | ||||
|   | ||||
| @@ -31,6 +31,7 @@ func TestFilterEndpoints(t *testing.T) { | ||||
| 	type endpoint struct { | ||||
| 		ip        string | ||||
| 		zoneHints sets.String | ||||
| 		unready   bool | ||||
| 	} | ||||
| 	testCases := []struct { | ||||
| 		name              string | ||||
| @@ -138,12 +139,12 @@ func TestFilterEndpoints(t *testing.T) { | ||||
|  | ||||
| 			endpoints := []Endpoint{} | ||||
| 			for _, ep := range tc.endpoints { | ||||
| 				endpoints = append(endpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints}) | ||||
| 				endpoints = append(endpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints, Ready: !ep.unready}) | ||||
| 			} | ||||
|  | ||||
| 			expectedEndpoints := []Endpoint{} | ||||
| 			for _, ep := range tc.expectedEndpoints { | ||||
| 				expectedEndpoints = append(expectedEndpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints}) | ||||
| 				expectedEndpoints = append(expectedEndpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints, Ready: !ep.unready}) | ||||
| 			} | ||||
|  | ||||
| 			filteredEndpoints := FilterEndpoints(endpoints, tc.serviceInfo, tc.nodeLabels) | ||||
| @@ -161,6 +162,7 @@ func Test_filterEndpointsWithHints(t *testing.T) { | ||||
| 	type endpoint struct { | ||||
| 		ip        string | ||||
| 		zoneHints sets.String | ||||
| 		unready   bool | ||||
| 	} | ||||
| 	testCases := []struct { | ||||
| 		name              string | ||||
| @@ -200,6 +202,35 @@ func Test_filterEndpointsWithHints(t *testing.T) { | ||||
| 			{ip: "10.1.2.3", zoneHints: sets.NewString("zone-a")}, | ||||
| 			{ip: "10.1.2.6", zoneHints: sets.NewString("zone-a")}, | ||||
| 		}, | ||||
| 	}, { | ||||
| 		name:            "unready endpoint", | ||||
| 		nodeLabels:      map[string]string{v1.LabelTopologyZone: "zone-a"}, | ||||
| 		hintsAnnotation: "auto", | ||||
| 		endpoints: []endpoint{ | ||||
| 			{ip: "10.1.2.3", zoneHints: sets.NewString("zone-a")}, | ||||
| 			{ip: "10.1.2.4", zoneHints: sets.NewString("zone-b")}, | ||||
| 			{ip: "10.1.2.5", zoneHints: sets.NewString("zone-c")}, | ||||
| 			{ip: "10.1.2.6", zoneHints: sets.NewString("zone-a"), unready: true}, | ||||
| 		}, | ||||
| 		expectedEndpoints: []endpoint{ | ||||
| 			{ip: "10.1.2.3", zoneHints: sets.NewString("zone-a")}, | ||||
| 		}, | ||||
| 	}, { | ||||
| 		name:            "only unready endpoints in same zone (should not filter)", | ||||
| 		nodeLabels:      map[string]string{v1.LabelTopologyZone: "zone-a"}, | ||||
| 		hintsAnnotation: "auto", | ||||
| 		endpoints: []endpoint{ | ||||
| 			{ip: "10.1.2.3", zoneHints: sets.NewString("zone-a"), unready: true}, | ||||
| 			{ip: "10.1.2.4", zoneHints: sets.NewString("zone-b")}, | ||||
| 			{ip: "10.1.2.5", zoneHints: sets.NewString("zone-c")}, | ||||
| 			{ip: "10.1.2.6", zoneHints: sets.NewString("zone-a"), unready: true}, | ||||
| 		}, | ||||
| 		expectedEndpoints: []endpoint{ | ||||
| 			{ip: "10.1.2.3", zoneHints: sets.NewString("zone-a"), unready: true}, | ||||
| 			{ip: "10.1.2.4", zoneHints: sets.NewString("zone-b")}, | ||||
| 			{ip: "10.1.2.5", zoneHints: sets.NewString("zone-c")}, | ||||
| 			{ip: "10.1.2.6", zoneHints: sets.NewString("zone-a"), unready: true}, | ||||
| 		}, | ||||
| 	}, { | ||||
| 		name:            "normal endpoint filtering, Auto annotation", | ||||
| 		nodeLabels:      map[string]string{v1.LabelTopologyZone: "zone-a"}, | ||||
| @@ -291,12 +322,12 @@ func Test_filterEndpointsWithHints(t *testing.T) { | ||||
| 		t.Run(tc.name, func(t *testing.T) { | ||||
| 			endpoints := []Endpoint{} | ||||
| 			for _, ep := range tc.endpoints { | ||||
| 				endpoints = append(endpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints}) | ||||
| 				endpoints = append(endpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints, Ready: !ep.unready}) | ||||
| 			} | ||||
|  | ||||
| 			expectedEndpoints := []Endpoint{} | ||||
| 			for _, ep := range tc.expectedEndpoints { | ||||
| 				expectedEndpoints = append(expectedEndpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints}) | ||||
| 				expectedEndpoints = append(expectedEndpoints, &BaseEndpointInfo{Endpoint: ep.ip, ZoneHints: ep.zoneHints, Ready: !ep.unready}) | ||||
| 			} | ||||
|  | ||||
| 			filteredEndpoints := filterEndpointsWithHints(endpoints, tc.hintsAnnotation, tc.nodeLabels) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Rob Scott
					Rob Scott