Skip to content

Commit

Permalink
(Backport) fix lambda validation (#3981)
Browse files Browse the repository at this point in the history
* Fix lambda route validation bug (#3979)

* added tests and impl fix
* Merge branch 'master' into fix-lambda-validation
* Merge refs/heads/master into fix-lambda-validation
* added changelog
* edited changelog
  • Loading branch information
saiskee committed Dec 11, 2020
1 parent 841f938 commit ef59051
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
changelog:
- type: FIX
issueLink: https://github.com/solo-io/gloo/issues/3975
description: fixes bug where route validation marks routes with redirect and direct response actions as invalid.
18 changes: 11 additions & 7 deletions projects/gloo/pkg/translator/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,28 +250,32 @@ func validateUpstreamLambdaFunctions(proxy *v1.Proxy, upstreams v1.UpstreamList,
for _, virtualHost := range httpListener.GetVirtualHosts() {
// Validate all routes to make sure that if they point to a lambda, it exists.
for _, route := range virtualHost.GetRoutes() {
if route.GetDirectResponseAction() == nil {
validateRouteDestinationForValidLambdas(proxy, route.GetRouteAction(), upstreamGroups, reports, upstreamLambdas)
}
validateRouteDestinationForValidLambdas(proxy, route, upstreamGroups, reports, upstreamLambdas)
}
}
}
}
}

// Validates a route that may have a single or multi upstream destinations to make sure that any lambda upstreams are referencing valid lambdas
func validateRouteDestinationForValidLambdas(proxy *v1.Proxy, route *v1.RouteAction, upstreamGroups v1.UpstreamGroupList, reports reporter.ResourceReports, upstreamLambdas map[core.ResourceRef]map[string]bool) {
func validateRouteDestinationForValidLambdas(proxy *v1.Proxy, route *v1.Route, upstreamGroups v1.UpstreamGroupList, reports reporter.ResourceReports, upstreamLambdas map[core.ResourceRef]map[string]bool) {
// Append destinations to a destination list to process all of them in one go
var destinations []*v1.Destination

switch typedRoute := route.GetDestination().(type) {
_, ok := route.GetAction().(*v1.Route_RouteAction)
if !ok {
// If this is not a Route_RouteAction (e.g. Route_DirectResponseAction, Route_RedirectAction), there is no destination to validate
return
}
routeAction := route.GetRouteAction()
switch typedRoute := routeAction.GetDestination().(type) {
case *v1.RouteAction_Single:
{
destinations = append(destinations, route.GetSingle())
destinations = append(destinations, routeAction.GetSingle())
}
case *v1.RouteAction_Multi:
{
multiDest := route.GetMulti()
multiDest := routeAction.GetMulti()
for _, weightedDest := range multiDest.GetDestinations() {
destinations = append(destinations, weightedDest.GetDestination())
}
Expand Down
24 changes: 24 additions & 0 deletions projects/gloo/pkg/translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,30 @@ var _ = Describe("Translator", func() {
})
})

Context("non route_routeaction routes", func() {
BeforeEach(func() {
redirectRoute := &v1.Route{
Action: &v1.Route_RedirectAction{
RedirectAction: &v1.RedirectAction{
ResponseCode: 400,
},
},
}
directResponseRoute := &v1.Route{
Action: &v1.Route_DirectResponseAction{
DirectResponseAction: &v1.DirectResponseAction{
Status: 400,
},
},
}
routes = []*v1.Route{redirectRoute, directResponseRoute}
})

It("reports no errors with a redirect route or direct response route", func() {
translate()
})
})

Context("Health check config", func() {

It("will error if required field is nil", func() {
Expand Down

0 comments on commit ef59051

Please sign in to comment.