Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7607c01

Browse files
Prevent policy includes duplication in advanced routing configuration (#3799) (#3819)
1 parent 0925904 commit 7607c01

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

‎internal/controller/state/dataplane/configuration.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,10 @@ func (hpr *hostPathRules) upsertRoute(
581581
if !exist {
582582
hostRule.Path = path
583583
hostRule.PathType = convertPathType(*m.Path.Type)
584+
hostRule.Policies = append(hostRule.Policies, pols...)
584585
}
585586

586587
hostRule.GRPC = GRPC
587-
hostRule.Policies = append(hostRule.Policies, pols...)
588588

589589
hostRule.MatchRules = append(hostRule.MatchRules, MatchRule{
590590
Source: objectSrc,

‎internal/controller/state/dataplane/configuration_test.go‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,37 @@ func TestBuildConfiguration(t *testing.T) {
678678
},
679679
)
680680

681+
hrAdvancedRouteWithPolicyAndHeaderMatch,
682+
groupsHRAdvancedWithHeaderMatch,
683+
routeHRAdvancedWithHeaderMatch := createTestResources(
684+
"hr-advanced-route-with-policy-header-match",
685+
"policy.com",
686+
"listener-80-1",
687+
pathAndType{path: "/rest", pathType: prefix},
688+
)
689+
690+
pathMatch := helpers.GetPointer(v1.HTTPPathMatch{
691+
Value: helpers.GetPointer("/rest"),
692+
Type: helpers.GetPointer(v1.PathMatchPathPrefix),
693+
})
694+
695+
routeHRAdvancedWithHeaderMatch.Spec.Rules[0].Matches = []v1.HTTPRouteMatch{
696+
{
697+
Path: pathMatch,
698+
Headers: []v1.HTTPHeaderMatch{
699+
{
700+
Name: "Referrer",
701+
Type: helpers.GetPointer(v1.HeaderMatchRegularExpression),
702+
Value: "(?i)(mydomain|myotherdomain).+\\.example\\.(cloud|com)",
703+
},
704+
},
705+
},
706+
{
707+
Path: pathMatch,
708+
},
709+
}
710+
routeHRAdvancedWithHeaderMatch.Spec.Hostnames = []v1.Hostname{"policy.com"}
711+
681712
l7RouteWithPolicy.Policies = []*graph.Policy{hrPolicy1, invalidPolicy}
682713

683714
httpsHRWithPolicy, expHTTPSHRWithPolicyGroups, l7HTTPSRouteWithPolicy := createTestResources(
@@ -2344,6 +2375,74 @@ func TestBuildConfiguration(t *testing.T) {
23442375
}),
23452376
msg: "Simple Gateway and HTTPRoute with policies attached",
23462377
},
2378+
{
2379+
graph: getModifiedGraph(func(g *graph.Graph) *graph.Graph {
2380+
gw := g.Gateways[gatewayNsName]
2381+
gw.Listeners = append(gw.Listeners, []*graph.Listener{
2382+
{
2383+
Name: "listener-80-1",
2384+
GatewayName: gatewayNsName,
2385+
Source: listener80,
2386+
Valid: true,
2387+
Routes: map[graph.RouteKey]*graph.L7Route{
2388+
graph.CreateRouteKey(hrAdvancedRouteWithPolicyAndHeaderMatch): routeHRAdvancedWithHeaderMatch,
2389+
},
2390+
},
2391+
}...)
2392+
gw.Policies = []*graph.Policy{gwPolicy1, gwPolicy2}
2393+
routeHRAdvancedWithHeaderMatch.Policies = []*graph.Policy{hrPolicy1}
2394+
g.Routes = map[graph.RouteKey]*graph.L7Route{
2395+
graph.CreateRouteKey(hrAdvancedRouteWithPolicyAndHeaderMatch): routeHRAdvancedWithHeaderMatch,
2396+
}
2397+
return g
2398+
}),
2399+
expConf: getModifiedExpectedConfiguration(func(conf Configuration) Configuration {
2400+
conf.SSLServers = []VirtualServer{}
2401+
conf.SSLKeyPairs = map[SSLKeyPairID]SSLKeyPair{}
2402+
conf.HTTPServers = []VirtualServer{
2403+
{
2404+
IsDefault: true,
2405+
Port: 80,
2406+
Policies: []policies.Policy{gwPolicy1.Source, gwPolicy2.Source},
2407+
},
2408+
{
2409+
Hostname: "policy.com",
2410+
PathRules: []PathRule{
2411+
{
2412+
Path: "/rest",
2413+
PathType: PathTypePrefix,
2414+
MatchRules: []MatchRule{
2415+
{
2416+
BackendGroup: groupsHRAdvancedWithHeaderMatch[0],
2417+
Source: &hrAdvancedRouteWithPolicyAndHeaderMatch.ObjectMeta,
2418+
Match: Match{
2419+
Headers: []HTTPHeaderMatch{
2420+
{
2421+
Name: "Referrer",
2422+
Value: "(?i)(mydomain|myotherdomain).+\\.example\\.(cloud|com)",
2423+
Type: "RegularExpression",
2424+
},
2425+
},
2426+
},
2427+
},
2428+
{
2429+
BackendGroup: groupsHRAdvancedWithHeaderMatch[0],
2430+
Source: &hrAdvancedRouteWithPolicyAndHeaderMatch.ObjectMeta,
2431+
},
2432+
},
2433+
Policies: []policies.Policy{hrPolicy1.Source},
2434+
},
2435+
},
2436+
Port: 80,
2437+
Policies: []policies.Policy{gwPolicy1.Source, gwPolicy2.Source},
2438+
},
2439+
}
2440+
conf.Upstreams = []Upstream{fooUpstream}
2441+
conf.BackendGroups = []BackendGroup{groupsHRAdvancedWithHeaderMatch[0]}
2442+
return conf
2443+
}),
2444+
msg: "Gateway and HTTPRoute with policies attached with advanced routing",
2445+
},
23472446
{
23482447
graph: getModifiedGraph(func(g *graph.Graph) *graph.Graph {
23492448
gw := g.Gateways[gatewayNsName]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /