openyurtio / yurt-edgex-manager

yurt-edgex-manager is an operator for managing EdgeX lifecycle(including deploy, delete, update) in OpenYurt cluster.
Apache License 2.0
18 stars 24 forks source link

[BUG] Error occurs when deleting edgex in reconcileDelete function #46

Closed LavenderQAQ closed 2 years ago

LavenderQAQ commented 2 years ago

What happened: When the edgex object is deleted, the reconcileDelete function displays the following error:

1.6638252595946293e+09  ERROR   reconcile failed        {"controller": "edgex", "controllerGroup": "device.openyurt.io", "controllerKind": "EdgeX", "edgeX": {"name":"edgex-sample-beijing","namespace":"default"}, "namespace": "default", "name": "edgex-sample-beijing", "reconcileID": "aef8ad82-7670-4e01-894e-276cfb7a92c0", "edgex": "default/edgex-sample-beijing", "error": "edgexes.device.openyurt.io \"edgex-sample-beijing\" not found", "errorCauses": [{"error": "edgexes.device.openyurt.io \"edgex-sample-beijing\" not found", "errorCauses": [{"error": "edgexes.device.openyurt.io \"edgex-sample-beijing\" not found"}]}]}
github.com/openyurtio/yurt-edgex-manager/controllers.(*EdgeXReconciler).Reconcile
        /home/hanqi/yurt-edgex-manager/controllers/edgex_controller.go:129
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile
        /home/hanqi/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.12.1/pkg/internal/controller/controller.go:121
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
        /home/hanqi/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.12.1/pkg/internal/controller/controller.go:320
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
        /home/hanqi/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.12.1/pkg/internal/controller/controller.go:273
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2

However, all pods can exit normally, and the functions of yurt-edgex-manager are not affected.

edgex-app-rules-engine-beijing-8kftr-745cd6d4ff-7mrq4        1/1     Terminating   0          19s
edgex-core-command-beijing-qrtzs-74dd6c4c75-rzwgb            1/1     Terminating   0          19s
edgex-core-data-beijing-r4ktw-6cf9645695-cqmr9               1/1     Terminating   0          19s
edgex-core-metadata-beijing-c2v5r-8497fc664-tmdw2            1/1     Terminating   0          18s
edgex-support-notifications-beijing-rm826-547b7c9774-kpqhg   1/1     Terminating   0          18s
edgex-support-scheduler-beijing-srdr2-84bfff55c9-84f4g       1/1     Terminating   0          19s
yurt-app-manager-789c97b55d-dw6qh                            1/1     Running       0          162m
yurt-app-manager-admission-create-4wdv6                      0/1     Completed     0          162m
yurt-app-manager-admission-patch-zl4q4                       0/1     Completed     1          162m

How to reproduce it (as minimally and precisely as possible): Install the CRD and fire the Delete event.

Anything else we need to know?: It is possible that this code triggered the error, but it is strange that the edgex object can only be not found after remove Finalizer.

func (r *EdgeXReconciler) reconcileDelete(ctx context.Context, edgex *devicev1alpha1.EdgeX) (ctrl.Result, error) {

    ud := &unitv1alpha1.YurtAppSet{}
    desiredeployments := append(CoreDeployment[edgex.Spec.Version], edgex.Spec.AdditionalDeployment...)
    for _, dd := range desiredeployments {

        if err := r.Get(
            ctx,
            types.NamespacedName{Namespace: edgex.Namespace, Name: dd.Name},
            ud); err != nil {
            continue
        }

        for i, pool := range ud.Spec.Topology.Pools {
            if pool.Name == edgex.Spec.PoolName {
                ud.Spec.Topology.Pools[i] = ud.Spec.Topology.Pools[len(ud.Spec.Topology.Pools)-1]
                ud.Spec.Topology.Pools = ud.Spec.Topology.Pools[:len(ud.Spec.Topology.Pools)-1]
            }
        }
        if err := r.Update(ctx, ud); err != nil {
            return ctrl.Result{}, err
        }
    }

    controllerutil.RemoveFinalizer(edgex, devicev1alpha1.EdgexFinalizer)

    return ctrl.Result{}, nil
}

Environment:

others

/kind bug

rambohe-ch commented 2 years ago

@lwmqwer PTAL

lwmqwer commented 2 years ago

@rambohe-ch Lavender-QAQ will handle this.

rambohe-ch commented 2 years ago

/assign @Lavender-QAQ

LavenderQAQ commented 2 years ago

PR#48 has solved this problem. Advise to use helm to deploy yurt-app-manager and yurt-edgex-manager.