Skip to content

Commit

Permalink
Set mergeGateways to Translator receiver
Browse files Browse the repository at this point in the history
Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>
  • Loading branch information
cnvergence committed Oct 11, 2023
1 parent 15efb53 commit a660419
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
6 changes: 2 additions & 4 deletions internal/gatewayapi/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ type AddressesTranslator interface {
func (t *Translator) ProcessAddresses(gateways []*GatewayContext, xdsIR XdsIRMap, infraIR InfraIRMap, resources *Resources) {
for _, gateway := range gateways {
// Infra IR already exist
var irKey string
if isMergeGatewaysEnabled(resources) {
irKey := irStringKey(gateway.Gateway.Namespace, gateway.Gateway.Name)
if t.MergeGateways {
irKey = string(t.GatewayClassName)
} else {
irKey = irStringKey(gateway.Gateway.Namespace, gateway.Gateway.Name)
}

gwInfraIR := infraIR[irKey]
Expand Down
9 changes: 3 additions & 6 deletions internal/gatewayapi/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR XdsIRMap
t.validateConflictedLayer7Listeners(gateways)
t.validateConflictedLayer4Listeners(gateways, v1beta1.TCPProtocolType, v1beta1.TLSProtocolType)
t.validateConflictedLayer4Listeners(gateways, v1beta1.UDPProtocolType)
if isMergeGatewaysEnabled(resources) {
if t.MergeGateways {
t.validateConflictedMergedListeners(gateways)
}

Expand All @@ -37,13 +37,10 @@ func (t *Translator) ProcessListeners(gateways []*GatewayContext, xdsIR XdsIRMap
for _, gateway := range gateways {
// Infra IR proxy ports must be unique.
var foundPorts []*protocolPort
var irKey string

if isMergeGatewaysEnabled(resources) {
t.validateConflictedMergedListeners(gateways)
irKey := irStringKey(gateway.Gateway.Namespace, gateway.Gateway.Name)
if t.MergeGateways {
irKey = string(t.GatewayClassName)
} else {
irKey = irStringKey(gateway.Gateway.Namespace, gateway.Gateway.Name)
}

if resources.EnvoyProxy != nil {
Expand Down
30 changes: 11 additions & 19 deletions internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (t *Translator) processHTTPRouteParentRefs(httpRoute *HTTPRouteContext, res
continue
}

var hasHostnameIntersection = t.processHTTPRouteParentRefListener(httpRoute, routeRoutes, parentRef, xdsIR, resources)
var hasHostnameIntersection = t.processHTTPRouteParentRefListener(httpRoute, routeRoutes, parentRef, xdsIR)
if !hasHostnameIntersection {
parentRef.SetCondition(httpRoute,
v1beta1.RouteConditionAccepted,
Expand Down Expand Up @@ -346,7 +346,7 @@ func (t *Translator) processGRPCRouteParentRefs(grpcRoute *GRPCRouteContext, res
if parentRef.HasCondition(grpcRoute, v1beta1.RouteConditionAccepted, metav1.ConditionFalse) {
continue
}
var hasHostnameIntersection = t.processHTTPRouteParentRefListener(grpcRoute, routeRoutes, parentRef, xdsIR, resources)
var hasHostnameIntersection = t.processHTTPRouteParentRefListener(grpcRoute, routeRoutes, parentRef, xdsIR)
if !hasHostnameIntersection {
parentRef.SetCondition(grpcRoute,
v1beta1.RouteConditionAccepted,
Expand Down Expand Up @@ -510,7 +510,7 @@ func (t *Translator) processGRPCRouteMethodRegularExpression(method *v1alpha2.GR
}
}

func (t *Translator) processHTTPRouteParentRefListener(route RouteContext, routeRoutes []*ir.HTTPRoute, parentRef *RouteParentContext, xdsIR XdsIRMap, resources *Resources) bool {
func (t *Translator) processHTTPRouteParentRefListener(route RouteContext, routeRoutes []*ir.HTTPRoute, parentRef *RouteParentContext, xdsIR XdsIRMap) bool {
var hasHostnameIntersection bool

for _, listener := range parentRef.listeners {
Expand Down Expand Up @@ -570,11 +570,9 @@ func (t *Translator) processHTTPRouteParentRefListener(route RouteContext, route
perHostRoutes = append(perHostRoutes, hostRoute)
}
}
var irKey string
if isMergeGatewaysEnabled(resources) {
irKey := irStringKey(listener.gateway.Namespace, listener.gateway.Name)
if t.MergeGateways {
irKey = string(t.GatewayClassName)
} else {
irKey = irStringKey(listener.gateway.Namespace, listener.gateway.Name)
}

irListener := xdsIR[irKey].GetHTTPListener(irHTTPListenerName(listener))
Expand Down Expand Up @@ -672,11 +670,9 @@ func (t *Translator) processTLSRouteParentRefs(tlsRoute *TLSRouteContext, resour

hasHostnameIntersection = true

var irKey string
if isMergeGatewaysEnabled(resources) {
irKey := irStringKey(listener.gateway.Namespace, listener.gateway.Name)
if t.MergeGateways {
irKey = string(t.GatewayClassName)
} else {
irKey = irStringKey(listener.gateway.Namespace, listener.gateway.Name)
}

containerPort := servicePortToContainerPort(int32(listener.Port))
Expand Down Expand Up @@ -817,11 +813,9 @@ func (t *Translator) processUDPRouteParentRefs(udpRoute *UDPRouteContext, resour
}
accepted = true

var irKey string
if isMergeGatewaysEnabled(resources) {
irKey := irStringKey(listener.gateway.Namespace, listener.gateway.Name)
if t.MergeGateways {
irKey = string(t.GatewayClassName)
} else {
irKey = irStringKey(listener.gateway.Namespace, listener.gateway.Name)
}

containerPort := servicePortToContainerPort(int32(listener.Port))
Expand Down Expand Up @@ -959,11 +953,9 @@ func (t *Translator) processTCPRouteParentRefs(tcpRoute *TCPRouteContext, resour
}
accepted = true

var irKey string
if isMergeGatewaysEnabled(resources) {
irKey := irStringKey(listener.gateway.Namespace, listener.gateway.Name)
if t.MergeGateways {
irKey = string(t.GatewayClassName)
} else {
irKey = irStringKey(listener.gateway.Namespace, listener.gateway.Name)
}

containerPort := servicePortToContainerPort(int32(listener.Port))
Expand Down
5 changes: 5 additions & 0 deletions internal/gatewayapi/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ type Translator struct {
// instead.
EndpointRoutingDisabled bool

// MergeGateways is true when all Gateway Listeners
// should be merged under the parent GatewayClass.
MergeGateways bool

// ExtensionGroupKinds stores the group/kind for all resources
// introduced by an Extension so that the translator can
// store referenced resources in the IR for later use.
Expand Down Expand Up @@ -196,6 +200,7 @@ func (t *Translator) InitIRs(gateways []*GatewayContext, resources *Resources) (
gwXdsIR := &ir.Xds{}
gwInfraIR := ir.NewInfra()
if isMergeGatewaysEnabled(resources) {
t.MergeGateways = true
irKey = string(t.GatewayClassName)
gwInfraIR.Proxy.GetProxyMetadata().Labels = GatewayClassOwnerLabel(string(t.GatewayClassName))
} else {
Expand Down

0 comments on commit a660419

Please sign in to comment.