@@ -75,6 +75,16 @@ func NewLabeler(
7575 }
7676}
7777
78+ // normalizeEventGroupResource normalizes event resources to use the core/v1 version consistently
79+ // This prevents race conditions between core/v1 events and events.k8s.io/v1 events.
80+ func normalizeEventGroupResource (gr schema.GroupResource ) schema.GroupResource {
81+ if gr .Resource == "events" && (gr .Group == "" || gr .Group == "events.k8s.io" ) {
82+ // Always normalize to core/v1 events for consistent labeling
83+ return schema.GroupResource {Group : "" , Resource : "events" }
84+ }
85+ return gr
86+ }
87+
7888// LabelsFor returns all the applicable labels for the cluster-group-resource relating to permission claims. This is
7989// the intersection of (1) all APIBindings in the cluster that have accepted claims for the group-resource with (2)
8090// associated APIExports that are claiming group-resource.
@@ -84,7 +94,10 @@ func (l *Labeler) LabelsFor(ctx context.Context, cluster logicalcluster.Name, gr
8494 return labels , nil
8595 }
8696
87- bindings , err := l .listAPIBindingsAcceptingClaimedGroupResource (cluster , groupResource )
97+ // Normalize event resources to prevent race conditions between API versions
98+ normalizedGR := normalizeEventGroupResource (groupResource )
99+
100+ bindings , err := l .listAPIBindingsAcceptingClaimedGroupResource (cluster , normalizedGR )
88101 if err != nil {
89102 return nil , fmt .Errorf ("error listing APIBindings in %q accepting claimed group resource %q: %w" , cluster , groupResource , err )
90103 }
@@ -104,7 +117,7 @@ func (l *Labeler) LabelsFor(ctx context.Context, cluster logicalcluster.Name, gr
104117 }
105118
106119 for _ , claim := range binding .Spec .PermissionClaims {
107- if claim .State != apisv1alpha2 .ClaimAccepted || claim .Group != groupResource .Group || claim .Resource != groupResource .Resource || ! claim .Selector .MatchAll {
120+ if claim .State != apisv1alpha2 .ClaimAccepted || claim .Group != normalizedGR .Group || claim .Resource != normalizedGR .Resource || ! claim .Selector .MatchAll {
108121 continue
109122 }
110123
0 commit comments