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