be more explicit about caching of download failures

This commit is contained in:
Yann Hamon 2020-05-31 01:09:05 +02:00
parent 30a6fe69b1
commit ef44c39ff2
2 changed files with 12 additions and 0 deletions

8
pkg/cache/main.go vendored
View file

@ -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

View file

@ -9,3 +9,7 @@ type Manifest struct {
type Registry interface {
DownloadSchema(resourceKind, resourceAPIVersion, k8sVersion string) (*gojsonschema.Schema, error)
}
type Retryable interface {
IsRetryable() bool
}