feat(k8s): add rate limit annotations.

This commit is contained in:
Fernandez Ludovic 2017-12-21 22:07:37 +01:00 committed by Traefiker
parent 4c0d6e211b
commit 1c495d7ea4
4 changed files with 117 additions and 8 deletions

View file

@ -2,7 +2,9 @@ package kubernetes
import (
"testing"
"time"
"github.com/containous/flaeg"
"github.com/containous/traefik/tls"
"github.com/containous/traefik/types"
"github.com/stretchr/testify/assert"
@ -252,6 +254,57 @@ func errorBackend(backend string) func(*types.ErrorPage) {
}
}
func rateLimit(opts ...func(*types.RateLimit)) func(*types.Frontend) {
return func(f *types.Frontend) {
if f.RateLimit == nil {
f.RateLimit = &types.RateLimit{}
}
for _, opt := range opts {
opt(f.RateLimit)
}
}
}
func rateExtractorFunc(exp string) func(*types.RateLimit) {
return func(limit *types.RateLimit) {
limit.ExtractorFunc = exp
}
}
func rateSet(name string, opts ...func(*types.Rate)) func(*types.RateLimit) {
return func(limit *types.RateLimit) {
if limit.RateSet == nil {
limit.RateSet = make(map[string]*types.Rate)
}
if len(name) > 0 {
limit.RateSet[name] = &types.Rate{}
for _, opt := range opts {
opt(limit.RateSet[name])
}
}
}
}
func limitAverage(avg int64) func(*types.Rate) {
return func(rate *types.Rate) {
rate.Average = avg
}
}
func limitBurst(burst int64) func(*types.Rate) {
return func(rate *types.Rate) {
rate.Burst = burst
}
}
func limitPeriod(period time.Duration) func(*types.Rate) {
return func(rate *types.Rate) {
rate.Period = flaeg.Duration(period)
}
}
func passTLSCert() func(*types.Frontend) {
return func(f *types.Frontend) {
f.PassTLSCert = true