Skip to content

Commit 5716048

Browse files
danehansnfuden
andauthored
gateway2/krtcollections: Improves Eventual Consistency of EndpointSlices (#10412)
Signed-off-by: Daneyon Hansen <[email protected]> Co-authored-by: Nathan Fudenberg <[email protected]>
1 parent 08c038d commit 5716048

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
changelog:
2+
- type: FIX
3+
issueLink: https://github.com/solo-io/solo-projects/issues/7286
4+
resolvesIssue: false
5+
description: >-
6+
Changes endpointslice logging level to debug for transformK8sEndpoints() function.

projects/gateway2/krtcollections/endpoints.go

+23-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/binary"
66
"encoding/json"
7-
"fmt"
87
"hash/fnv"
98

109
envoy_config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
@@ -230,27 +229,32 @@ func transformK8sEndpoints(ctx context.Context, inputs EndpointsInputs) func(kct
230229
spec := kubeUpstream.Kube
231230
kubeSvcPort, singlePortSvc := findPortForService(kctx, svcs, spec)
232231
if kubeSvcPort == nil {
233-
logger.Debug("findPortForService - not found.", zap.Uint32("port", spec.GetServicePort()), zap.String("svcName", spec.GetServiceName()), zap.String("svcNamespace", spec.GetServiceNamespace()))
232+
logger.Debug("port not found for service", zap.Uint32("port", spec.GetServicePort()), zap.String("name", spec.GetServiceName()), zap.String("namespace", spec.GetServiceNamespace()))
234233
return nil
235234
}
236235

237-
svcNs := spec.GetServiceNamespace()
238-
svcName := spec.GetServiceName()
239-
// Fetch all EndpointSlices for the service
236+
// Fetch all EndpointSlices for the upstream service
240237
key := types.NamespacedName{
241-
Namespace: svcNs,
242-
Name: svcName,
238+
Namespace: spec.GetServiceNamespace(),
239+
Name: spec.GetServiceName(),
243240
}
244241

245242
endpointSlices := krt.Fetch(kctx, inputs.EndpointSlices, krt.FilterIndex(inputs.EndpointSlicesByService, key))
246243
if len(endpointSlices) == 0 {
247-
warnsToLog = append(warnsToLog, fmt.Sprintf("EndpointSlices not found for service %v/%v", svcNs, svcName))
244+
logger.Debug("no endpointslices found for service", zap.String("name", key.Name), zap.String("namespace", key.Namespace))
248245
return nil
249246
}
250247

251-
if len(endpointSlices) == 0 {
252-
warnsToLog = append(warnsToLog, fmt.Sprintf("EndpointSlices not found for service %v/%v", svcNs, svcName))
253-
logger.Debug("EndpointSlices not found for service")
248+
// Handle potential eventually consistency of EndpointSlices for the upstream service
249+
found := false
250+
for _, endpointSlice := range endpointSlices {
251+
if port := findPortInEndpointSlice(endpointSlice, singlePortSvc, kubeSvcPort); port != 0 {
252+
found = true
253+
break
254+
}
255+
}
256+
if !found {
257+
logger.Debug("no ports found in endpointslices for service", zap.String("name", key.Name), zap.String("namespace", key.Namespace))
254258
return nil
255259
}
256260

@@ -266,8 +270,9 @@ func transformK8sEndpoints(ctx context.Context, inputs EndpointsInputs) func(kct
266270
for _, endpointSlice := range endpointSlices {
267271
port := findPortInEndpointSlice(endpointSlice, singlePortSvc, kubeSvcPort)
268272
if port == 0 {
269-
warnsToLog = append(warnsToLog, fmt.Sprintf("port %v not found for service %v/%v in EndpointSlice %v",
270-
spec.GetServicePort(), svcNs, svcName, endpointSlice.Name))
273+
logger.Debug("no port found in endpointslice; will try next endpointslice if one exists",
274+
zap.String("name", endpointSlice.Name),
275+
zap.String("namespace", endpointSlice.Namespace))
271276
continue
272277
}
273278

@@ -400,6 +405,11 @@ func findPortForService(kctx krt.HandlerContext, services krt.Collection[*corev1
400405

401406
func findPortInEndpointSlice(endpointSlice *discoveryv1.EndpointSlice, singlePortService bool, kubeServicePort *corev1.ServicePort) uint32 {
402407
var port uint32
408+
409+
if endpointSlice == nil || kubeServicePort == nil {
410+
return port
411+
}
412+
403413
for _, p := range endpointSlice.Ports {
404414
if p.Port == nil {
405415
continue

0 commit comments

Comments
 (0)