mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 15:37:24 +00:00
endpoinslices must mirror services labels
Implement, in the endpoint slice controller, the same logic used for labels in the legacy endpoints controller. The labels in the endpoint and in the parent must be equivalent. Headless services add the well-known IsHeadlessService label. Slices must have two well known labels: LabelServiceName and LabelManagedBy.
This commit is contained in:
@@ -246,9 +246,11 @@ func (r *reconciler) finalize(
|
||||
|
||||
// reconcileByPortMapping compares the endpoints found in existing slices with
|
||||
// the list of desired endpoints and returns lists of slices to create, update,
|
||||
// and delete. The logic is split up into several main steps:
|
||||
// and delete. It also checks that the slices mirror the parent services labels.
|
||||
// The logic is split up into several main steps:
|
||||
// 1. Iterate through existing slices, delete endpoints that are no longer
|
||||
// desired and update matching endpoints that have changed.
|
||||
// desired and update matching endpoints that have changed. It also checks
|
||||
// if the slices have the labels of the parent services, and updates them if not.
|
||||
// 2. Iterate through slices that have been modified in 1 and fill them up with
|
||||
// any remaining desired endpoints.
|
||||
// 3. If there still desired endpoints left, try to fit them into a previously
|
||||
@@ -287,6 +289,9 @@ func (r *reconciler) reconcileByPortMapping(
|
||||
}
|
||||
}
|
||||
|
||||
// generate the slice labels and check if parent labels have changed
|
||||
labels, labelsChanged := setEndpointSliceLabels(existingSlice, service)
|
||||
|
||||
// If an endpoint was updated or removed, mark for update or delete
|
||||
if endpointUpdated || len(existingSlice.Endpoints) != len(newEndpoints) {
|
||||
if len(existingSlice.Endpoints) > len(newEndpoints) {
|
||||
@@ -299,9 +304,16 @@ func (r *reconciler) reconcileByPortMapping(
|
||||
// otherwise, copy and mark for update
|
||||
epSlice := existingSlice.DeepCopy()
|
||||
epSlice.Endpoints = newEndpoints
|
||||
epSlice.Labels = labels
|
||||
slicesByName[existingSlice.Name] = epSlice
|
||||
sliceNamesToUpdate.Insert(epSlice.Name)
|
||||
}
|
||||
} else if labelsChanged {
|
||||
// if labels have changed, copy and mark for update
|
||||
epSlice := existingSlice.DeepCopy()
|
||||
epSlice.Labels = labels
|
||||
slicesByName[existingSlice.Name] = epSlice
|
||||
sliceNamesToUpdate.Insert(epSlice.Name)
|
||||
} else {
|
||||
// slices with no changes will be useful if there are leftover endpoints
|
||||
sliceNamesUnchanged.Insert(existingSlice.Name)
|
||||
|
||||
Reference in New Issue
Block a user