File tree Expand file tree Collapse file tree
data-plane/core/src/main/java/dev/knative/eventing/kafka/broker/core/eventtype Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -92,7 +92,32 @@ public Future<EventType> create(
9292 .withSchema (event .getDataSchema ())
9393 .withDescription ("Event Type auto-created by controller" );
9494
95- return this .eventTypeClient .resource (et .build ()).create ();
95+ try {
96+ return this .eventTypeClient .resource (et .build ()).create ();
97+ } catch (io .fabric8 .kubernetes .client .KubernetesClientException e ) {
98+ // Handle race condition where EventType was created between cache check and creation attempt
99+ // Check for HTTP 409 (Conflict) status code or "AlreadyExists" reason
100+ final boolean isAlreadyExists = (e .getCode () == 409 )
101+ || (e .getStatus () != null
102+ && "AlreadyExists" .equals (e .getStatus ().getReason ()));
103+
104+ if (isAlreadyExists ) {
105+ logger .debug ("EventType {} already exists (race condition), fetching existing resource" , name );
106+ // Fetch the existing EventType instead of failing
107+ final var existing = this .eventTypeClient
108+ .inNamespace (ownerReference .getNamespace ())
109+ .withName (name )
110+ .get ();
111+ if (existing != null ) {
112+ return existing ;
113+ }
114+ // If we can't fetch it, fall back to the original exception
115+ logger .warn (
116+ "EventType {} already exists but could not fetch it, falling back to original error" , name );
117+ }
118+ // Re-throw the original exception if it's not an AlreadyExists error or we couldn't handle it
119+ throw e ;
120+ }
96121 });
97122 }
98123}
You can’t perform that action at this time.
0 commit comments