Deep copying EndpointSlices in reconciler before modifying them.

This commit is contained in:
Rob Scott
2019-11-15 15:28:05 -08:00
parent 65aefd3def
commit 4229b99203
3 changed files with 83 additions and 15 deletions

View File

@@ -290,9 +290,11 @@ func (r *reconciler) reconcileByPortMapping(
// if no endpoints desired in this slice, mark for deletion
sliceNamesToDelete.Insert(existingSlice.Name)
} else {
// otherwise, mark for update
existingSlice.Endpoints = newEndpoints
sliceNamesToUpdate.Insert(existingSlice.Name)
// otherwise, copy and mark for update
epSlice := existingSlice.DeepCopy()
epSlice.Endpoints = newEndpoints
slicesByName[existingSlice.Name] = epSlice
sliceNamesToUpdate.Insert(epSlice.Name)
}
} else {
// slices with no changes will be useful if there are leftover endpoints
@@ -344,6 +346,10 @@ func (r *reconciler) reconcileByPortMapping(
// If we didn't find a sliceToFill, generate a new empty one.
if sliceToFill == nil {
sliceToFill = newEndpointSlice(service, endpointMeta)
} else {
// deep copy required to modify this slice.
sliceToFill = sliceToFill.DeepCopy()
slicesByName[sliceToFill.Name] = sliceToFill
}
// Fill the slice up with remaining endpoints.