Skip to content

Commit

Permalink
fixup: should not increment twice on the index of http route match wh…
Browse files Browse the repository at this point in the history
…en building the wasm action set name

Signed-off-by: Guilherme Cassolato <[email protected]>
  • Loading branch information
guicassolato committed Oct 17, 2024
1 parent 4f30986 commit 3040027
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pkg/wasm/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func BuildActionSetsForPath(pathID string, path []machinery.Targetable, policyRu
return lo.FlatMap(kuadrantgatewayapi.HostnamesFromListenerAndHTTPRoute(listener.Listener, httpRoute.HTTPRoute), func(hostname gatewayapiv1.Hostname, _ int) []kuadrantgatewayapi.HTTPRouteMatchConfig {
return lo.Map(httpRouteRule.Matches, func(httpRouteMatch gatewayapiv1.HTTPRouteMatch, j int) kuadrantgatewayapi.HTTPRouteMatchConfig {
actionSet := ActionSet{
Name: ActionSetNameForPath(pathID, j+1, string(hostname)),
Name: ActionSetNameForPath(pathID, j, string(hostname)),
Actions: actions,

Check warning on line 66 in pkg/wasm/utils.go

View check run for this annotation

Codecov / codecov/patch

pkg/wasm/utils.go#L62-L66

Added lines #L62 - L66 were not covered by tests
}
routeRuleConditions := RouteRuleConditions{
Expand Down
4 changes: 2 additions & 2 deletions tests/envoygateway/extension_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var _ = Describe("wasm controller", func() {
mHTTPRoute,
&machinery.HTTPRouteRule{HTTPRoute: mHTTPRoute, HTTPRouteRule: &gwRoute.Spec.Rules[0], Name: "rule-1"},
})
actionSetName = wasm.ActionSetNameForPath(pathID, 1, string(gwRoute.Spec.Hostnames[0]))
actionSetName = wasm.ActionSetNameForPath(pathID, 0, string(gwRoute.Spec.Hostnames[0]))

gwPolicy = policyFactory(func(policy *kuadrantv1beta3.RateLimitPolicy) {
policy.Name = "gw"
Expand Down Expand Up @@ -272,7 +272,7 @@ var _ = Describe("wasm controller", func() {
mHTTPRoute,
&machinery.HTTPRouteRule{HTTPRoute: mHTTPRoute, HTTPRouteRule: &gwRoute.Spec.Rules[0], Name: "rule-1"},
})
actionSetName = wasm.ActionSetNameForPath(pathID, 1, string(gwRoute.Spec.Hostnames[0]))
actionSetName = wasm.ActionSetNameForPath(pathID, 0, string(gwRoute.Spec.Hostnames[0]))

routePolicy = policyFactory(func(policy *kuadrantv1beta3.RateLimitPolicy) {
policy.Name = "route"
Expand Down
38 changes: 19 additions & 19 deletions tests/istio/extension_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// api.toystore.io/assets*
actionSet := existingWASMConfig.ActionSets[0]
pathID := kuadrantv1.PathID(append(basePath, httpRouteRuleAssets))
Expect(actionSet.Name).To(Equal(wasm.ActionSetNameForPath(pathID, 3, "api.toystore.io")))
Expect(actionSet.Name).To(Equal(wasm.ActionSetNameForPath(pathID, 0, "api.toystore.io")))
Expect(actionSet.RouteRuleConditions.Hostnames).To(Equal([]string{"api.toystore.io"}))
Expect(actionSet.RouteRuleConditions.Matches).To(ContainElements(
wasm.Predicate{
Expand Down Expand Up @@ -367,7 +367,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// GET api.toystore.io/toys*
actionSet = existingWASMConfig.ActionSets[1]
pathID = kuadrantv1.PathID(append(basePath, httpRouteRuleToys))
Expect(actionSet.Name).To(Equal(wasm.ActionSetNameForPath(pathID, 1, "api.toystore.io")))
Expect(actionSet.Name).To(Equal(wasm.ActionSetNameForPath(pathID, 0, "api.toystore.io")))
Expect(actionSet.RouteRuleConditions.Hostnames).To(Equal([]string{"api.toystore.io"}))
Expect(actionSet.RouteRuleConditions.Matches).To(ContainElements(
wasm.Predicate{
Expand Down Expand Up @@ -430,7 +430,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// POST api.toystore.io/toys*
actionSet = existingWASMConfig.ActionSets[2]
pathID = kuadrantv1.PathID(append(basePath, httpRouteRuleToys))
Expect(actionSet.Name).To(Equal(wasm.ActionSetNameForPath(pathID, 2, "api.toystore.io")))
Expect(actionSet.Name).To(Equal(wasm.ActionSetNameForPath(pathID, 1, "api.toystore.io")))
Expect(actionSet.RouteRuleConditions.Hostnames).To(Equal([]string{"api.toystore.io"}))
Expect(actionSet.RouteRuleConditions.Matches).To(ContainElements(
wasm.Predicate{
Expand Down Expand Up @@ -493,7 +493,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// *.toystore.acme.com/assets*
actionSet = existingWASMConfig.ActionSets[3]
pathID = kuadrantv1.PathID(append(basePath, httpRouteRuleAssets))
Expect(actionSet.Name).To(Equal(wasm.ActionSetNameForPath(pathID, 3, "*.toystore.acme.com")))
Expect(actionSet.Name).To(Equal(wasm.ActionSetNameForPath(pathID, 0, "*.toystore.acme.com")))
Expect(actionSet.RouteRuleConditions.Hostnames).To(Equal([]string{"*.toystore.acme.com"}))
Expect(actionSet.RouteRuleConditions.Matches).To(ContainElements(
wasm.Predicate{
Expand Down Expand Up @@ -551,7 +551,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// GET *.toystore.acme.com/toys*
actionSet = existingWASMConfig.ActionSets[4]
pathID = kuadrantv1.PathID(append(basePath, httpRouteRuleToys))
Expect(actionSet.Name).To(Equal(wasm.ActionSetNameForPath(pathID, 1, "*.toystore.acme.com")))
Expect(actionSet.Name).To(Equal(wasm.ActionSetNameForPath(pathID, 0, "*.toystore.acme.com")))
Expect(actionSet.RouteRuleConditions.Hostnames).To(Equal([]string{"*.toystore.acme.com"}))
Expect(actionSet.RouteRuleConditions.Matches).To(ContainElements(
wasm.Predicate{
Expand Down Expand Up @@ -614,7 +614,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
// POST *.toystore.acme.com/toys*
actionSet = existingWASMConfig.ActionSets[5]
pathID = kuadrantv1.PathID(append(basePath, httpRouteRuleToys))
Expect(actionSet.Name).To(Equal(wasm.ActionSetNameForPath(pathID, 2, "*.toystore.acme.com")))
Expect(actionSet.Name).To(Equal(wasm.ActionSetNameForPath(pathID, 1, "*.toystore.acme.com")))
Expect(actionSet.RouteRuleConditions.Hostnames).To(Equal([]string{"*.toystore.acme.com"}))
Expect(actionSet.RouteRuleConditions.Matches).To(ContainElements(
wasm.Predicate{
Expand Down Expand Up @@ -745,7 +745,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
},
ActionSets: []wasm.ActionSet{
{
Name: wasm.ActionSetNameForPath(pathID, 1, "*.example.com"),
Name: wasm.ActionSetNameForPath(pathID, 0, "*.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.example.com"},
Matches: []wasm.Predicate{
Expand Down Expand Up @@ -969,7 +969,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
},
ActionSets: []wasm.ActionSet{
{
Name: wasm.ActionSetNameForPath(pathID, 1, "*.example.com"),
Name: wasm.ActionSetNameForPath(pathID, 0, "*.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.example.com"},
Matches: []wasm.Predicate{
Expand Down Expand Up @@ -1182,7 +1182,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
},
ActionSets: []wasm.ActionSet{
{
Name: wasm.ActionSetNameForPath(pathID, 1, "*.example.com"),
Name: wasm.ActionSetNameForPath(pathID, 0, "*.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.example.com"},
Matches: []wasm.Predicate{
Expand Down Expand Up @@ -1313,7 +1313,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
},
ActionSets: []wasm.ActionSet{
{
Name: wasm.ActionSetNameForPath(pathID, 1, "*.example.com"),
Name: wasm.ActionSetNameForPath(pathID, 0, "*.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.example.com"},
Matches: []wasm.Predicate{
Expand Down Expand Up @@ -1516,7 +1516,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
},
ActionSets: []wasm.ActionSet{
{
Name: wasm.ActionSetNameForPath(pathID, 1, "*.a.example.com"),
Name: wasm.ActionSetNameForPath(pathID, 0, "*.a.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.a.example.com"},
Matches: []wasm.Predicate{
Expand Down Expand Up @@ -1610,7 +1610,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
},
ActionSets: []wasm.ActionSet{
{
Name: wasm.ActionSetNameForPath(pathID, 1, "*.b.example.com"),
Name: wasm.ActionSetNameForPath(pathID, 0, "*.b.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.b.example.com"},
Matches: []wasm.Predicate{
Expand Down Expand Up @@ -1788,7 +1788,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
},
ActionSets: []wasm.ActionSet{
{
Name: wasm.ActionSetNameForPath(pathID, 1, "*.a.example.com"),
Name: wasm.ActionSetNameForPath(pathID, 0, "*.a.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.a.example.com"},
Matches: []wasm.Predicate{
Expand Down Expand Up @@ -1900,7 +1900,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
},
ActionSets: []wasm.ActionSet{
{
Name: wasm.ActionSetNameForPath(pathID, 1, "*.a.example.com"),
Name: wasm.ActionSetNameForPath(pathID, 0, "*.a.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.a.example.com"},
Matches: []wasm.Predicate{
Expand Down Expand Up @@ -2114,7 +2114,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
},
ActionSets: []wasm.ActionSet{
{
Name: wasm.ActionSetNameForPath(pathID, 1, "*.a.example.com"),
Name: wasm.ActionSetNameForPath(pathID, 0, "*.a.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.a.example.com"},
Matches: []wasm.Predicate{
Expand Down Expand Up @@ -2223,7 +2223,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
},
ActionSets: []wasm.ActionSet{
{
Name: wasm.ActionSetNameForPath(pathID, 1, "*.a.example.com"),
Name: wasm.ActionSetNameForPath(pathID, 0, "*.a.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.a.example.com"},
Matches: []wasm.Predicate{
Expand Down Expand Up @@ -2257,7 +2257,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
},
},
{
Name: wasm.ActionSetNameForPath(pathID_B, 1, "*.b.example.com"),
Name: wasm.ActionSetNameForPath(pathID_B, 0, "*.b.example.com"),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{"*.b.example.com"},
Matches: []wasm.Predicate{
Expand Down Expand Up @@ -2399,7 +2399,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
},
ActionSets: []wasm.ActionSet{
{
Name: wasm.ActionSetNameForPath(pathID, 1, gwHostname),
Name: wasm.ActionSetNameForPath(pathID, 0, gwHostname),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{gwHostname},
Matches: []wasm.Predicate{
Expand Down Expand Up @@ -2478,7 +2478,7 @@ var _ = Describe("Rate Limiting WasmPlugin controller", func() {
},
ActionSets: []wasm.ActionSet{
{
Name: wasm.ActionSetNameForPath(pathID, 1, hostname),
Name: wasm.ActionSetNameForPath(pathID, 0, hostname),
RouteRuleConditions: wasm.RouteRuleConditions{
Hostnames: []string{hostname},
Matches: []wasm.Predicate{
Expand Down

0 comments on commit 3040027

Please sign in to comment.