diff --git a/acceptance.bats b/acceptance.bats index 8617d5b..37b6e1b 100755 --- a/acceptance.bats +++ b/acceptance.bats @@ -115,6 +115,11 @@ [ "$status" -eq 0 ] } +@test "Pass when parsing a Custom Resource and specifying several local registries, the last one having the appropriate CRD" { + run bin/kubeconform -schema-location 'fixtures/{{ .ResourceKind }}.json' -schema-location './fixtures/registry/{{ .ResourceKind }}{{ .KindSuffix }}.json' fixtures/test_crd.yaml + [ "$status" -eq 0 ] +} + @test "Pass when parsing a config with additional properties" { run bin/kubeconform -summary fixtures/extra_property.yaml [ "$status" -eq 0 ] diff --git a/pkg/registry/http.go b/pkg/registry/http.go index 3126114..765632a 100644 --- a/pkg/registry/http.go +++ b/pkg/registry/http.go @@ -19,16 +19,6 @@ type SchemaRegistry struct { strict bool } -// NotFoundError is returned when the registry does not contain a schema for the resource -type NotFoundError struct { - err error -} - -func newNetFoundError(err error) *NotFoundError { - return &NotFoundError{err} -} -func (e *NotFoundError) Error() string { return e.err.Error() } - func newHTTPRegistry(schemaPathTemplate string, strict bool, skipTLS bool) *SchemaRegistry { reghttp := &http.Transport{ MaxIdleConns: 100, @@ -61,7 +51,7 @@ func (r SchemaRegistry) DownloadSchema(resourceKind, resourceAPIVersion, k8sVers defer resp.Body.Close() if resp.StatusCode == http.StatusNotFound { - return nil, newNetFoundError(fmt.Errorf("no schema found")) + return nil, newNotFoundError(fmt.Errorf("no schema found")) } if resp.StatusCode != http.StatusOK { diff --git a/pkg/registry/local.go b/pkg/registry/local.go index ed17ce4..afb5b0c 100644 --- a/pkg/registry/local.go +++ b/pkg/registry/local.go @@ -11,17 +11,6 @@ type LocalRegistry struct { strict bool } -type fileNotFoundError struct { - err error - isRetryable bool -} - -func newFileNotFoundError(err error, isRetryable bool) *fileNotFoundError { - return &fileNotFoundError{err, isRetryable} -} -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 { return &LocalRegistry{ @@ -39,7 +28,7 @@ func (r LocalRegistry) DownloadSchema(resourceKind, resourceAPIVersion, k8sVersi f, err := os.Open(schemaFile) if err != nil { if os.IsNotExist(err) { - return nil, newFileNotFoundError(fmt.Errorf("no schema found"), false) + return nil, newNotFoundError(fmt.Errorf("no schema found")) } return nil, fmt.Errorf("failed to open schema %s", schemaFile) } diff --git a/pkg/registry/registry.go b/pkg/registry/registry.go index d700721..32ecbb7 100644 --- a/pkg/registry/registry.go +++ b/pkg/registry/registry.go @@ -21,6 +21,17 @@ type Retryable interface { IsNotFound() bool } +// NotFoundError is returned when the registry does not contain a schema for the resource +type NotFoundError struct { + err error +} + +func newNotFoundError(err error) *NotFoundError { + return &NotFoundError{err} +} +func (e *NotFoundError) Error() string { return e.err.Error() } +func (e *NotFoundError) Retryable() bool { return false } + func schemaPath(tpl, resourceKind, resourceAPIVersion, k8sVersion string, strict bool) (string, error) { normalisedVersion := k8sVersion if normalisedVersion != "master" {