Updating EndpointSliceMirroring controller to listen for Service changes
This fixes a bug that could occur if a custom Endpoints resource was created before a Service was created.
This commit is contained in:
@@ -185,14 +185,35 @@ func objectRefPtrEqual(ref1, ref2 *corev1.ObjectReference) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// getServiceFromDeleteAction parses a Service resource from a delete
|
||||
// action.
|
||||
func getServiceFromDeleteAction(obj interface{}) *corev1.Service {
|
||||
if service, ok := obj.(*corev1.Service); ok {
|
||||
return service
|
||||
}
|
||||
// If we reached here it means the Service was deleted but its final state
|
||||
// is unrecorded.
|
||||
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
|
||||
if !ok {
|
||||
utilruntime.HandleError(fmt.Errorf("Couldn't get object from tombstone %#v", obj))
|
||||
return nil
|
||||
}
|
||||
service, ok := tombstone.Obj.(*corev1.Service)
|
||||
if !ok {
|
||||
utilruntime.HandleError(fmt.Errorf("Tombstone contained object that is not a Service resource: %#v", obj))
|
||||
return nil
|
||||
}
|
||||
return service
|
||||
}
|
||||
|
||||
// getEndpointsFromDeleteAction parses an Endpoints resource from a delete
|
||||
// action.
|
||||
func getEndpointsFromDeleteAction(obj interface{}) *corev1.Endpoints {
|
||||
if endpointSlice, ok := obj.(*corev1.Endpoints); ok {
|
||||
return endpointSlice
|
||||
if endpoints, ok := obj.(*corev1.Endpoints); ok {
|
||||
return endpoints
|
||||
}
|
||||
// If we reached here it means the EndpointSlice was deleted but its final
|
||||
// state is unrecorded.
|
||||
// If we reached here it means the Endpoints resource was deleted but its
|
||||
// final state is unrecorded.
|
||||
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
|
||||
if !ok {
|
||||
utilruntime.HandleError(fmt.Errorf("Couldn't get object from tombstone %#v", obj))
|
||||
|
Reference in New Issue
Block a user