Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/controller/state/dataplane/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,10 @@ func (hpr *hostPathRules) upsertRoute(
if !exist {
hostRule.Path = path
hostRule.PathType = convertPathType(*m.Path.Type)
hostRule.Policies = append(hostRule.Policies, pols...)
}

hostRule.GRPC = GRPC
hostRule.Policies = append(hostRule.Policies, pols...)

hostRule.MatchRules = append(hostRule.MatchRules, MatchRule{
Source: objectSrc,
Expand Down
102 changes: 102 additions & 0 deletions internal/controller/state/dataplane/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,28 @@
},
)

hrAdvancedRouteWithPolicyAndHeaderMatch, groupsHRAdvancedWithHeaderMatch, routeHRAdvancedWithHeaderMatch := createTestResources(

Check failure on line 683 in internal/controller/state/dataplane/configuration_test.go

View workflow job for this annotation

GitHub Actions / Go Lint (.)

The line is 129 characters long, which exceeds the maximum of 120 characters. (lll)
"hr-advanced-route-with-policy-header-match",
"policy.com",
"listener-80-1",
pathAndType{path: "/rest", pathType: prefix},
)

routeHRAdvancedWithHeaderMatch.Spec.Rules[0].Matches[0].Headers = []v1.HTTPHeaderMatch{
{
Name: "Referrer",
Type: helpers.GetPointer(v1.HeaderMatchRegularExpression),
Value: "(?i)(mydomain|myotherdomain).+\\.example\\.(cloud|com)",
},
}

hrAdvancedRouteWithPolicyNoHeaderMatch, groupsHRAdvancedNoHeaderMatch, routeHRAdvancedNoHeaderMatch := createTestResources(

Check failure on line 698 in internal/controller/state/dataplane/configuration_test.go

View workflow job for this annotation

GitHub Actions / Go Lint (.)

The line is 124 characters long, which exceeds the maximum of 120 characters. (lll)
"hr-advanced-route-with-policy-no-header-match",
"policy.com",
"listener-80-1",
pathAndType{path: "/rest", pathType: prefix},
)

l7RouteWithPolicy.Policies = []*graph.Policy{hrPolicy1, invalidPolicy}

httpsHRWithPolicy, expHTTPSHRWithPolicyGroups, l7HTTPSRouteWithPolicy := createTestResources(
Expand Down Expand Up @@ -2346,6 +2368,80 @@
}),
msg: "Simple Gateway and HTTPRoute with policies attached",
},
{
graph: getModifiedGraph(func(g *graph.Graph) *graph.Graph {
gw := g.Gateways[gatewayNsName]
gw.Listeners = append(gw.Listeners, []*graph.Listener{
{
Name: "listener-80-1",
GatewayName: gatewayNsName,
Source: listener80,
Valid: true,
Routes: map[graph.RouteKey]*graph.L7Route{
graph.CreateRouteKey(hrAdvancedRouteWithPolicyAndHeaderMatch): routeHRAdvancedWithHeaderMatch,
graph.CreateRouteKey(hrAdvancedRouteWithPolicyNoHeaderMatch): routeHRAdvancedNoHeaderMatch,
},
},
}...)
gw.Policies = []*graph.Policy{gwPolicy1, gwPolicy2}
g.Routes = map[graph.RouteKey]*graph.L7Route{
graph.CreateRouteKey(hrAdvancedRouteWithPolicyAndHeaderMatch): routeHRAdvancedWithHeaderMatch,
graph.CreateRouteKey(hrAdvancedRouteWithPolicyNoHeaderMatch): routeHRAdvancedNoHeaderMatch,
}
return g
}),
expConf: getModifiedExpectedConfiguration(func(conf Configuration) Configuration {
conf.HTTPServers = []VirtualServer{
{
IsDefault: true,
Port: 80,
Policies: []policies.Policy{gwPolicy1.Source, gwPolicy2.Source},
},
{
Hostname: "policy.com",
PathRules: []PathRule{
{
Path: "/rest",
PathType: PathTypePrefix,
MatchRules: []MatchRule{
{
BackendGroup: groupsHRAdvancedWithHeaderMatch[0],
Source: &hrAdvancedRouteWithPolicyAndHeaderMatch.ObjectMeta,
Match: Match{
Headers: []HTTPHeaderMatch{
{
Name: "Referrer",
Value: "(?i)(mydomain|myotherdomain).+\\.example\\.(cloud|com)",
Type: "RegularExpression",
},
},
},
},
},
Policies: []policies.Policy{hrPolicy2.Source},
},
{
Path: "/rest",
PathType: PathTypePrefix,
MatchRules: []MatchRule{
{
BackendGroup: groupsHRAdvancedNoHeaderMatch[0],
Source: &hrAdvancedRouteWithPolicyNoHeaderMatch.ObjectMeta,
},
},
Policies: []policies.Policy{hrPolicy2.Source},
},
},
Port: 80,
Policies: []policies.Policy{gwPolicy1.Source, gwPolicy2.Source},
},
}
conf.Upstreams = []Upstream{fooUpstream}
conf.BackendGroups = []BackendGroup{groupsHRAdvancedWithHeaderMatch[0], groupsHRAdvancedNoHeaderMatch[0]}
return conf
}),
msg: "Simple Gateway and HTTPRoute with advanced routing and policies attached",
},
{
graph: getModifiedGraph(func(g *graph.Graph) *graph.Graph {
gw := g.Gateways[gatewayNsName]
Expand Down Expand Up @@ -2547,6 +2643,12 @@
false,
)

if test.msg == "Simple Gateway and HTTPRoute with advanced routing and policies attached" {
fmt.Printf("Results for %s: %+v\n", test.msg, result.HTTPServers)
fmt.Println("-----")
fmt.Printf("Expected for %s: %+v\n", test.msg, test.expConf.HTTPServers)
}

g.Expect(result.BackendGroups).To(ConsistOf(test.expConf.BackendGroups))
g.Expect(result.Upstreams).To(ConsistOf(test.expConf.Upstreams))
g.Expect(result.HTTPServers).To(ConsistOf(test.expConf.HTTPServers))
Expand Down
Loading