Skip to content

Commit a2cafb6

Browse files
committed
enable rate limit for month and year
Signed-off-by: Rico Pahlisch <[email protected]> Signed-off-by: Rico Pahlisch <[email protected]>
1 parent 544bd9c commit a2cafb6

File tree

6 files changed

+196
-175
lines changed

6 files changed

+196
-175
lines changed

api/v1alpha1/ratelimit_types.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ type RateLimitValue struct {
198198
}
199199

200200
// RateLimitUnit specifies the intervals for setting rate limits.
201-
// Valid RateLimitUnit values are "Second", "Minute", "Hour", and "Day".
201+
// Valid RateLimitUnit values are "Second", "Minute", "Hour", "Day", "Month" and "Year".
202202
//
203-
// +kubebuilder:validation:Enum=Second;Minute;Hour;Day
203+
// +kubebuilder:validation:Enum=Second;Minute;Hour;Day;Month;Year
204204
type RateLimitUnit string
205205

206206
// RateLimitUnit constants.
@@ -216,4 +216,10 @@ const (
216216

217217
// RateLimitUnitDay specifies the rate limit interval to be 1 day.
218218
RateLimitUnitDay RateLimitUnit = "Day"
219+
220+
// RateLimitUnitMonth specifies the rate limit interval to be 1 month.
221+
RateLimitUnitMonth RateLimitUnit = "Month"
222+
223+
// RateLimitUnitYear specifies the rate limit interval to be 1 year.
224+
RateLimitUnitYear RateLimitUnit = "Year"
219225
)

charts/gateway-helm/crds/generated/gateway.envoyproxy.io_backendtrafficpolicies.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,12 +766,14 @@ spec:
766766
unit:
767767
description: |-
768768
RateLimitUnit specifies the intervals for setting rate limits.
769-
Valid RateLimitUnit values are "Second", "Minute", "Hour", and "Day".
769+
Valid RateLimitUnit values are "Second", "Minute", "Hour", "Day", "Month" and "Year".
770770
enum:
771771
- Second
772772
- Minute
773773
- Hour
774774
- Day
775+
- Month
776+
- Year
775777
type: string
776778
required:
777779
- requests
@@ -901,12 +903,14 @@ spec:
901903
unit:
902904
description: |-
903905
RateLimitUnit specifies the intervals for setting rate limits.
904-
Valid RateLimitUnit values are "Second", "Minute", "Hour", and "Day".
906+
Valid RateLimitUnit values are "Second", "Minute", "Hour", "Day", "Month" and "Year".
905907
enum:
906908
- Second
907909
- Minute
908910
- Hour
909911
- Day
912+
- Month
913+
- Year
910914
type: string
911915
required:
912916
- requests

internal/gatewayapi/backendtrafficpolicy.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,10 @@ func ratelimitUnitToDuration(unit egv1a1.RateLimitUnit) int64 {
800800
seconds = 60 * 60
801801
case egv1a1.RateLimitUnitDay:
802802
seconds = 60 * 60 * 24
803+
case egv1a1.RateLimitUnitMonth:
804+
seconds = 60 * 60 * 24 * 30
805+
case egv1a1.RateLimitUnitYear:
806+
seconds = 60 * 60 * 24 * 365
803807
}
804808
return seconds
805809
}

internal/xds/translator/local_ratelimit.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ func ratelimitUnitToDuration(unit ir.RateLimitUnit) *durationpb.Duration {
302302
seconds = 60 * 60
303303
case egv1a1.RateLimitUnitDay:
304304
seconds = 60 * 60 * 24
305+
case egv1a1.RateLimitUnitMonth:
306+
seconds = 60 * 60 * 24 * 30
307+
case egv1a1.RateLimitUnitYear:
308+
seconds = 60 * 60 * 24 * 365
305309
}
306310
return &durationpb.Duration{
307311
Seconds: seconds,

site/content/en/latest/api/extension_types.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3450,7 +3450,7 @@ _Appears in:_
34503450
_Underlying type:_ _string_
34513451

34523452
RateLimitUnit specifies the intervals for setting rate limits.
3453-
Valid RateLimitUnit values are "Second", "Minute", "Hour", and "Day".
3453+
Valid RateLimitUnit values are "Second", "Minute", "Hour", and "Day", "Month" and "Year".
34543454

34553455
_Appears in:_
34563456
- [RateLimitValue](#ratelimitvalue)
@@ -3461,6 +3461,8 @@ _Appears in:_
34613461
| `Minute` | RateLimitUnitMinute specifies the rate limit interval to be 1 minute.<br /> |
34623462
| `Hour` | RateLimitUnitHour specifies the rate limit interval to be 1 hour.<br /> |
34633463
| `Day` | RateLimitUnitDay specifies the rate limit interval to be 1 day.<br /> |
3464+
| `Month` | RateLimitUnitDay specifies the rate limit interval to be 1 month.<br /> |
3465+
| `Year` | RateLimitUnitDay specifies the rate limit interval to be 1 year.<br /> |
34643466

34653467

34663468
#### RateLimitValue

0 commit comments

Comments
 (0)