@@ -30,31 +30,48 @@ func init() {
3030 HTTPRoute : map [string ]* gatewayv1beta1.HTTPRoute {},
3131 Endpoints : map [string ]* v1.Endpoints {},
3232 Service : map [string ]* v1.Service {},
33- GatewayClasses : map [string ]* gatewayv1beta1.GatewayClass {},
33+ GatewayClass : map [string ]* gatewayv1beta1.GatewayClass {},
34+ Namespace : map [string ]* v1.Namespace {},
3435 }
3536}
3637
38+ func (c * SIGCache ) SetNamespace (obj * v1.Namespace ) {
39+ c .mutex .Lock ()
40+ defer c .mutex .Unlock ()
41+
42+ if obj != nil {
43+ c .Namespace [obj .Name ] = obj
44+ }
45+ }
46+
47+ func (c * SIGCache ) UnsetNamespace (keyname string ) {
48+ c .mutex .Lock ()
49+ defer c .mutex .Unlock ()
50+
51+ delete (c .Namespace , keyname )
52+ }
53+
3754func (c * SIGCache ) SetGatewayClass (obj * gatewayv1beta1.GatewayClass ) {
3855 c .mutex .Lock ()
3956 defer c .mutex .Unlock ()
4057
4158 if obj != nil {
42- c .GatewayClasses [obj .Name ] = obj
59+ c .GatewayClass [obj .Name ] = obj
4360 }
4461}
4562
4663func (c * SIGCache ) UnsetGatewayClass (keyname string ) {
4764 c .mutex .Lock ()
4865 defer c .mutex .Unlock ()
4966
50- delete (c .GatewayClasses , keyname )
67+ delete (c .GatewayClass , keyname )
5168}
5269
5370func (c * SIGCache ) GetGatewayClass (keyname string ) * gatewayv1beta1.GatewayClass {
5471 c .mutex .RLock ()
5572 defer c .mutex .RUnlock ()
5673
57- return c .GatewayClasses [keyname ]
74+ return c .GatewayClass [keyname ]
5875}
5976
6077func (c * SIGCache ) SetGateway (obj * gatewayv1beta1.Gateway ) {
@@ -211,6 +228,15 @@ func (c *SIGCache) _attachedHTTPRoutes(gw *gatewayv1beta1.Gateway) []*gatewayv1b
211228 return []* gatewayv1beta1.HTTPRoute {}
212229 }
213230
231+ allowedRoutes := map [string ]* gatewayv1beta1.AllowedRoutes {}
232+ for _ , listener := range gw .Spec .Listeners {
233+ vsname := gwListenerName (gw , & listener )
234+
235+ if listener .AllowedRoutes != nil {
236+ allowedRoutes [vsname ] = listener .AllowedRoutes
237+ }
238+ }
239+
214240 hrs := []* gatewayv1beta1.HTTPRoute {}
215241 for _ , hr := range ActiveSIGs .HTTPRoute {
216242 for _ , pr := range hr .Spec .ParentRefs {
@@ -219,7 +245,15 @@ func (c *SIGCache) _attachedHTTPRoutes(gw *gatewayv1beta1.Gateway) []*gatewayv1b
219245 ns = string (* pr .Namespace )
220246 }
221247 if utils .Keyname (ns , string (pr .Name )) == utils .Keyname (gw .Namespace , gw .Name ) {
222- hrs = append (hrs , hr )
248+ vsname := hrParentName (hr , & pr )
249+ if allowed , ok := allowedRoutes [vsname ]; ok {
250+ if routeNs , ok := ActiveSIGs .Namespace [hr .Namespace ]; ok {
251+ matched := namespaceMatches (gw .Namespace , allowed .Namespaces , routeNs )
252+ if matched {
253+ hrs = append (hrs , hr )
254+ }
255+ }
256+ }
223257 }
224258 }
225259 }
@@ -274,7 +308,7 @@ func (c *SIGCache) AllAttachedServiceKeys() []string {
274308 defer c .mutex .RUnlock ()
275309
276310 svcs := []string {}
277- for _ , gwc := range c .GatewayClasses {
311+ for _ , gwc := range c .GatewayClass {
278312 for _ , gw := range c ._attachedGateways (gwc ) {
279313 for _ , hr := range c ._attachedHTTPRoutes (gw ) {
280314 svcs = append (svcs , c ._attachedServiceKeys (hr )... )
@@ -438,6 +472,7 @@ func (c *SIGCache) syncCoreV1Resources(mgr manager.Manager) error {
438472 c .Endpoints [utils .Keyname (eps .Namespace , eps .Name )] = eps .DeepCopy ()
439473 }
440474 }
475+
441476 if svcList , err := kubeClient .CoreV1 ().Services (v1 .NamespaceAll ).List (context .TODO (), metav1.ListOptions {}); err != nil {
442477 return err
443478 } else {
@@ -446,6 +481,16 @@ func (c *SIGCache) syncCoreV1Resources(mgr manager.Manager) error {
446481 c .Service [utils .Keyname (svc .Namespace , svc .Name )] = svc .DeepCopy ()
447482 }
448483 }
484+
485+ if nsList , err := kubeClient .CoreV1 ().Namespaces ().List (context .TODO (), metav1.ListOptions {}); err != nil {
486+ return nil
487+ } else {
488+ for _ , ns := range nsList .Items {
489+ slog .Debugf ("found ns: %s" , ns .Name )
490+ c .Namespace [ns .Name ] = ns .DeepCopy ()
491+ }
492+ }
493+
449494 if nList , err := kubeClient .CoreV1 ().Nodes ().List (context .TODO (), metav1.ListOptions {}); err != nil {
450495 return err
451496 } else {
@@ -495,7 +540,7 @@ func (c *SIGCache) syncGatewayResources(mgr manager.Manager) error {
495540 for _ , gwc := range gwcList .Items {
496541 if gwc .Spec .ControllerName == gatewayv1beta1 .GatewayController (ActiveSIGs .ControllerName ) {
497542 slog .Debugf ("found gatewayclass %s" , gwc .Name )
498- c .GatewayClasses [gwc .Name ] = gwc .DeepCopy ()
543+ c .GatewayClass [gwc .Name ] = gwc .DeepCopy ()
499544 } else {
500545 msg := fmt .Sprintf ("This gwc's ControllerName %s not equal to this controller. Ignore." , gwc .Spec .ControllerName )
501546 slog .Debugf (msg )
0 commit comments