Skip to content

Commit

Permalink
Merge pull request #210 from davidhao3300/master
Browse files Browse the repository at this point in the history
Cache schema misses if missing schemas allowed
  • Loading branch information
garethr authored Apr 14, 2020
2 parents ed0bb9a + ef1599d commit 46c69da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
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

0 comments on commit 46c69da

Please sign in to comment.