Conversation
| freq time.Duration | ||
|
|
||
| // Track all endpoint slices for this service | ||
| endpointSlicesMu sync.RWMutex |
There was a problem hiding this comment.
As far as I understand the code, only one goroutine handles events, so we don't have to synchronize using a mutex.
| var allAddresses []resolver.Address | ||
| totalEndpoints := 0 | ||
|
|
||
| for _, slice := range k.endpointSlices { | ||
| addrs := k.makeAddresses(slice) | ||
| allAddresses = append(allAddresses, addrs...) | ||
| totalEndpoints += len(slice.Endpoints) | ||
| } |
There was a problem hiding this comment.
According to the documentation https://kubernetes.io/docs/concepts/services-networking/endpoint-slices/#duplicate-endpoints endpoints can be duplicated, which means we should deduplicate them
| if sliceName == "" { | ||
| // Fallback: generate name from first endpoint if metadata is missing | ||
| if len(event.Object.Endpoints) > 0 && len(event.Object.Endpoints[0].Addresses) > 0 { | ||
| sliceName = fmt.Sprintf("slice-%s", event.Object.Endpoints[0].Addresses[0]) | ||
| } else { | ||
| sliceName = fmt.Sprintf("slice-%d", len(k.endpointSlices)) | ||
| } | ||
| } |
There was a problem hiding this comment.
Due to the fact that endpoints can be duplicated, I think that using a hashmap with keys based on endpoints might not work.
| defer k.endpointSlicesMu.Unlock() | ||
|
|
||
| sliceName := event.Object.Metadata.Name | ||
| if sliceName == "" { |
There was a problem hiding this comment.
I'm pretty sure that endpoint slice name has to be present. If it is absent, then we should probably ignore such event.
There was a problem hiding this comment.
Why were there no unit tests written?
Also, i'm seeing that when you submit a PR, there is nothing in place to run the tests 😱
Also, the tests don't pass in my machine 😱 😱 😱
$ go test -race ./...
^C2026/01/23 12:55:22 ERROR: kuberesolver: watching ended with error='Get "http://127.0.0.1:8001/apis/discovery.k8s.io/v1/watch/namespaces/kube-system/endpointslices?labelSelector=kubernetes.io/service-name=kube-dns": dial tcp 127.0.0.1:8001: connect: connection refused', will reconnect again
2026/01/23 12:55:23 ERROR: kuberesolver: recovered from panic: "sync: negative WaitGroup counter" (sync: negative WaitGroup counter)
bug fix #66