// ensureDeleteTargetForInstance ensures that the target for an instance is deleted
ensureDeleteTargetForInstance ensures that the target for an instance is deleted
// ensureDeleteTargetForInstance ensures that the target for an instance is deleted
func (c *Controller) ensureDeleteTargetForInstance(ctx context.Context, log logr.Logger, instance *lssv1alpha1.Instance) (bool, error) {
	log.Info("Delete target for instance")
	target := &lsv1alpha1.Target{}
	if err := c.Client().Get(ctx, instance.Status.TargetRef.NamespacedName(), target); err != nil {
		if apierrors.IsNotFound(err) {
			instance.Status.TargetRef = nil
			if err := c.Client().Status().Update(ctx, instance); err != nil {
				return false, fmt.Errorf("failed to remove target reference: %w", err)
			}
			return true, nil
		} else {
			return false, fmt.Errorf("unable to get target for instance: %w", err)
		}
	}
	if target.DeletionTimestamp.IsZero() {
		if err := c.Client().Delete(ctx, target); err != nil {
			return false, fmt.Errorf("unable to delete target for instance: %w", err)
		}
	}
	return false, nil
}
func ( c * Controller ) ensureDeleteTargetForInstance ( ctx context . Context , log logr . Logger , instance * lssv1alpha1 . Instance ) ( bool , error ) { log . Info ( " " ) target := & lsv1alpha1 . Target { } if err := c . Client ( ) . Get ( ctx , instance . Status . TargetRef . NamespacedName ( ) , target ) ; err != nil { if apierrors . IsNotFound ( err ) { instance . Status . TargetRef = nil if err := c . Client ( ) . Status ( ) . Update ( ctx , instance ) ; err != nil { return false , fmt . Errorf ( " " , err ) } return true , nil } else { return false , fmt . Errorf ( " " , err ) } } if target . DeletionTimestamp . IsZero ( ) { if err := c . Client ( ) . Delete ( ctx , target ) ; err != nil { return false , fmt . Errorf ( " " , err ) } } return false , nil }
ensureDeleteTargetForInstance ensures that the target for an instance is deleted
ensureDeleteTargetForInstance ensures that the target for an instance is deleted