-
Notifications
You must be signed in to change notification settings - Fork 84
Endpoint slices bug fix #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| freq time.Duration | ||
|
|
||
| // Track all endpoint slices for this service | ||
| endpointSlicesMu sync.RWMutex |
There was a problem hiding this comment.
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.
| 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.
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
| 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.
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 == "" { |
There was a problem hiding this comment.
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.
bug fix #66