From d12832f8a6599207119e9b500444e3a450a78361 Mon Sep 17 00:00:00 2001 From: dongming Date: Thu, 15 Dec 2022 16:39:33 +0800 Subject: [PATCH] l-38 --- .../sigs.k8s.io/controller-runtime/pkg/builder/controller.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vendor/sigs.k8s.io/controller-runtime/pkg/builder/controller.go b/vendor/sigs.k8s.io/controller-runtime/pkg/builder/controller.go index efaf069..ccc06b4 100644 --- a/vendor/sigs.k8s.io/controller-runtime/pkg/builder/controller.go +++ b/vendor/sigs.k8s.io/controller-runtime/pkg/builder/controller.go @@ -75,11 +75,13 @@ type ForInput struct { err error } +// For 方法监控的对象只能是一个 // For defines the type of Object being *reconciled*, and configures the ControllerManagedBy to respond to create / delete / // update events by *reconciling the object*. // This is the equivalent of calling // Watches(&source.Kind{Type: apiType}, &handler.EnqueueRequestForObject{}). func (blder *Builder) For(object client.Object, opts ...ForOption) *Builder { + // 如果已经存在就报错退出,完成了之间空一个对象的逻辑 if blder.forInput.object != nil { blder.forInput.err = fmt.Errorf("For(...) should only be called once, could not assign multiple objects for reconciliation") return blder @@ -173,6 +175,7 @@ func (blder *Builder) Complete(r reconcile.Reconciler) error { // Build builds the Application Controller and returns the Controller it created. func (blder *Builder) Build(r reconcile.Reconciler) (controller.Controller, error) { + // 异常检查,保证后续的执行不会产生空指针的 panic if r == nil { return nil, fmt.Errorf("must provide a non-nil Reconciler") }