Skip to content

Commit 2464ad5

Browse files
authored
ratelimitpolicy virtualhosts ratelimits (Kuadrant#85)
* ratelimitpolicy virtualhosts ratelimits * apim/ratelimitpolicy_controller: remove unnecessary route match for virtualhost * fix lint issue
1 parent c67bcd5 commit 2464ad5

File tree

8 files changed

+351
-155
lines changed

8 files changed

+351
-155
lines changed

apis/apim/v1alpha1/ratelimitpolicy_types.go

+21-9
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ type RLGenericKey struct {
2929
DescriptorValue string `json:"descriptor_value"`
3030
}
3131

32+
//TODO(eguzki): oneOf each kind
33+
//
34+
// https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/route/v3/route_components.proto#envoy-v3-api-msg-config-route-v3-ratelimit-action
35+
36+
// Action_Specifier defines the envoy rate limit actions
3237
type ActionSpecifier struct {
33-
GenericKey RLGenericKey `json:"generic_key"`
38+
// +optional
39+
GenericKey *RLGenericKey `json:"generic_key,omitempty"`
3440
}
3541

3642
// +kubebuilder:validation:Enum=PREAUTH;POSTAUTH;BOTH
@@ -57,19 +63,23 @@ var RateLimitStageName = map[int32]string{
5763
var RateLimitStageValue = map[RateLimitStage]int32{
5864
"PREAUTH": 0,
5965
"POSTAUTH": 1,
60-
"BOTH": 2,
6166
}
6267

63-
type Route struct {
64-
// name of the route present in the virutalservice
65-
Name string `json:"name"`
68+
type RateLimit struct {
6669
// Definfing phase at which rate limits will be applied.
6770
// Valid values are: PREAUTH, POSTAUTH, BOTH
6871
Stage RateLimitStage `json:"stage"`
69-
// rule specific actions
72+
// +optional
7073
Actions []*ActionSpecifier `json:"actions,omitempty"`
7174
}
7275

76+
type Route struct {
77+
// name of the route present in the virutalservice
78+
Name string `json:"name"`
79+
// +optional
80+
RateLimits []*RateLimit `json:"rateLimits,omitempty"`
81+
}
82+
7383
type NetworkingRef struct {
7484
Type NetworkingRefType `json:"type"`
7585
Name string `json:"name"`
@@ -85,9 +95,11 @@ type RateLimitPolicySpec struct {
8595
//+listType=map
8696
//+listMapKey=name
8797
Routes []Route `json:"routes,omitempty"`
88-
// these actions are used for all of the matching rules
89-
Actions []*ActionSpecifier `json:"actions,omitempty"`
90-
Limits []limitadorv1alpha1.RateLimitSpec `json:"limits,omitempty"`
98+
99+
// RateLimits are used for all of the matching rules
100+
// +optional
101+
RateLimits []*RateLimit `json:"rateLimits,omitempty"`
102+
Limits []limitadorv1alpha1.RateLimitSpec `json:"limits,omitempty"`
91103
}
92104

93105
//+kubebuilder:object:root=true

apis/apim/v1alpha1/zz_generated.deepcopy.go

+41-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/apim.kuadrant.io_ratelimitpolicies.yaml

+47-27
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,6 @@ spec:
3636
spec:
3737
description: RateLimitPolicySpec defines the desired state of RateLimitPolicy
3838
properties:
39-
actions:
40-
description: these actions are used for all of the matching rules
41-
items:
42-
properties:
43-
generic_key:
44-
properties:
45-
descriptor_key:
46-
type: string
47-
descriptor_value:
48-
type: string
49-
required:
50-
- descriptor_key
51-
- descriptor_value
52-
type: object
53-
required:
54-
- generic_key
55-
type: object
56-
type: array
5739
limits:
5840
items:
5941
description: RateLimitSpec defines the desired state of RateLimit
@@ -99,13 +81,14 @@ spec:
9981
- type
10082
- name
10183
x-kubernetes-list-type: map
102-
routes:
103-
description: route specific staging and actions
84+
rateLimits:
85+
description: RateLimits are used for all of the matching rules
10486
items:
10587
properties:
10688
actions:
107-
description: rule specific actions
10889
items:
90+
description: Action_Specifier defines the envoy rate limit
91+
actions
10992
properties:
11093
generic_key:
11194
properties:
@@ -117,13 +100,8 @@ spec:
117100
- descriptor_key
118101
- descriptor_value
119102
type: object
120-
required:
121-
- generic_key
122103
type: object
123104
type: array
124-
name:
125-
description: name of the route present in the virutalservice
126-
type: string
127105
stage:
128106
description: 'Definfing phase at which rate limits will be applied.
129107
Valid values are: PREAUTH, POSTAUTH, BOTH'
@@ -133,10 +111,52 @@ spec:
133111
- BOTH
134112
type: string
135113
required:
136-
- name
137114
- stage
138115
type: object
139116
type: array
117+
routes:
118+
description: route specific staging and actions
119+
items:
120+
properties:
121+
name:
122+
description: name of the route present in the virutalservice
123+
type: string
124+
rateLimits:
125+
items:
126+
properties:
127+
actions:
128+
items:
129+
description: Action_Specifier defines the envoy rate
130+
limit actions
131+
properties:
132+
generic_key:
133+
properties:
134+
descriptor_key:
135+
type: string
136+
descriptor_value:
137+
type: string
138+
required:
139+
- descriptor_key
140+
- descriptor_value
141+
type: object
142+
type: object
143+
type: array
144+
stage:
145+
description: 'Definfing phase at which rate limits will
146+
be applied. Valid values are: PREAUTH, POSTAUTH, BOTH'
147+
enum:
148+
- PREAUTH
149+
- POSTAUTH
150+
- BOTH
151+
type: string
152+
required:
153+
- stage
154+
type: object
155+
type: array
156+
required:
157+
- name
158+
type: object
159+
type: array
140160
x-kubernetes-list-map-keys:
141161
- name
142162
x-kubernetes-list-type: map

config/deploy/manifests.yaml

+44-27
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,6 @@ spec:
112112
spec:
113113
description: RateLimitPolicySpec defines the desired state of RateLimitPolicy
114114
properties:
115-
actions:
116-
description: these actions are used for all of the matching rules
117-
items:
118-
properties:
119-
generic_key:
120-
properties:
121-
descriptor_key:
122-
type: string
123-
descriptor_value:
124-
type: string
125-
required:
126-
- descriptor_key
127-
- descriptor_value
128-
type: object
129-
required:
130-
- generic_key
131-
type: object
132-
type: array
133115
limits:
134116
items:
135117
description: RateLimitSpec defines the desired state of RateLimit
@@ -175,13 +157,13 @@ spec:
175157
- type
176158
- name
177159
x-kubernetes-list-type: map
178-
routes:
179-
description: route specific staging and actions
160+
rateLimits:
161+
description: RateLimits are used for all of the matching rules
180162
items:
181163
properties:
182164
actions:
183-
description: rule specific actions
184165
items:
166+
description: Action_Specifier defines the envoy rate limit actions
185167
properties:
186168
generic_key:
187169
properties:
@@ -193,13 +175,8 @@ spec:
193175
- descriptor_key
194176
- descriptor_value
195177
type: object
196-
required:
197-
- generic_key
198178
type: object
199179
type: array
200-
name:
201-
description: name of the route present in the virutalservice
202-
type: string
203180
stage:
204181
description: 'Definfing phase at which rate limits will be applied. Valid values are: PREAUTH, POSTAUTH, BOTH'
205182
enum:
@@ -208,10 +185,50 @@ spec:
208185
- BOTH
209186
type: string
210187
required:
211-
- name
212188
- stage
213189
type: object
214190
type: array
191+
routes:
192+
description: route specific staging and actions
193+
items:
194+
properties:
195+
name:
196+
description: name of the route present in the virutalservice
197+
type: string
198+
rateLimits:
199+
items:
200+
properties:
201+
actions:
202+
items:
203+
description: Action_Specifier defines the envoy rate limit actions
204+
properties:
205+
generic_key:
206+
properties:
207+
descriptor_key:
208+
type: string
209+
descriptor_value:
210+
type: string
211+
required:
212+
- descriptor_key
213+
- descriptor_value
214+
type: object
215+
type: object
216+
type: array
217+
stage:
218+
description: 'Definfing phase at which rate limits will be applied. Valid values are: PREAUTH, POSTAUTH, BOTH'
219+
enum:
220+
- PREAUTH
221+
- POSTAUTH
222+
- BOTH
223+
type: string
224+
required:
225+
- stage
226+
type: object
227+
type: array
228+
required:
229+
- name
230+
type: object
231+
type: array
215232
x-kubernetes-list-map-keys:
216233
- name
217234
x-kubernetes-list-type: map

0 commit comments

Comments
 (0)