knative / pkg

Knative common packages
Apache License 2.0
259 stars 331 forks source link

Bug when implementing "Pod Spec"-able Bindings #2356

Closed ricardozanini closed 2 years ago

ricardozanini commented 3 years ago

Hi all!

I've been working on a small refactoring on Kogito Eventing to have a source capable to bind to any "Podspecable" and sink the events to any Sink.

The Sink part is already done, but I'm having a hard time implementing the "subject" binding. I've followed this guide, but I'm getting weird exceptions on my controller.

I might be implementing it wrong, so I came for advice. Could also be a bug, I'm not sure if we have this use case in other sources.

Expected Behavior

The "subject" be bound to the source.

Actual Behavior

If the subject is defined without the namespace, the controller can't find it. I'm assuming the controller is looking for the subject in the default namespace instead to look at the same namespace the source CR is created. If I define the namespace, this null reference is raised:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x15c7f8f]

goroutine 79 [running]:
knative.dev/pkg/webhook/psbinding.(*BaseReconciler).labelNamespace(0xc000343d40, {0x1c57058, 0xc0000c5bf0}, {{0xc000834750, 0x16}, {0xc0008e6200, 0x7}, {0xc0008e6210, 0xb}, {0xc000056750, ...}, ...})
    knative.dev/pkg@v0.0.0-20211117133034-22c0eba0cacf/webhook/psbinding/reconciler.go:279 +0x4f
knative.dev/pkg/webhook/psbinding.(*BaseReconciler).ReconcileSubject(0xc000343d40, {0x1c57058, 0xc0000c5bf0}, {0x1ca9bf8, 0xc000b285a0}, 0xc0000dafa8)
    knative.dev/pkg@v0.0.0-20211117133034-22c0eba0cacf/webhook/psbinding/reconciler.go:355 +0x897
knative.dev/pkg/webhook/psbinding.(*BaseReconciler).reconcile(0xc000343d40, {0x1c57058, 0xc0000c5bf0}, {0x1ca9bf8, 0xc000b285a0})
    knative.dev/pkg@v0.0.0-20211117133034-22c0eba0cacf/webhook/psbinding/reconciler.go:182 +0x165
knative.dev/pkg/webhook/psbinding.(*BaseReconciler).Reconcile(0xc000343d40, {0x1c57058, 0xc0000c5bf0}, {0xc000a29b00, 0x37})
    knative.dev/pkg@v0.0.0-20211117133034-22c0eba0cacf/webhook/psbinding/reconciler.go:139 +0x335
knative.dev/pkg/controller.(*Impl).processNextWorkItem(0xc0000b8a80)
    knative.dev/pkg@v0.0.0-20211117133034-22c0eba0cacf/controller/controller.go:542 +0x5a5
knative.dev/pkg/controller.(*Impl).RunContext.func3()
    knative.dev/pkg@v0.0.0-20211117133034-22c0eba0cacf/controller/controller.go:478 +0x68
created by knative.dev/pkg/controller.(*Impl).RunContext
    knative.dev/pkg@v0.0.0-20211117133034-22c0eba0cacf/controller/controller.go:476 +0x2de

Steps to Reproduce the Problem

  1. Pull this PR
  2. Install the source in a cluster with Knative installed
  3. Try the source sample in this gist.

Additional Info

The necessary information to reproduce the problem is in the linked gist. Please, reach out to me if you need more details.

Many thanks!

/kind bug /area API

lionelvillard commented 3 years ago

I added a comment to your PR.

ricardozanini commented 3 years ago

Fixed by adding the NamespaceLister attribute to the controller constructor. We can update the guide to reflect this change. From the GitHub Source: https://github.com/knative-sandbox/eventing-github/blob/v0.27.0/pkg/reconciler/binding/controller.go#L60-L82

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 90 days with no activity. It will automatically close after 30 more days of inactivity. Reopen the issue with /reopen. Mark the issue as fresh by adding the comment /remove-lifecycle stale.