@@ -7,6 +7,7 @@ package kubernetes
77
88import (
99 "context"
10+ "errors"
1011 "fmt"
1112 "time"
1213
@@ -214,13 +215,14 @@ func (r *gatewayAPIReconciler) Reconcile(ctx context.Context, _ reconcile.Reques
214215 // Initialize resource types.
215216 gwcResource := resource .NewResources ()
216217 gwcResource .GatewayClass = managedGC
217- gwcResources = append ( gwcResources , gwcResource )
218- resourceMappings := newResourceMapping ()
218+
219+ gwcResourceMapping := newResourceMapping ()
219220
220221 // Process the parametersRef of the accepted GatewayClass.
221222 // This should run before processGateways and processBackendRefs
222223 if managedGC .Spec .ParametersRef != nil && managedGC .DeletionTimestamp == nil {
223- if err := r .processGatewayClassParamsRef (ctx , managedGC , resourceMappings , gwcResource ); err != nil {
224+ if err := r .processGatewayClassParamsRef (ctx , managedGC , gwcResourceMapping , gwcResource ); err != nil {
225+ r .log .Error (err , fmt .Sprintf ("failed processGatewayClassParamsRef for gatewayClass %s, skipping it" , managedGC .Name ))
224226 msg := fmt .Sprintf ("%s: %v" , status .MsgGatewayClassInvalidParams , err )
225227 gc := status .SetGatewayClassAccepted (
226228 managedGC .DeepCopy (),
@@ -231,55 +233,63 @@ func (r *gatewayAPIReconciler) Reconcile(ctx context.Context, _ reconcile.Reques
231233 continue
232234 }
233235 }
236+ // it's safe here to append gwcResource to gwcResources
237+ gwcResources = append (gwcResources , gwcResource )
238+ // process global resources
239+ // add the OIDC HMAC Secret to the resourceTree
240+ r .processOIDCHMACSecret (ctx , gwcResource , gwcResourceMapping )
241+ // add the Envoy TLS Secret to the resourceTree
242+ r .processEnvoyTLSSecret (ctx , gwcResource , gwcResourceMapping )
234243
235244 // Add all Gateways, their associated Routes, and referenced resources to the resourceTree
236- if err = r .processGateways (ctx , managedGC , resourceMappings , gwcResource ); err != nil {
245+ if err = r .processGateways (ctx , managedGC , gwcResourceMapping , gwcResource ); err != nil {
237246 r .log .Error (err , fmt .Sprintf ("failed processGateways for gatewayClass %s, skipping it" , managedGC .Name ))
238247 continue
239248 }
240249
241250 if r .eppCRDExists {
242251 // Add all EnvoyPatchPolicies to the resourceTree
243- if err = r .processEnvoyPatchPolicies (ctx , gwcResource , resourceMappings ); err != nil {
252+ if err = r .processEnvoyPatchPolicies (ctx , gwcResource , gwcResourceMapping ); err != nil {
244253 r .log .Error (err , fmt .Sprintf ("failed processEnvoyPatchPolicies for gatewayClass %s, skipping it" , managedGC .Name ))
245254 continue
246255 }
247256 }
257+
248258 if r .ctpCRDExists {
249259 // Add all ClientTrafficPolicies and their referenced resources to the resourceTree
250- if err = r .processClientTrafficPolicies (ctx , gwcResource , resourceMappings ); err != nil {
260+ if err = r .processClientTrafficPolicies (ctx , gwcResource , gwcResourceMapping ); err != nil {
251261 r .log .Error (err , fmt .Sprintf ("failed processClientTrafficPolicies for gatewayClass %s, skipping it" , managedGC .Name ))
252262 continue
253263 }
254264 }
255265
256266 if r .btpCRDExists {
257267 // Add all BackendTrafficPolicies to the resourceTree
258- if err = r .processBackendTrafficPolicies (ctx , gwcResource , resourceMappings ); err != nil {
268+ if err = r .processBackendTrafficPolicies (ctx , gwcResource , gwcResourceMapping ); err != nil {
259269 r .log .Error (err , fmt .Sprintf ("failed processBackendTrafficPolicies for gatewayClass %s, skipping it" , managedGC .Name ))
260270 continue
261271 }
262272 }
263273
264274 if r .spCRDExists {
265275 // Add all SecurityPolicies and their referenced resources to the resourceTree
266- if err = r .processSecurityPolicies (ctx , gwcResource , resourceMappings ); err != nil {
276+ if err = r .processSecurityPolicies (ctx , gwcResource , gwcResourceMapping ); err != nil {
267277 r .log .Error (err , fmt .Sprintf ("failed processSecurityPolicies for gatewayClass %s, skipping it" , managedGC .Name ))
268278 continue
269279 }
270280 }
271281
272282 if r .bTLSPolicyCRDExists {
273283 // Add all BackendTLSPolies to the resourceTree
274- if err = r .processBackendTLSPolicies (ctx , gwcResource , resourceMappings ); err != nil {
284+ if err = r .processBackendTLSPolicies (ctx , gwcResource , gwcResourceMapping ); err != nil {
275285 r .log .Error (err , fmt .Sprintf ("failed processBackendTLSPolicies for gatewayClass %s, skipping it" , managedGC .Name ))
276286 continue
277287 }
278288 }
279289
280290 if r .eepCRDExists {
281291 // Add all EnvoyExtensionPolicies and their referenced resources to the resourceTree
282- if err = r .processEnvoyExtensionPolicies (ctx , gwcResource , resourceMappings ); err != nil {
292+ if err = r .processEnvoyExtensionPolicies (ctx , gwcResource , gwcResourceMapping ); err != nil {
283293 r .log .Error (err , fmt .Sprintf ("failed processEnvoyExtensionPolicies for gatewayClass %s, skipping it" , managedGC .Name ))
284294 continue
285295 }
@@ -300,11 +310,11 @@ func (r *gatewayAPIReconciler) Reconcile(ctx context.Context, _ reconcile.Reques
300310 // Add the referenced services, ServiceImports, and EndpointSlices in
301311 // the collected BackendRefs to the resourceTree.
302312 // BackendRefs are referred by various Route objects and the ExtAuth in SecurityPolicies.
303- r .processBackendRefs (ctx , gwcResource , resourceMappings )
313+ r .processBackendRefs (ctx , gwcResource , gwcResourceMapping )
304314
305315 // For this particular Gateway, and all associated objects, check whether the
306316 // namespace exists. Add to the resourceTree.
307- for ns := range resourceMappings .allAssociatedNamespaces {
317+ for ns := range gwcResourceMapping .allAssociatedNamespaces {
308318 namespace , err := r .getNamespace (ctx , ns )
309319 if err != nil {
310320 r .log .Error (err , "unable to find the namespace" )
@@ -1271,11 +1281,6 @@ func (r *gatewayAPIReconciler) processSecurityPolicies(
12711281 // Add the referenced Resources in SecurityPolicies to the resourceTree
12721282 r .processSecurityPolicyObjectRefs (ctx , resourceTree , resourceMap )
12731283
1274- // Add the OIDC HMAC Secret to the resourceTree
1275- r .processOIDCHMACSecret (ctx , resourceTree , resourceMap )
1276-
1277- // Add the Envoy TLS Secret to the resourceTree
1278- r .processEnvoyTLSSecret (ctx , resourceTree , resourceMap )
12791284 return nil
12801285}
12811286
@@ -2045,7 +2050,7 @@ func (r *gatewayAPIReconciler) processGatewayClassParamsRef(ctx context.Context,
20452050
20462051 // Check for incompatible configuration: both MergeGateways and GatewayNamespaceMode enabled
20472052 if r .gatewayNamespaceMode && ep .Spec .MergeGateways != nil && * ep .Spec .MergeGateways {
2048- return fmt . Errorf ("using Merged Gateways with Gateway Namespace Mode is not supported. " )
2053+ return errors . New ("using Merged Gateways with Gateway Namespace Mode is not supported" )
20492054 }
20502055
20512056 if err := r .processEnvoyProxy (ep , resourceMap ); err != nil {
0 commit comments