Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache schema misses if missing schemas allowed #210

Merged
merged 2 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion fixtures/test_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@ metadata:
namespace: test-namespace
spec:
encryptedData:
SOME_ENCRYPTED_DATA: c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2
SOME_ENCRYPTED_DATA: c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2
---
apiVersion: bitnami.com/v1alpha1
kind: SealedSecret
metadata:
name: test-secret-clone
namespace: test-namespace
spec:
encryptedData:
SOME_ENCRYPTED_DATA: c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2
8 changes: 4 additions & 4 deletions kubeval/kubeval.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func validateResource(data []byte, schemaCache map[string]*gojsonschema.Schema,
func validateAgainstSchema(body interface{}, resource *ValidationResult, schemaCache map[string]*gojsonschema.Schema, config *Config) ([]gojsonschema.ResultError, error) {

schema, err := downloadSchema(resource, schemaCache, config)
if err != nil {
if err != nil || schema == nil {
return handleMissingSchema(err, config)
}

Expand All @@ -161,6 +161,7 @@ func validateAgainstSchema(body interface{}, resource *ValidationResult, schemaC
return []gojsonschema.ResultError{}, nil
}

// returned schema may be nil scehma is missing and missing schemas are allowed
func downloadSchema(resource *ValidationResult, schemaCache map[string]*gojsonschema.Schema, config *Config) (*gojsonschema.Schema, error) {
if schema, ok := schemaCache[resource.VersionKind()]; ok {
// If the schema was previously cached, there's no work to be done
Expand Down Expand Up @@ -196,9 +197,8 @@ func downloadSchema(resource *ValidationResult, schemaCache map[string]*gojsonsc
errors.ErrorFormat = singleLineErrorFormat
}

// TODO: this currently triggers a segfault in offline cases
// We couldn't find a schema for this resource. Cache it's lack of existence, then stop
//schemaCache[resource.VersionKind()] = nil
// We couldn't find a schema for this resource. Cache its lack of existence
schemaCache[resource.VersionKind()] = nil
return nil, errors.ErrorOrNil()
}

Expand Down