in internal/controllers/resourceslice/slicecleanup.go [130:159]
func (c *cleanupController) shouldDelete(ctx context.Context, reader client.Reader, slice *apiv1.ResourceSlice, ref *metav1.OwnerReference) (bool, error) {
comp := &apiv1.Composition{}
err := reader.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: slice.Namespace}, comp)
if errors.IsNotFound(err) {
return true, nil
}
if err != nil {
return false, fmt.Errorf("getting composition: %w", err)
}
// Don't delete slices that are part of an active synthesis
if comp.Status.InFlightSynthesis != nil && comp.Status.InFlightSynthesis.UUID == slice.Spec.SynthesisUUID {
return false, nil
}
// Check resource slice references
for _, syn := range []*apiv1.Synthesis{comp.Status.CurrentSynthesis, comp.Status.PreviousSynthesis} {
if syn == nil {
continue
}
idx := slices.IndexFunc(syn.ResourceSlices, func(ref *apiv1.ResourceSliceRef) bool {
return ref.Name == slice.Name
})
if idx != -1 {
return false, nil
}
}
return true, nil
}