diff --git a/cmd/kubeconform/main.go b/cmd/kubeconform/main.go index 4a727ed..451e77d 100644 --- a/cmd/kubeconform/main.go +++ b/cmd/kubeconform/main.go @@ -26,7 +26,7 @@ func downloadSchema(registries []registry.Registry, kind, version, k8sVersion st } // If we get a 404, we try the next registry, but we exit if we get a real failure - if er, retryable := err.(registry.Retryable); retryable && !er.IsRetryable() { + if _, notfound := err.(*registry.NotFoundError); notfound { continue } diff --git a/pkg/registry/kubernetesjsonschema.go b/pkg/registry/kubernetesjsonschema.go index 4970024..7b9ee12 100644 --- a/pkg/registry/kubernetesjsonschema.go +++ b/pkg/registry/kubernetesjsonschema.go @@ -12,16 +12,14 @@ type KubernetesRegistry struct { strict bool } -type downloadError struct { - err error - isRetryable bool +type NotFoundError struct { + err error } -func newDownloadError(err error, isRetryable bool) *downloadError { - return &downloadError{err, isRetryable} +func newNetFoundError(err error) *NotFoundError { + return &NotFoundError{err} } -func (e *downloadError) IsRetryable() bool { return e.isRetryable } -func (e *downloadError) Error() string { return e.err.Error() } +func (e *NotFoundError) Error() string { return e.err.Error() } func newHTTPRegistry(schemaPathTemplate string, strict bool, skipTLS bool) *KubernetesRegistry { if skipTLS { @@ -47,7 +45,7 @@ func (r KubernetesRegistry) DownloadSchema(resourceKind, resourceAPIVersion, k8s defer resp.Body.Close() if resp.StatusCode == http.StatusNotFound { - return nil, newDownloadError(fmt.Errorf("no schema found"), false) + return nil, newNetFoundError(fmt.Errorf("no schema found")) } if resp.StatusCode != http.StatusOK { diff --git a/pkg/registry/local.go b/pkg/registry/local.go index d746591..6c41fd8 100644 --- a/pkg/registry/local.go +++ b/pkg/registry/local.go @@ -19,8 +19,8 @@ type fileNotFoundError struct { func newFileNotFoundError(err error, isRetryable bool) *fileNotFoundError { return &fileNotFoundError{err, isRetryable} } -func (e *fileNotFoundError) IsRetryable() bool { return e.isRetryable } -func (e *fileNotFoundError) Error() string { return e.err.Error() } +func (e *fileNotFoundError) IsNotFound() bool { return e.isRetryable } +func (e *fileNotFoundError) Error() string { return e.err.Error() } // NewLocalSchemas creates a new "registry", that will serve schemas from files, given a list of schema filenames func newLocalRegistry(pathTemplate string, strict bool) *LocalRegistry { diff --git a/pkg/registry/registry.go b/pkg/registry/registry.go index 0732355..f5e21b4 100644 --- a/pkg/registry/registry.go +++ b/pkg/registry/registry.go @@ -17,7 +17,7 @@ type Registry interface { // Retryable indicates whether an error is a temporary or a permanent failure type Retryable interface { - IsRetryable() bool + IsNotFound() bool } func schemaPath(tpl, resourceKind, resourceAPIVersion, k8sVersion string, strict bool) (string, error) {