diff --git a/api/v1beta2/ratelimitpolicy_types.go b/api/v1beta2/ratelimitpolicy_types.go index 17676598b..28f93f30f 100644 --- a/api/v1beta2/ratelimitpolicy_types.go +++ b/api/v1beta2/ratelimitpolicy_types.go @@ -34,6 +34,8 @@ import ( // ContextSelector defines one item from the well known attributes // Attributes: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes // Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors +// They are named by a dot-separated path (e.g. request.path) +// Example: "request.path" -> The path portion of the URL // +kubebuilder:validation:MinLength=1 // +kubebuilder:validation:MaxLength=253 type ContextSelector string diff --git a/bundle/manifests/kuadrant.io_ratelimitpolicies.yaml b/bundle/manifests/kuadrant.io_ratelimitpolicies.yaml index 2d52f40d1..2eeebd93a 100644 --- a/bundle/manifests/kuadrant.io_ratelimitpolicies.yaml +++ b/bundle/manifests/kuadrant.io_ratelimitpolicies.yaml @@ -47,7 +47,9 @@ spec: items: description: 'ContextSelector defines one item from the well known attributes Attributes: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes - Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors' + Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors + They are named by a dot-separated path (e.g. request.path) + Example: "request.path" -> The path portion of the URL' maxLength: 253 minLength: 1 type: string diff --git a/config/crd/bases/kuadrant.io_ratelimitpolicies.yaml b/config/crd/bases/kuadrant.io_ratelimitpolicies.yaml index 000ff75fc..be4b708de 100644 --- a/config/crd/bases/kuadrant.io_ratelimitpolicies.yaml +++ b/config/crd/bases/kuadrant.io_ratelimitpolicies.yaml @@ -46,7 +46,9 @@ spec: items: description: 'ContextSelector defines one item from the well known attributes Attributes: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes - Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors' + Well-known selectors: https://github.com/Kuadrant/architecture/blob/main/rfcs/0001-rlp-v2.md#well-known-selectors + They are named by a dot-separated path (e.g. request.path) + Example: "request.path" -> The path portion of the URL' maxLength: 253 minLength: 1 type: string diff --git a/controllers/ratelimitpolicy_controller_test.go b/controllers/ratelimitpolicy_controller_test.go index 3028aae08..3933e154d 100644 --- a/controllers/ratelimitpolicy_controller_test.go +++ b/controllers/ratelimitpolicy_controller_test.go @@ -117,7 +117,7 @@ func testBuildBasicRoutePolicy(policyName, ns, routeName string) *kuadrantv1beta Name: gatewayapiv1beta1.ObjectName(routeName), }, Limits: map[string]kuadrantv1beta2.Limit{ - "l1": kuadrantv1beta2.Limit{ + "l1": { Rates: []kuadrantv1beta2.Rate{ { Limit: 1, Duration: 3, Unit: kuadrantv1beta2.TimeUnit("minute"), @@ -146,7 +146,7 @@ func testBuildGatewayPolicy(policyName, ns, gwName string) *kuadrantv1beta2.Rate Name: gatewayapiv1beta1.ObjectName(gwName), }, Limits: map[string]kuadrantv1beta2.Limit{ - "l1": kuadrantv1beta2.Limit{ + "l1": { Rates: []kuadrantv1beta2.Rate{ { Limit: 1, Duration: 3, Unit: kuadrantv1beta2.TimeUnit("minute"), diff --git a/pkg/rlptools/wasm/types.go b/pkg/rlptools/wasm/types.go index d971bba57..9355734e2 100644 --- a/pkg/rlptools/wasm/types.go +++ b/pkg/rlptools/wasm/types.go @@ -18,13 +18,9 @@ var ( ) type SelectorSpec struct { - // Selector of an attribute from the contextual properties provided by Envoy + // Selector of an attribute from the contextual properties provided by kuadrant // during request and connection processing - // https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes - // They are named by a dot-separated path (e.g. request.path) - // Examples: - // "request.path" -> The path portion of the URL - Selector string `json:"selector"` + Selector kuadrantv1beta2.ContextSelector `json:"selector"` // If not set it defaults to `selector` field value as the descriptor key. // +optional @@ -54,13 +50,9 @@ type DataItem struct { type PatternOperator kuadrantv1beta2.WhenConditionOperator type PatternExpression struct { - // Selector of an attribute from the contextual properties provided by Envoy + // Selector of an attribute from the contextual properties provided by kuadrant // during request and connection processing - // https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/advanced/attributes - // They are named by a dot-separated path (e.g. request.path) - // Examples: - // "request.path" -> The path portion of the URL - Selector string `json:"selector"` + Selector kuadrantv1beta2.ContextSelector `json:"selector"` // The binary operator to be applied to the content fetched from context, for comparison with "value". // Possible values are: "eq" (equal to), "neq" (not equal to), "incl" (includes; for arrays), "excl" (excludes; for arrays), "matches" (regex) diff --git a/pkg/rlptools/wasm_utils.go b/pkg/rlptools/wasm_utils.go index c4756ecb0..8f66100b9 100644 --- a/pkg/rlptools/wasm_utils.go +++ b/pkg/rlptools/wasm_utils.go @@ -164,7 +164,7 @@ func patternExpresionFromMethod(method gatewayapiv1beta1.HTTPMethod) wasm.Patter func patternExpresionFromWhen(when kuadrantv1beta2.WhenCondition) wasm.PatternExpression { return wasm.PatternExpression{ - Selector: string(when.Selector), + Selector: when.Selector, Operator: wasm.PatternOperator(when.Operator), Value: when.Value, } @@ -189,7 +189,7 @@ func dataFromLimt(limitFullName string, limit *kuadrantv1beta2.Limit) []wasm.Dat data = append(data, wasm.DataItem{Static: &wasm.StaticSpec{Key: limitFullName, Value: "1"}}) for _, counter := range limit.Counters { - data = append(data, wasm.DataItem{Selector: &wasm.SelectorSpec{Selector: string(counter)}}) + data = append(data, wasm.DataItem{Selector: &wasm.SelectorSpec{Selector: counter}}) } return data