Skip to content

Conversation

@sercand
Copy link
Owner

@sercand sercand commented Jun 30, 2025

bug fix #66

freq time.Duration

// Track all endpoint slices for this service
endpointSlicesMu sync.RWMutex

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand the code, only one goroutine handles events, so we don't have to synchronize using a mutex.

Comment on lines +322 to +329
var allAddresses []resolver.Address
totalEndpoints := 0

for _, slice := range k.endpointSlices {
addrs := k.makeAddresses(slice)
allAddresses = append(allAddresses, addrs...)
totalEndpoints += len(slice.Endpoints)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +288 to +295
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))
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 == "" {
Copy link

@lothar1998 lothar1998 Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that endpoint slice name has to be present. If it is absent, then we should probably ignore such event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EndpointSlices implementation is broken

4 participants