Skip to content

Commit

Permalink
draft coding
Browse files Browse the repository at this point in the history
Signed-off-by: Ronnie Personal <76408835+Ronnie-personal@users.noreply.github.com>
  • Loading branch information
Ronnie-personal committed Aug 23, 2023
1 parent 5bcbca7 commit b6492d0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
23 changes: 14 additions & 9 deletions internal/gatewayapi/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type HTTPFilterIR struct {
AddResponseHeaders []ir.AddHeader
RemoveResponseHeaders []string

Mirror *ir.RouteDestination
Mirror []*ir.RouteDestination

RequestAuthentication *ir.RequestAuthentication
RateLimit *ir.RateLimit
Expand Down Expand Up @@ -121,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
Expand All @@ -139,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:
Expand Down Expand Up @@ -841,22 +842,26 @@ func (t *Translator) processRequestMirrorFilter(
// Only add missing mirror destinations
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)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions internal/ir/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,10 @@ func (h HTTPRoute) Validate() error {
}
}
if h.Mirror != nil {
if err := h.Mirror.Validate(); err != nil {
errs = multierror.Append(errs, err)
for _, mirror := range h.Mirror {
if err := mirror.Validate(); err != nil {
errs = multierror.Append(errs, err)
}
}
}
if len(h.AddRequestHeaders) > 0 {
Expand Down
10 changes: 8 additions & 2 deletions internal/ir/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions internal/xds/translator/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,16 @@ func (t *Translator) processHTTPListenerXdsTranslation(tCtx *types.ResourceVersi
}

if httpRoute.Mirror != nil {
if err := addXdsCluster(tCtx, addXdsClusterArgs{
name: httpRoute.Mirror.Name,
endpoints: httpRoute.Mirror.Endpoints,
tSocket: nil,
protocol: protocol,
endpointType: Static,
}); err != nil && !errors.Is(err, ErrXdsClusterExists) {
return err
for _, mirrorDest := range httpRoute.Mirror {
if err := addXdsCluster(tCtx, addXdsClusterArgs{
name: mirrorDest.Name,
endpoints: mirrorDest.Endpoints,
tSocket: nil,
protocol: protocol,
endpointType: Static,
}); err != nil && !errors.Is(err, ErrXdsClusterExists) {
return err
}
}
}
}
Expand Down

0 comments on commit b6492d0

Please sign in to comment.