Skip to content

Commit 5bc6890

Browse files
committed
Use gateway namespace for namespaced mode
Signed-off-by: jukie <10012479+Jukie@users.noreply.github.com>
1 parent 5e51514 commit 5bc6890

File tree

3 files changed

+8
-25
lines changed

3 files changed

+8
-25
lines changed

internal/gatewayapi/globalresources.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,14 @@ func (t *Translator) ProcessGlobalResources(resources *resource.Resources, xdsIR
5959

6060
// processServiceClusterForGateway returns the matching IR key for a gateway and builds a RouteDestination to represent the ProxyServiceCluster
6161
func (t *Translator) processServiceClusterForGateway(gateway *GatewayContext, resources *resource.Resources) (string, *ir.RouteDestination) {
62-
var (
63-
labels = make(map[string]string)
64-
irKey string
65-
)
66-
67-
if t.MergeGateways {
68-
irKey = string(t.GatewayClassName)
69-
labels[OwningGatewayClassLabel] = string(t.GatewayClassName)
70-
} else {
71-
irKey = irStringKey(gateway.Namespace, gateway.Name)
72-
labels[OwningGatewayNamespaceLabel] = gateway.Namespace
73-
labels[OwningGatewayNameLabel] = gateway.Name
74-
}
62+
irKey := t.getIRKey(gateway.Gateway)
63+
labels := OwnerLabels(gateway.Gateway, t.MergeGateways)
7564

76-
svcCluster := resources.GetServiceByLabels(labels, t.ControllerNamespace)
65+
svcClusterNamespace := t.ControllerNamespace
66+
if t.GatewayNamespaceMode {
67+
svcClusterNamespace = gateway.Namespace
68+
}
69+
svcCluster := resources.GetServiceByLabels(labels, svcClusterNamespace)
7770

7871
// Service lookup fails on first iteration
7972
if svcCluster == nil {

internal/gatewayapi/testdata/gateway-namespace-mode-infra-httproute.out.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,6 @@ xdsIR:
396396
accessLog:
397397
json:
398398
- path: /dev/stdout
399-
globalResources:
400-
proxyServiceCluster:
401-
name: test-ns/gateway-3
402-
settings:
403-
- metadata:
404-
name: envoy-default-gateway-1-bfd08ef4
405-
namespace: envoy-gateway-system
406-
sectionName: "8080"
407-
name: test-ns/gateway-3
408-
protocol: TCP
409399
http:
410400
- address: 0.0.0.0
411401
hostnames:

internal/provider/kubernetes/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ func (r *gatewayAPIReconciler) processGateways(ctx context.Context, managedGC *g
13571357
}
13581358

13591359
mergedGateways := false
1360-
if resourceTree.EnvoyProxyForGatewayClass != nil && resourceTree.EnvoyProxyForGatewayClass.Spec.MergeGateways != nil && *resourceTree.EnvoyProxyForGatewayClass.Spec.MergeGateways {
1360+
if r.mergeGateways.Has(managedGC.Name) {
13611361
mergedGateways = true
13621362
r.processServiceCluster(managedGC.Name, resourceMap)
13631363
}

0 commit comments

Comments
 (0)