-
Notifications
You must be signed in to change notification settings - Fork 360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Multiple RequestMirrors Filters per HTTPRoute Rule #1819
Changes from 1 commit
e7a1f39
d903853
8ea547d
c70320e
c1b816c
219949f
ba0a590
94e9217
be5748d
d0ff46d
17eff36
e86e473
1b4c8a2
cb3254a
93cc046
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ type HTTPFiltersTranslator interface { | |
processRedirectFilter(redirect *v1beta1.HTTPRequestRedirectFilter, filterContext *HTTPFiltersContext) | ||
processRequestHeaderModifierFilter(headerModifier *v1beta1.HTTPHeaderFilter, filterContext *HTTPFiltersContext) | ||
processResponseHeaderModifierFilter(headerModifier *v1beta1.HTTPHeaderFilter, filterContext *HTTPFiltersContext) | ||
processRequestMirrorFilter(mirror *v1beta1.HTTPRequestMirrorFilter, filterContext *HTTPFiltersContext, resources *Resources) | ||
processRequestMirrorFilter(filterIdx int, mirror *v1beta1.HTTPRequestMirrorFilter, filterContext *HTTPFiltersContext, resources *Resources) | ||
processExtensionRefHTTPFilter(extRef *v1beta1.LocalObjectReference, filterContext *HTTPFiltersContext, resources *Resources) | ||
processUnsupportedHTTPFilter(filterType string, filterContext *HTTPFiltersContext) | ||
} | ||
|
@@ -56,7 +56,7 @@ type HTTPFilterIR struct { | |
AddResponseHeaders []ir.AddHeader | ||
RemoveResponseHeaders []string | ||
|
||
Mirror *ir.RouteDestination | ||
Mirror []*ir.RouteDestination | ||
|
||
RequestAuthentication *ir.RequestAuthentication | ||
RateLimit *ir.RateLimit | ||
|
@@ -76,7 +76,7 @@ func (t *Translator) ProcessHTTPFilters(parentRef *RouteParentContext, | |
RuleIdx: ruleIdx, | ||
HTTPFilterIR: &HTTPFilterIR{}, | ||
} | ||
|
||
filterIdx := 0 | ||
for i := range filters { | ||
filter := filters[i] | ||
// If an invalid filter type has been configured then skip processing any more filters | ||
|
@@ -98,7 +98,8 @@ func (t *Translator) ProcessHTTPFilters(parentRef *RouteParentContext, | |
case v1beta1.HTTPRouteFilterResponseHeaderModifier: | ||
t.processResponseHeaderModifierFilter(filter.ResponseHeaderModifier, httpFiltersContext) | ||
case v1beta1.HTTPRouteFilterRequestMirror: | ||
t.processRequestMirrorFilter(filter.RequestMirror, httpFiltersContext, resources) | ||
t.processRequestMirrorFilter(filterIdx, filter.RequestMirror, httpFiltersContext, resources) | ||
filterIdx++ | ||
case v1beta1.HTTPRouteFilterExtensionRef: | ||
t.processExtensionRefHTTPFilter(filter.ExtensionRef, httpFiltersContext, resources) | ||
default: | ||
|
@@ -120,7 +121,7 @@ func (t *Translator) ProcessGRPCFilters(parentRef *RouteParentContext, | |
|
||
HTTPFilterIR: &HTTPFilterIR{}, | ||
} | ||
|
||
filterIdx := 0 | ||
for i := range filters { | ||
filter := filters[i] | ||
// If an invalid filter type has been configured then skip processing any more filters | ||
|
@@ -138,7 +139,8 @@ func (t *Translator) ProcessGRPCFilters(parentRef *RouteParentContext, | |
case v1alpha2.GRPCRouteFilterResponseHeaderModifier: | ||
t.processResponseHeaderModifierFilter(filter.ResponseHeaderModifier, httpFiltersContext) | ||
case v1alpha2.GRPCRouteFilterRequestMirror: | ||
t.processRequestMirrorFilter(filter.RequestMirror, httpFiltersContext, resources) | ||
t.processRequestMirrorFilter(filterIdx, filter.RequestMirror, httpFiltersContext, resources) | ||
filterIdx++ | ||
case v1alpha2.GRPCRouteFilterExtensionRef: | ||
t.processExtensionRefHTTPFilter(filter.ExtensionRef, httpFiltersContext, resources) | ||
default: | ||
|
@@ -808,6 +810,7 @@ func (t *Translator) processExtensionRefHTTPFilter(extFilter *v1beta1.LocalObjec | |
} | ||
|
||
func (t *Translator) processRequestMirrorFilter( | ||
filterIdx int, | ||
mirrorFilter *v1beta1.HTTPRequestMirrorFilter, | ||
filterContext *HTTPFiltersContext, | ||
resources *Resources) { | ||
|
@@ -839,22 +842,26 @@ func (t *Translator) processRequestMirrorFilter( | |
// Only add missing mirror destinations | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo this entire logic of adding missing mirror destinations can be removed, and so you can simplify this logic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Are we building filterContext.Mirror from scratch and there is no duplicate Endpoints? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes we dont need to consider the duplicate case, please go ahead and refactor |
||
for _, mirrorEp := range mirrorEndpoints { | ||
var found bool | ||
if filterContext.Mirror != nil { | ||
for _, mirror := range filterContext.Mirror.Endpoints { | ||
if filterContext.Mirror != nil && filterIdx < len(filterContext.Mirror) { | ||
for _, mirror := range filterContext.Mirror[filterIdx].Endpoints { | ||
if mirror != nil { | ||
if mirror.Host == mirrorEp.Host && mirror.Port == mirrorEp.Port { | ||
found = true | ||
} | ||
} | ||
} | ||
} | ||
|
||
if !found { | ||
if filterContext.Mirror == nil { | ||
filterContext.Mirror = &ir.RouteDestination{ | ||
Name: fmt.Sprintf("%s-mirror", irRouteDestinationName(filterContext.Route, filterContext.RuleIdx)), | ||
if filterContext.Mirror == nil || filterIdx >= len(filterContext.Mirror) { | ||
newMirror := &ir.RouteDestination{ | ||
Name: fmt.Sprintf("%s-mirror-%d", irRouteDestinationName(filterContext.Route, filterContext.RuleIdx), filterIdx), | ||
} | ||
newMirror.Endpoints = append(newMirror.Endpoints, mirrorEp) | ||
filterContext.Mirror = append(filterContext.Mirror, newMirror) | ||
} else { | ||
filterContext.Mirror[filterIdx].Endpoints = append(filterContext.Mirror[filterIdx].Endpoints, mirrorEp) | ||
} | ||
filterContext.Mirror.Endpoints = append(filterContext.Mirror.Endpoints, mirrorEp) | ||
} | ||
} | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use i
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I can use 'i' if I don't need to match the value with the index of Mirror list.