// handleDelete handles the deletion of instances
handleDelete handles the deletion of instances
// handleDelete handles the deletion of instances
func (c *Controller) handleDelete(ctx context.Context, log logr.Logger, instance *lssv1alpha1.Instance) error {
	var (
		err                 error
		curOp               = "Delete"
		targetDeleted       = true
		installationDeleted = true
	)
	if instance.Status.InstallationRef != nil && !instance.Status.InstallationRef.IsEmpty() {
		if targetDeleted, err = c.ensureDeleteInstallationForInstance(ctx, log, instance); err != nil {
			return lsserrors.NewWrappedError(err, curOp, "DeleteInstallation", err.Error())
		}
	}
	if !targetDeleted {
		return nil
	}
	if instance.Status.TargetRef != nil && !instance.Status.TargetRef.IsEmpty() {
		if installationDeleted, err = c.ensureDeleteTargetForInstance(ctx, log, instance); err != nil {
			return lsserrors.NewWrappedError(err, curOp, "DeleteTarget", err.Error())
		}
	}
	if !installationDeleted {
		return nil
	}
	serviceTargetConfig := &lssv1alpha1.ServiceTargetConfig{}
	if err := c.Client().Get(ctx, instance.Spec.ServiceTargetConfigRef.NamespacedName(), serviceTargetConfig); err != nil {
		return lsserrors.NewWrappedError(err, curOp, "GetServiceTargetConfig", err.Error())
	}
	serviceTargetConfig.Status.InstanceRefs = utils.RemoveReference(serviceTargetConfig.Status.InstanceRefs, &lssv1alpha1.ObjectReference{
		Name:      instance.GetName(),
		Namespace: instance.GetNamespace(),
	})
	if err := c.Client().Status().Update(ctx, serviceTargetConfig); err != nil {
		return lsserrors.NewWrappedError(err, curOp, "RemoveRefFromServiceTargetConfig", err.Error())
	}
	controllerutil.RemoveFinalizer(instance, lssv1alpha1.LandscaperServiceFinalizer)
	if err := c.Client().Update(ctx, instance); err != nil {
		return lsserrors.NewWrappedError(err, curOp, "RemoveFinalizer", err.Error())
	}
	return nil
}
func ( c * Controller ) handleDelete ( ctx context . Context , log logr . Logger , instance * lssv1alpha1 . Instance ) error { var ( err error curOp = " " targetDeleted = true installationDeleted = true ) if instance . Status . InstallationRef != nil && ! instance . Status . InstallationRef . IsEmpty ( ) { if targetDeleted , err = c . ensureDeleteInstallationForInstance ( ctx , log , instance ) ; err != nil { return lsserrors . NewWrappedError ( err , curOp , " " , err . Error ( ) ) } } if ! targetDeleted { return nil } if instance . Status . TargetRef != nil && ! instance . Status . TargetRef . IsEmpty ( ) { if installationDeleted , err = c . ensureDeleteTargetForInstance ( ctx , log , instance ) ; err != nil { return lsserrors . NewWrappedError ( err , curOp , " " , err . Error ( ) ) } } if ! installationDeleted { return nil } serviceTargetConfig := & lssv1alpha1 . ServiceTargetConfig { } if err := c . Client ( ) . Get ( ctx , instance . Spec . ServiceTargetConfigRef . NamespacedName ( ) , serviceTargetConfig ) ; err != nil { return lsserrors . NewWrappedError ( err , curOp , " " , err . Error ( ) ) } serviceTargetConfig . Status . InstanceRefs = utils . RemoveReference ( serviceTargetConfig . Status . InstanceRefs , & lssv1alpha1 . ObjectReference { Name : instance . GetName ( ) , Namespace : instance . GetNamespace ( ) , } ) if err := c . Client ( ) . Status ( ) . Update ( ctx , serviceTargetConfig ) ; err != nil { return lsserrors . NewWrappedError ( err , curOp , " " , err . Error ( ) ) } controllerutil . RemoveFinalizer ( instance , lssv1alpha1 . LandscaperServiceFinalizer ) if err := c . Client ( ) . Update ( ctx , instance ) ; err != nil { return lsserrors . NewWrappedError ( err , curOp , " " , err . Error ( ) ) } return nil }
handleDelete handles the deletion of instances
handleDelete handles the deletion of instances
// remove instance reference from service target config