Change:
Opening this issue based on what I ran into on with namespace as follows While unit testing the controller, we create a fake client and setup the controller to run using the client. This ends up creating a having the namespace set to When the call eventually reaches The action gets associated with a namespace only if the object has a namespace associated with it. Which in this will be Which will result in the error in to manage the event like does. In case if the namespace is set to Above is a test case that can easily simulate the issue in question. Referring back to the test under PR NA <details</details<details</details<details</details<details</details<details</details<details</details
/sig api-machinery
/help /triage accepted
This request has been marked as needing help from a contributor. Please ensure that the issue body includes answers to the following questions: Why are we solving this issue? To address this issue, are there any code changes? If there are code changes, what needs to be done in the code and what places can the assignee treat as reference points? Does this issue have zero to low barrier of entry? How can the assignee reach out to you for help? For more details on the requirements of such an issue, please see and ensure that they are met. If this request no longer meets these requirements, the label can be removed by commenting with the command. <detailsIn response to : /help /triage accepted Instructions for interacting with me using PR comments are available . If you have questions or suggestions related to my behavior, please file an issue against the repository. </details
/assign

Discussion:
package fake import ( <del> "k8s.io/api/core/v1" </del> <ins> v1 "k8s.io/api/core/v1" </ins> metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime"

) func (c *FakeEvents) CreateWithEventNamespace(event *v1.Event) (*v1.Event, error) { <del> action := core.NewRootCreateAction(eventsResource, event) </del> <ins> var action core.CreateActionImpl </ins> if c.ns != "" { action = core.NewCreateAction(eventsResource, c.ns, event) <ins> } else { action = core.NewCreateAction(eventsResource, event.GetNamespace(), event) </ins> } obj, err := c.Fake.Invokes(action, event) if obj == nil {

// Update replaces an existing event. Returns the copy of the event the server returns, or an error. func (c *FakeEvents) UpdateWithEventNamespace(event *v1.Event) (*v1.Event, error) { <del> action := core.NewRootUpdateAction(eventsResource, event) </del> <ins> var action core.UpdateActionImpl </ins> if c.ns != "" { action = core.NewUpdateAction(eventsResource, c.ns, event) <ins> } else { action = core.NewUpdateAction(eventsResource, event.GetNamespace(), event) </ins> } obj, err := c.Fake.Invokes(action, event) if obj == nil {

func (c *FakeEvents) PatchWithEventNamespace(event *v1.Event, data []byte) (*v1.Event, error) { // TODO: Should be configurable to support additional patch strategies. pt := types.StrategicMergePatchType <del> action := core.NewRootPatchAction(eventsResource, event.Name, pt, data) </del> <ins> var action core.PatchActionImpl </ins> if c.ns != "" { action = core.NewPatchAction(eventsResource, c.ns, event.Name, pt, data) <ins> } else { action = core.NewPatchAction(eventsResource, event.GetNamespace(), event.Name, pt, data) </ins> } obj, err := c.Fake.Invokes(action, event) if obj == nil {

// Search returns a list of events matching the specified object. func (c *FakeEvents) Search(scheme *runtime.Scheme, objOrRef runtime.Object) (*v1.EventList, error) { <del> action := core.NewRootListAction(eventsResource, eventsKind, metav1.ListOptions{}) </del> <ins> var action core.ListActionImpl </ins> if c.ns != "" { action = core.NewListAction(eventsResource, eventsKind, c.ns, metav1.ListOptions{}) <ins> } else { action = core.NewListAction(eventsResource, eventsKind, v1.NamespaceDefault, metav1.ListOptions{}) </ins> } obj, err := c.Fake.Invokes(action, &v1.EventList{}) if obj == nil {