in pkg/controllers/member/endpointslice/controller.go [253:325]
func (r *Reconciler) shouldSkipOrUnexportEndpointSlice(ctx context.Context,
endpointSlice *discoveryv1.EndpointSlice) (skipOrUnexportEndpointSliceOp, error) {
// Skip the reconciliation if the EndpointSlice is not permanently exportable.
if isEndpointSlicePermanentlyUnexportable(endpointSlice) {
return shouldSkipEndpointSliceOp, nil
}
// If the Service name label is absent, the EndpointSlice is not in use by a Service and thus cannot
// be exported.
svcName, hasSvcNameLabel := endpointSlice.Labels[discoveryv1.LabelServiceName]
// It is guaranteed that if there is no unique name assigned to an EndpointSlice as an annotation, no attempt has
// been made to export an EndpointSlice.
_, hasUniqueNameAnnotation := endpointSlice.Annotations[objectmeta.ExportedObjectAnnotationUniqueName]
if !hasSvcNameLabel {
if !hasUniqueNameAnnotation {
// The Service is not in use by a Service and does not have a unique name annotation (i.e. it has not been
// exported before); it should be skipped for further processing.
return shouldSkipEndpointSliceOp, nil
}
// The Service is not in use by a Service but has a unique name annotation (i.e. it might have been exported);
// this could happen on an orphaned exported EndpointSlice, which should be unexported.
return shouldUnexportEndpointSliceOp, nil
}
// Retrieve the Service Export.
svcExport := &fleetnetv1alpha1.ServiceExport{}
err := r.MemberClient.Get(ctx, types.NamespacedName{Namespace: endpointSlice.Namespace, Name: svcName}, svcExport)
switch {
case errors.IsNotFound(err) && hasUniqueNameAnnotation:
// The Service using the EndpointSlice is not exported but the EndpointSlice has a unique name annotation
// present (i.e. it might have been exported); the EndpointSlice should be unexported.
return shouldUnexportEndpointSliceOp, nil
case errors.IsNotFound(err) && !hasUniqueNameAnnotation:
// The Service using the EndpointSlice is not exported and the EndpointSlice has no unique name annotation
// present (i.e. it has not been exported before); the EndpointSlice should be skipped for further processing.
return shouldSkipEndpointSliceOp, nil
case err != nil:
// An unexpected error has occurred.
return continueReconcileOp, err
}
// Check if the ServiceExport is valid with no conflicts.
if !isServiceExportValidWithNoConflict(svcExport) {
if hasUniqueNameAnnotation {
// The Service using the EndpointSlice is not valid for export or has conflicts with other exported
// Services, but the EndpointSlice has a unique name annotation present (i.e. it might have been
// exported before); the EndpointSlice should be unexported.
return shouldUnexportEndpointSliceOp, nil
}
// The Service using the EndpointSlice is not valid for export or has conflicts with other exported
// Services, and the EndpointSlice has no unique name annoation present (i.e. it has not been
// exported before); the EndpointSlice should be skipped for further processing.
return shouldSkipEndpointSliceOp, nil
}
if endpointSlice.DeletionTimestamp != nil {
if hasUniqueNameAnnotation {
// The Service using the EndpointSlice is exported with no conflicts, and the EndpointSlice has a unique
// name annotation (i.e. it might have been exported), but it has been deleted; as a result,
// the EndpointSlice should be unexported.
return shouldUnexportEndpointSliceOp, nil
}
// The Service using the EndpointSlice is exported with no conflicts, but the EndpointSlice does not have a
// unique name annotation (i.e. it has not been exported), and it has been deleted; as a result,
// the EndpointSlice should be skipped.
return shouldSkipEndpointSliceOp, nil
}
// The Service using the EndpointSlice is exported with no conflicts, and the EndpointSlice is not marked
// for deletion; the EndpointSlice should be further processed.
return continueReconcileOp, nil
}