Skip to content

Commit f569102

Browse files
committed
fix event creation
Signed-off-by: Joe McGuire <[email protected]> Signed-off-by: Joe McGuire <[email protected]>
1 parent e873205 commit f569102

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

internal/kgateway/agentgatewaysyncer/nack/publisher.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (p *Publisher) OnNack(event krtxds.NackEvent) {
4444
k8sEvent := &corev1.Event{
4545
ObjectMeta: metav1.ObjectMeta{
4646
GenerateName: "agentgateway-nack-",
47-
Namespace: p.systemNamespace,
47+
Namespace: event.Gateway.Namespace,
4848
Annotations: map[string]string{
4949
AnnotationNackID: nackID,
5050
AnnotationTypeURL: event.TypeUrl,
@@ -69,7 +69,7 @@ func (p *Publisher) OnNack(event krtxds.NackEvent) {
6969
ReportingController: wellknown.DefaultAgwControllerName,
7070
}
7171

72-
_, err := p.client.Kube().CoreV1().Events(p.systemNamespace).Create(
72+
_, err := p.client.Kube().CoreV1().Events(event.Gateway.Namespace).Create(
7373
p.ctx, k8sEvent, metav1.CreateOptions{},
7474
)
7575
if err != nil && !errors.IsAlreadyExists(err) {
@@ -91,7 +91,7 @@ func (p *Publisher) OnAck(event krtxds.AckEvent) {
9191
k8sEvent := &corev1.Event{
9292
ObjectMeta: metav1.ObjectMeta{
9393
GenerateName: "agentgateway-ack-",
94-
Namespace: p.systemNamespace,
94+
Namespace: event.Gateway.Namespace,
9595
Annotations: map[string]string{
9696
AnnotationNackID: ComputeNackID(event.Gateway.Namespace+"/"+event.Gateway.Name, event.TypeUrl),
9797
AnnotationTypeURL: event.TypeUrl,
@@ -114,7 +114,7 @@ func (p *Publisher) OnAck(event krtxds.AckEvent) {
114114
ReportingController: wellknown.DefaultAgwControllerName,
115115
}
116116

117-
_, err := p.client.Kube().CoreV1().Events(p.systemNamespace).Create(
117+
_, err := p.client.Kube().CoreV1().Events(event.Gateway.Namespace).Create(
118118
p.ctx, k8sEvent, metav1.CreateOptions{},
119119
)
120120
if err != nil && !errors.IsAlreadyExists(err) {

pkg/agentgateway/plugins/collection.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package plugins
22

33
import (
44
"context"
5+
"fmt"
56

67
"istio.io/istio/pkg/config/schema/gvk"
78
"istio.io/istio/pkg/config/schema/gvr"
@@ -22,6 +23,7 @@ import (
2223
gwxv1a1 "sigs.k8s.io/gateway-api/apisx/v1alpha1"
2324

2425
"github.com/kgateway-dev/kgateway/v2/api/v1alpha1"
26+
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/agentgatewaysyncer/nack"
2527
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/krtcollections"
2628
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/wellknown"
2729
kgwversioned "github.com/kgateway-dev/kgateway/v2/pkg/client/clientset/versioned"
@@ -316,11 +318,10 @@ func NewAgwCollections(
316318
EndpointSlices: krt.WrapClient(
317319
kclient.NewFiltered[*discovery.EndpointSlice](commoncol.Client, kubetypes.Filter{ObjectFilter: commoncol.Client.ObjectFilter()}),
318320
commoncol.KrtOpts.ToOptions("informer/EndpointSlices")...),
319-
// we only want to watch events in the system namespace (that we control) to avoid performance issues.
320-
// todo: we could probably tighten this further with a field selector for the involved object being of kind Gateway. (overkill/)
321+
// we only want to watch events that we created (AgentgatewayNACK/AgentgatewayACK) to avoid performance issues.
321322
Events: krt.WrapClient(
322323
kclient.NewFiltered[*corev1.Event](commoncol.Client, kubetypes.Filter{
323-
Namespace: systemNamespace,
324+
FieldSelector: fmt.Sprintf("reason=%s,reason=%s", nack.ReasonNack, nack.ReasonAck),
324325
}),
325326
commoncol.KrtOpts.ToOptions("informer/Events")...),
326327

0 commit comments

Comments
 (0)