From ef44c39ff2c0e6a46418d5ec97f2dfdd07d361c2 Mon Sep 17 00:00:00 2001 From: Yann Hamon Date: Sun, 31 May 2020 01:09:05 +0200 Subject: [PATCH] be more explicit about caching of download failures --- pkg/cache/main.go | 8 ++++++++ pkg/registry/registry.go | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/pkg/cache/main.go b/pkg/cache/main.go index 5416a50..396cc27 100644 --- a/pkg/cache/main.go +++ b/pkg/cache/main.go @@ -3,6 +3,7 @@ package cache import ( "fmt" "github.com/xeipuuv/gojsonschema" + "github.com/yannh/kubeconform/pkg/registry" "sync" ) @@ -24,6 +25,13 @@ func WithCache(downloadSchema func(string, string, string) (*gojsonschema.Schema } schema, err := downloadSchema(resourceKind, resourceAPIVersion, k8sVersion) + if err != nil { + // will try to download the schema later, except if the error implements Retryable + // and returns false on IsRetryable + if er, retryable := err.(registry.Retryable); !(retryable && !er.IsRetryable()) { + return schema, err + } + } mu.Lock() schemas[cacheKey] = schema diff --git a/pkg/registry/registry.go b/pkg/registry/registry.go index 85cefa0..ef32f17 100644 --- a/pkg/registry/registry.go +++ b/pkg/registry/registry.go @@ -9,3 +9,7 @@ type Manifest struct { type Registry interface { DownloadSchema(resourceKind, resourceAPIVersion, k8sVersion string) (*gojsonschema.Schema, error) } + +type Retryable interface { + IsRetryable() bool +} \ No newline at end of file