fix: propagate source criterion config to RateLimit middleware in Kubernetes CRD

This commit is contained in:
Romain Bailly 2021-11-26 12:10:11 +01:00 committed by GitHub
parent 321c9421ea
commit ef2d03d96e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 1 deletions

View file

@ -9,6 +9,24 @@ spec:
prefixes:
- /tobestripped
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: ratelimit
namespace: default
spec:
rateLimit:
period: 1m
average: 6
burst: 12
sourceCriterion:
ipStrategy:
excludedIPs:
- 127.0.0.1/32
- 192.168.1.7
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
@ -40,5 +58,6 @@ spec:
port: 80
middlewares:
- name: stripprefix
- name: ratelimit
- name: addprefix
namespace: foo

View file

@ -426,6 +426,10 @@ func createRateLimitMiddleware(rateLimit *v1alpha1.RateLimit) (*dynamic.RateLimi
}
}
if rateLimit.SourceCriterion != nil {
rl.SourceCriterion = rateLimit.SourceCriterion
}
return rl, nil
}

View file

@ -1470,10 +1470,22 @@ func TestLoadIngressRoutes(t *testing.T) {
Service: "default-test2-route-23c7f4c450289ee29016",
Rule: "Host(`foo.com`) && PathPrefix(`/tobestripped`)",
Priority: 12,
Middlewares: []string{"default-stripprefix", "foo-addprefix"},
Middlewares: []string{"default-stripprefix", "default-ratelimit", "foo-addprefix"},
},
},
Middlewares: map[string]*dynamic.Middleware{
"default-ratelimit": {
RateLimit: &dynamic.RateLimit{
Average: 6,
Burst: 12,
Period: ptypes.Duration(60 * time.Second),
SourceCriterion: &dynamic.SourceCriterion{
IPStrategy: &dynamic.IPStrategy{
ExcludedIPs: []string{"127.0.0.1/32", "192.168.1.7"},
},
},
},
},
"default-stripprefix": {
StripPrefix: &dynamic.StripPrefix{
Prefixes: []string{"/tobestripped"},