diff options
| author | jannfis <jann@mistrust.net> | 2020-11-23 11:42:50 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-23 11:42:50 +0100 |
| commit | d5fb02198919da7ae95f52dd9209abdd3ec3bf4f (patch) | |
| tree | 2b4a0e5c28da64298e108ea43323ad42a005b78d /pkg | |
| parent | 96a470327693304ded06432da348926130ee91af (diff) | |
fix: Provide sane rate limiter defaults (#119)
* fix: Adapt rate limiter defaults
* Set default to reasonable value
* Prevent rate limit <0
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/registry/endpoints.go | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/pkg/registry/endpoints.go b/pkg/registry/endpoints.go index ec98a42..f218699 100644 --- a/pkg/registry/endpoints.go +++ b/pkg/registry/endpoints.go @@ -21,6 +21,11 @@ const ( SortLatestLast TagListSort = 2 ) +const ( + RateLimitNone = math.MaxInt32 + RateLimitDefault = 10 +) + // IsTimeSorted returns whether a tag list is time sorted func (tls TagListSort) IsTimeSorted() bool { return tls == SortLatestFirst || tls == SortLatestLast @@ -69,7 +74,7 @@ var defaultRegistries map[string]*RegistryEndpoint = map[string]*RegistryEndpoin Insecure: false, DefaultNS: "library", Cache: cache.NewMemCache(), - Limiter: ratelimit.New(5), + Limiter: ratelimit.New(RateLimitDefault), }, "gcr.io": { RegistryName: "Google Container Registry", @@ -78,7 +83,7 @@ var defaultRegistries map[string]*RegistryEndpoint = map[string]*RegistryEndpoin Ping: false, Insecure: false, Cache: cache.NewMemCache(), - Limiter: ratelimit.New(5), + Limiter: ratelimit.New(RateLimitDefault), }, "quay.io": { RegistryName: "RedHat Quay", @@ -87,7 +92,7 @@ var defaultRegistries map[string]*RegistryEndpoint = map[string]*RegistryEndpoin Ping: false, Insecure: false, Cache: cache.NewMemCache(), - Limiter: ratelimit.New(5), + Limiter: ratelimit.New(RateLimitDefault), }, "docker.pkg.github.com": { RegistryName: "GitHub packages", @@ -95,9 +100,8 @@ var defaultRegistries map[string]*RegistryEndpoint = map[string]*RegistryEndpoin RegistryAPI: "https://docker.pkg.github.com", Ping: false, Insecure: false, - TagListSort: SortLatestFirst, Cache: cache.NewMemCache(), - Limiter: ratelimit.New(5), + Limiter: ratelimit.New(RateLimitDefault), }, "ghcr.io": { RegistryName: "GitHub Container Registry", @@ -105,9 +109,8 @@ var defaultRegistries map[string]*RegistryEndpoint = map[string]*RegistryEndpoin RegistryAPI: "https://ghcr.io", Ping: false, Insecure: false, - TagListSort: SortLatestLast, Cache: cache.NewMemCache(), - Limiter: ratelimit.New(5), + Limiter: ratelimit.New(RateLimitDefault), }, } @@ -120,8 +123,8 @@ var registryLock sync.RWMutex func AddRegistryEndpoint(prefix, name, apiUrl, credentials, defaultNS string, insecure bool, tagListSort TagListSort, limit int) error { registryLock.Lock() defer registryLock.Unlock() - if limit == 0 { - limit = math.MaxInt32 + if limit <= 0 { + limit = RateLimitNone } log.Debugf("rate limit for %s is %d", apiUrl, limit) registries[prefix] = &RegistryEndpoint{ @@ -175,6 +178,7 @@ func ConfiguredEndpoints() []string { // DeepCopy copies the endpoint to a new object, but creating a new Cache func (ep *RegistryEndpoint) DeepCopy() *RegistryEndpoint { + ep.lock.RLock() newEp := &RegistryEndpoint{} newEp.RegistryAPI = ep.RegistryAPI newEp.RegistryName = ep.RegistryName @@ -186,6 +190,7 @@ func (ep *RegistryEndpoint) DeepCopy() *RegistryEndpoint { newEp.Insecure = ep.Insecure newEp.DefaultNS = ep.DefaultNS newEp.Limiter = ep.Limiter + ep.lock.RUnlock() return newEp } |
