Skip to content

Commit e588bac

Browse files
committed
Flatten emitter HTTPRoute ingress features
- Remove the emitter HTTPRoute IngressNginx wrapper. - Project ingress-derived feature fields directly on HTTPRouteContext using provider-neutral type names. - Restructure provider_intermediate conversion to match upstream shape. - Move downstream ingress feature projection into a dedicated helper file for easier future rebases. Signed-off-by: Daneyon Hansen <daneyon.hansen@solo.io>
1 parent f4c867b commit e588bac

9 files changed

Lines changed: 359 additions & 347 deletions

File tree

pkg/i2gw/emitter_intermediate/intermediate_representation.go

Lines changed: 83 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,20 @@ type GatewayContext struct {
5656

5757
type HTTPRouteContext struct {
5858
gatewayv1.HTTPRoute
59-
// IngressNginx contains ingress-nginx-specific IR data for kgateway emitter
60-
IngressNginx *IngressNginxHTTPRouteIR
61-
// RuleBackendSources tracks the source Ingress resources for each backend
59+
60+
// PoliciesBySourceIngressName stores feature policy data keyed by source Ingress name.
61+
PoliciesBySourceIngressName map[string]Policy
62+
63+
// RegexLocationForHost is true when regex location matching should be used for the route host.
64+
RegexLocationForHost *bool
65+
66+
// RegexForcedByUseRegex is true when RegexLocationForHost is driven by use-regex annotation.
67+
RegexForcedByUseRegex bool
68+
69+
// RegexForcedByRewrite is true when RegexLocationForHost is driven by rewrite-target annotation.
70+
RegexForcedByRewrite bool
71+
72+
// RuleBackendSources tracks the source Ingress resources for each backend.
6273
RuleBackendSources [][]BackendSource
6374
}
6475

@@ -104,38 +115,14 @@ type ReferenceGrantContext struct {
104115
gatewayv1beta1.ReferenceGrant
105116
}
106117

107-
// IngressNginxGatewayIR is the emitter-side ingress-nginx gateway IR.
108-
type IngressNginxGatewayIR struct{}
109-
110-
// IngressNginxServiceIR is the emitter-side ingress-nginx service IR.
111-
type IngressNginxServiceIR struct{}
112-
113-
// IngressNginxHTTPRouteIR contains ingress-nginx-specific fields for HTTPRoute.
114-
type IngressNginxHTTPRouteIR struct {
115-
// Policies keyed by source Ingress name.
116-
Policies map[string]IngressNginxPolicy
117-
118-
// RegexLocationForHost is true when ingress-nginx would enforce the "~*" (case-insensitive)
119-
// regex location modifier for all paths under a host.
120-
RegexLocationForHost *bool
121-
122-
// RegexForcedByUseRegex is true when RegexLocationForHost is true specifically
123-
// because of the nginx.ingress.kubernetes.io/use-regex annotation.
124-
RegexForcedByUseRegex bool
125-
126-
// RegexForcedByRewrite is true when RegexLocationForHost is true specifically
127-
// because of the nginx.ingress.kubernetes.io/rewrite-target annotation.
128-
RegexForcedByRewrite bool
129-
}
130-
131-
// IngressNginxPolicyIndex identifies a (rule, backend) pair within a merged HTTPRoute.
132-
type IngressNginxPolicyIndex struct {
118+
// PolicyIndex identifies a (rule, backend) pair within a merged HTTPRoute.
119+
type PolicyIndex struct {
133120
Rule int
134121
Backend int
135122
}
136123

137-
// IngressNginxCorsPolicy defines a CORS policy extracted from ingress-nginx annotations.
138-
type IngressNginxCorsPolicy struct {
124+
// CorsPolicy defines a CORS policy extracted from annotations.
125+
type CorsPolicy struct {
139126
Enable bool
140127
AllowOrigin []string
141128
AllowCredentials *bool
@@ -145,20 +132,20 @@ type IngressNginxCorsPolicy struct {
145132
MaxAge *int32
146133
}
147134

148-
// IngressNginxExtAuthPolicy defines an external auth policy extracted from ingress-nginx annotations.
149-
type IngressNginxExtAuthPolicy struct {
135+
// ExtAuthPolicy defines an external auth policy extracted from annotations.
136+
type ExtAuthPolicy struct {
150137
AuthURL string
151138
ResponseHeaders []string
152139
}
153140

154-
// IngressNginxBasicAuthPolicy defines a basic auth policy extracted from ingress-nginx annotations.
155-
type IngressNginxBasicAuthPolicy struct {
141+
// BasicAuthPolicy defines a basic auth policy extracted from annotations.
142+
type BasicAuthPolicy struct {
156143
SecretName string
157144
AuthType string
158145
}
159146

160-
// IngressNginxSessionAffinityPolicy defines a session affinity policy extracted from ingress-nginx annotations.
161-
type IngressNginxSessionAffinityPolicy struct {
147+
// SessionAffinityPolicy defines a session affinity policy extracted from annotations.
148+
type SessionAffinityPolicy struct {
162149
CookieName string
163150
CookiePath string
164151
CookieDomain string
@@ -167,99 +154,99 @@ type IngressNginxSessionAffinityPolicy struct {
167154
CookieSecure *bool
168155
}
169156

170-
// IngressNginxBackendTLSPolicy defines a backend TLS policy extracted from ingress-nginx annotations.
171-
type IngressNginxBackendTLSPolicy struct {
157+
// BackendTLSPolicy defines a backend TLS policy extracted from annotations.
158+
type BackendTLSPolicy struct {
172159
SecretName string
173160
Verify bool
174161
Hostname string
175162
}
176163

177-
// IngressNginxPolicy describes per-Ingress policy knobs projected from ingress-nginx.
178-
type IngressNginxPolicy struct {
164+
// Policy describes per-Ingress policy knobs projected by providers.
165+
type Policy struct {
179166
ClientBodyBufferSize *resource.Quantity
180167
ProxyBodySize *resource.Quantity
181-
Cors *IngressNginxCorsPolicy
182-
RateLimit *IngressNginxRateLimitPolicy
168+
Cors *CorsPolicy
169+
RateLimit *RateLimitPolicy
183170
ProxySendTimeout *metav1.Duration
184171
ProxyReadTimeout *metav1.Duration
185172
ProxyConnectTimeout *metav1.Duration
186173
EnableAccessLog *bool
187-
ExtAuth *IngressNginxExtAuthPolicy
188-
BasicAuth *IngressNginxBasicAuthPolicy
189-
SessionAffinity *IngressNginxSessionAffinityPolicy
190-
LoadBalancing *IngressNginxBackendLoadBalancingPolicy
191-
BackendTLS *IngressNginxBackendTLSPolicy
192-
BackendProtocol *IngressNginxBackendProtocol
174+
ExtAuth *ExtAuthPolicy
175+
BasicAuth *BasicAuthPolicy
176+
SessionAffinity *SessionAffinityPolicy
177+
LoadBalancing *BackendLoadBalancingPolicy
178+
BackendTLS *BackendTLSPolicy
179+
BackendProtocol *BackendProtocol
193180
SSLRedirect *bool
194181
RewriteTarget *string
195182
UseRegexPaths *bool
196183

197184
// RuleBackendSources lists covered (rule, backend) pairs in the merged HTTPRoute.
198-
RuleBackendSources []IngressNginxPolicyIndex
185+
RuleBackendSources []PolicyIndex
199186

200187
// Backends holds all proxied backends that cannot be rendered as a standard k8s service.
201-
Backends map[types.NamespacedName]IngressNginxBackend
188+
Backends map[types.NamespacedName]Backend
202189

203190
// ruleBackendIndexSet is an internal helper used to deduplicate RuleBackendSources entries.
204-
ruleBackendIndexSet map[IngressNginxPolicyIndex]struct{}
191+
ruleBackendIndexSet map[PolicyIndex]struct{}
205192
}
206193

207-
// IngressNginxBackendProtocol defines the L7 protocol used to talk to a Backend.
208-
type IngressNginxBackendProtocol string
194+
// BackendProtocol defines the L7 protocol used to talk to a Backend.
195+
type BackendProtocol string
209196

210-
// IngressNginxBackendProtocolGRPC is the gRPC protocol.
211-
const IngressNginxBackendProtocolGRPC IngressNginxBackendProtocol = "grpc"
197+
// BackendProtocolGRPC is the gRPC protocol.
198+
const BackendProtocolGRPC BackendProtocol = "grpc"
212199

213-
// IngressNginxBackend defines a proxied backend that cannot be rendered as a standard k8s Service.
214-
type IngressNginxBackend struct {
200+
// Backend defines a proxied backend that cannot be rendered as a standard k8s Service.
201+
type Backend struct {
215202
Namespace string
216203
Name string
217204
Port int32
218205
Host string
219-
Protocol *IngressNginxBackendProtocol
206+
Protocol *BackendProtocol
220207
}
221208

222-
// IngressNginxRateLimitUnit defines the unit of rate limiting.
223-
type IngressNginxRateLimitUnit string
209+
// RateLimitUnit defines the unit of rate limiting.
210+
type RateLimitUnit string
224211

225212
const (
226-
// IngressNginxRateLimitUnitRPS defines rate limit in requests per second.
227-
IngressNginxRateLimitUnitRPS IngressNginxRateLimitUnit = "rps"
228-
// IngressNginxRateLimitUnitRPM defines rate limit in requests per minute.
229-
IngressNginxRateLimitUnitRPM IngressNginxRateLimitUnit = "rpm"
213+
// RateLimitUnitRPS defines rate limit in requests per second.
214+
RateLimitUnitRPS RateLimitUnit = "rps"
215+
// RateLimitUnitRPM defines rate limit in requests per minute.
216+
RateLimitUnitRPM RateLimitUnit = "rpm"
230217
)
231218

232-
// IngressNginxRateLimitPolicy defines a rate limiting policy derived from ingress-nginx annotations.
233-
type IngressNginxRateLimitPolicy struct {
219+
// RateLimitPolicy defines a rate limiting policy derived from annotations.
220+
type RateLimitPolicy struct {
234221
Limit int32
235-
Unit IngressNginxRateLimitUnit
222+
Unit RateLimitUnit
236223
BurstMultiplier int32
237224
}
238225

239-
// IngressNginxLoadBalancingStrategy represents upstream load-balancing mode.
240-
type IngressNginxLoadBalancingStrategy string
226+
// LoadBalancingStrategy represents upstream load-balancing mode.
227+
type LoadBalancingStrategy string
241228

242-
// IngressNginxLoadBalancingStrategyRoundRobin is the supported round_robin strategy.
243-
const IngressNginxLoadBalancingStrategyRoundRobin IngressNginxLoadBalancingStrategy = "round_robin"
229+
// LoadBalancingStrategyRoundRobin is the supported round_robin strategy.
230+
const LoadBalancingStrategyRoundRobin LoadBalancingStrategy = "round_robin"
244231

245-
// IngressNginxBackendLoadBalancingPolicy defines backend load-balancing policy.
246-
type IngressNginxBackendLoadBalancingPolicy struct {
247-
Strategy IngressNginxLoadBalancingStrategy
232+
// BackendLoadBalancingPolicy defines backend load-balancing policy.
233+
type BackendLoadBalancingPolicy struct {
234+
Strategy LoadBalancingStrategy
248235
}
249236

250237
// AddRuleBackendSources returns a copy of p with idxs added to RuleBackendSources,
251238
// ensuring each (rule, backend) pair is unique.
252-
func (p IngressNginxPolicy) AddRuleBackendSources(idxs []IngressNginxPolicyIndex) IngressNginxPolicy {
239+
func (p Policy) AddRuleBackendSources(idxs []PolicyIndex) Policy {
253240
pCopy := p
254241

255242
if len(pCopy.RuleBackendSources) > 0 && pCopy.ruleBackendIndexSet == nil {
256-
pCopy.ruleBackendIndexSet = make(map[IngressNginxPolicyIndex]struct{}, len(pCopy.RuleBackendSources))
243+
pCopy.ruleBackendIndexSet = make(map[PolicyIndex]struct{}, len(pCopy.RuleBackendSources))
257244
for _, existing := range pCopy.RuleBackendSources {
258245
pCopy.ruleBackendIndexSet[existing] = struct{}{}
259246
}
260247
}
261248
if pCopy.ruleBackendIndexSet == nil {
262-
pCopy.ruleBackendIndexSet = make(map[IngressNginxPolicyIndex]struct{})
249+
pCopy.ruleBackendIndexSet = make(map[PolicyIndex]struct{})
263250
}
264251

265252
for _, idx := range idxs {
@@ -273,38 +260,38 @@ func (p IngressNginxPolicy) AddRuleBackendSources(idxs []IngressNginxPolicyIndex
273260
return pCopy
274261
}
275262

276-
// Type aliases for emitter code ergonomics.
263+
// Backward-compatibility aliases for older ingress-nginx-prefixed names.
277264

278-
type Policy = IngressNginxPolicy
265+
type IngressNginxPolicy = Policy
279266

280-
type PolicyIndex = IngressNginxPolicyIndex
267+
type IngressNginxPolicyIndex = PolicyIndex
281268

282-
type CorsPolicy = IngressNginxCorsPolicy
269+
type IngressNginxCorsPolicy = CorsPolicy
283270

284-
type ExtAuthPolicy = IngressNginxExtAuthPolicy
271+
type IngressNginxExtAuthPolicy = ExtAuthPolicy
285272

286-
type BasicAuthPolicy = IngressNginxBasicAuthPolicy
273+
type IngressNginxBasicAuthPolicy = BasicAuthPolicy
287274

288-
type SessionAffinityPolicy = IngressNginxSessionAffinityPolicy
275+
type IngressNginxSessionAffinityPolicy = SessionAffinityPolicy
289276

290-
type BackendTLSPolicy = IngressNginxBackendTLSPolicy
277+
type IngressNginxBackendTLSPolicy = BackendTLSPolicy
291278

292-
type BackendProtocol = IngressNginxBackendProtocol
279+
type IngressNginxBackendProtocol = BackendProtocol
293280

294-
const BackendProtocolGRPC = IngressNginxBackendProtocolGRPC
281+
const IngressNginxBackendProtocolGRPC = BackendProtocolGRPC
295282

296-
type Backend = IngressNginxBackend
283+
type IngressNginxBackend = Backend
297284

298-
type RateLimitUnit = IngressNginxRateLimitUnit
285+
type IngressNginxRateLimitUnit = RateLimitUnit
299286

300-
const RateLimitUnitRPS = IngressNginxRateLimitUnitRPS
287+
const IngressNginxRateLimitUnitRPS = RateLimitUnitRPS
301288

302-
const RateLimitUnitRPM = IngressNginxRateLimitUnitRPM
289+
const IngressNginxRateLimitUnitRPM = RateLimitUnitRPM
303290

304-
type RateLimitPolicy = IngressNginxRateLimitPolicy
291+
type IngressNginxRateLimitPolicy = RateLimitPolicy
305292

306-
type LoadBalancingStrategy = IngressNginxLoadBalancingStrategy
293+
type IngressNginxLoadBalancingStrategy = LoadBalancingStrategy
307294

308-
const LoadBalancingStrategyRoundRobin = IngressNginxLoadBalancingStrategyRoundRobin
295+
const IngressNginxLoadBalancingStrategyRoundRobin = LoadBalancingStrategyRoundRobin
309296

310-
type BackendLoadBalancingPolicy = IngressNginxBackendLoadBalancingPolicy
297+
type IngressNginxBackendLoadBalancingPolicy = BackendLoadBalancingPolicy

pkg/i2gw/emitters/agentgateway/emitter.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,22 @@ func (e *Emitter) Emit(ir emitterir.EmitterIR) (i2gw.GatewayResources, field.Err
7575
basicAuthSecretSeen := map[basicAuthSecretKey]struct{}{}
7676

7777
for httpRouteKey, httpRouteContext := range ir.HTTPRoutes {
78-
ingx := httpRouteContext.IngressNginx
79-
if ingx == nil {
78+
if len(httpRouteContext.PoliciesBySourceIngressName) == 0 {
8079
continue
8180
}
8281

8382
// Apply host-wide regex enforcement first (so rule path regex is finalized)
8483
// TODO: implement regex path matching if needed
8584

8685
// deterministic policy iteration
87-
policyNames := make([]string, 0, len(ingx.Policies))
88-
for name := range ingx.Policies {
86+
policyNames := make([]string, 0, len(httpRouteContext.PoliciesBySourceIngressName))
87+
for name := range httpRouteContext.PoliciesBySourceIngressName {
8988
policyNames = append(policyNames, name)
9089
}
9190
sort.Strings(policyNames)
9291

9392
for _, polSourceIngressName := range policyNames {
94-
pol := ingx.Policies[polSourceIngressName]
93+
pol := httpRouteContext.PoliciesBySourceIngressName[polSourceIngressName]
9594

9695
// Normalize (rule, backend) coverage to unique pairs to avoid
9796
// generating duplicate filters on the same backendRef.

pkg/i2gw/emitters/agentgateway/ssl_redirect.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
// Semantics:
3333
// - If SSLRedirect is enabled, mark the HTTPRoute for later splitting
3434
// - Returns true if SSL redirect is enabled for this policy
35-
func applySSLRedirectPolicy(pol emitterir.IngressNginxPolicy) bool {
35+
func applySSLRedirectPolicy(pol emitterir.Policy) bool {
3636
if pol.SSLRedirect == nil || !*pol.SSLRedirect {
3737
return false
3838
}
@@ -83,9 +83,12 @@ func splitHTTPRouteForSSLRedirect(
8383

8484
// Create HTTP redirect route
8585
httpRedirectRoute := emitterir.HTTPRouteContext{
86-
HTTPRoute: *httpRouteContext.HTTPRoute.DeepCopy(),
87-
IngressNginx: httpRouteContext.IngressNginx,
88-
RuleBackendSources: httpRouteContext.RuleBackendSources,
86+
HTTPRoute: *httpRouteContext.HTTPRoute.DeepCopy(),
87+
PoliciesBySourceIngressName: httpRouteContext.PoliciesBySourceIngressName,
88+
RegexLocationForHost: httpRouteContext.RegexLocationForHost,
89+
RegexForcedByUseRegex: httpRouteContext.RegexForcedByUseRegex,
90+
RegexForcedByRewrite: httpRouteContext.RegexForcedByRewrite,
91+
RuleBackendSources: httpRouteContext.RuleBackendSources,
8992
}
9093
httpRedirectRoute.ObjectMeta.Name = fmt.Sprintf("%s-http-redirect", httpRouteKey.Name)
9194
httpRedirectRoute.ObjectMeta.Namespace = httpRouteKey.Namespace
@@ -125,9 +128,12 @@ func splitHTTPRouteForSSLRedirect(
125128
var httpsBackendRoute *emitterir.HTTPRouteContext
126129
if httpsListenerName != nil {
127130
route := emitterir.HTTPRouteContext{
128-
HTTPRoute: *httpRouteContext.HTTPRoute.DeepCopy(),
129-
IngressNginx: httpRouteContext.IngressNginx,
130-
RuleBackendSources: httpRouteContext.RuleBackendSources,
131+
HTTPRoute: *httpRouteContext.HTTPRoute.DeepCopy(),
132+
PoliciesBySourceIngressName: httpRouteContext.PoliciesBySourceIngressName,
133+
RegexLocationForHost: httpRouteContext.RegexLocationForHost,
134+
RegexForcedByUseRegex: httpRouteContext.RegexForcedByUseRegex,
135+
RegexForcedByRewrite: httpRouteContext.RegexForcedByRewrite,
136+
RuleBackendSources: httpRouteContext.RuleBackendSources,
131137
}
132138
route.ObjectMeta.Name = fmt.Sprintf("%s-https", httpRouteKey.Name)
133139
route.ObjectMeta.Namespace = httpRouteKey.Namespace

pkg/i2gw/emitters/kgateway/emitter.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ func (e *Emitter) Emit(ir emitterir.EmitterIR) (i2gw.GatewayResources, field.Err
8686
routesToSplitForSSLRedirect := map[types.NamespacedName]bool{}
8787

8888
for httpRouteKey, httpRouteContext := range ir.HTTPRoutes {
89-
ingx := httpRouteContext.IngressNginx
90-
if ingx == nil {
89+
if len(httpRouteContext.PoliciesBySourceIngressName) == 0 {
9190
continue
9291
}
9392

@@ -98,22 +97,23 @@ func (e *Emitter) Emit(ir emitterir.EmitterIR) (i2gw.GatewayResources, field.Err
9897
tp := map[string]*kgateway.TrafficPolicy{}
9998

10099
// Apply host-wide regex enforcement first (so rule path regex is finalized)
101-
applyRegexPathMatchingForHost(ingx, &httpRouteContext)
100+
applyRegexPathMatchingForHost(&httpRouteContext)
102101

103102
// deterministic policy iteration
104-
policyNames := make([]string, 0, len(ingx.Policies))
105-
for name := range ingx.Policies {
103+
policyNames := make([]string, 0, len(httpRouteContext.PoliciesBySourceIngressName))
104+
for name := range httpRouteContext.PoliciesBySourceIngressName {
106105
policyNames = append(policyNames, name)
107106
}
108107
sort.Strings(policyNames)
109108

110109
// Rewrite-target pass: creates per-rule TPs and attaches filters itself.
111110
for _, name := range policyNames {
112-
pol := ingx.Policies[name]
111+
pol := httpRouteContext.PoliciesBySourceIngressName[name]
113112
applyRewriteTargetPolicies(pol, name, httpRouteKey.Namespace, &httpRouteContext, tp)
114113
}
115114

116-
for polSourceIngressName, pol := range ingx.Policies {
115+
for _, polSourceIngressName := range policyNames {
116+
pol := httpRouteContext.PoliciesBySourceIngressName[polSourceIngressName]
117117
// Normalize (rule, backend) coverage to unique pairs to avoid
118118
// generating duplicate filters on the same backendRef.
119119
coverage := uniquePolicyIndices(pol.RuleBackendSources)

0 commit comments

Comments
 (0)