mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 14:09:21 +00:00
fix - do try following schema registries when schema not found in local registry
This commit is contained in:
parent
9a56fc4176
commit
1a76217195
4 changed files with 18 additions and 23 deletions
|
|
@ -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 ]
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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" {
|
||||
|
|
|
|||
Loading…
Reference in a new issue