Skip to content

Commit

Permalink
Added acceptance tests and docs for the ignore missing schemas flag
Browse files Browse the repository at this point in the history
  • Loading branch information
garethr committed Jul 13, 2019
1 parent e13fe0d commit 312975f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
10 changes: 10 additions & 0 deletions acceptance.bats
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,13 @@
run kubeval fixtures/extra_property.yaml
[ "$status" -eq 0 ]
}

@test "Fail when parsing a config with CRD" {
run kubeval fixtures/test_crd.yaml
[ "$status" -eq 1 ]
}

@test "Pass when parsing a config with CRD and ignoring missing schemas" {
run kubeval --ignore-missing-schemas fixtures/test_crd.yaml
[ "$status" -eq 0 ]
}
14 changes: 14 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ $ echo $?
```


## CRDs

Currently kubeval relies on schemas generated from the Kubernetes API. This means it's not
possible to validate resources using CRDs. Currently you need to pass a flag to ignore
missing schemas, though this may change in a future major version.

```
$ kubeval --ignore-missing-schemas fixtures/test_crd.yaml
Warning: Set to ignore missing schemas
The document fixtures/test_crd.yaml contains a valid SealedSecret
```


## Full usage instructions

```
Expand All @@ -73,6 +86,7 @@ Usage:
Flags:
-f, --filename string filename to be displayed when testing manifests read from stdin (default "stdin")
-h, --help help for kubeval
--ignore-missing-schemas Skip validation for resource definitions without a schema
-v, --kubernetes-version string Version of Kubernetes to validate against (default "master")
--openshift Use OpenShift schemas instead of upstream Kubernetes
--schema-location string Base URL used to download schemas. Can also be specified with the environment variable KUBEVAL_SCHEMA_LOCATION (default "https://raw.githubusercontent.com/garethr")
Expand Down
2 changes: 1 addition & 1 deletion kubeval/kubeval.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func validateResource(data []byte, fileName string, schemaCache map[string]*gojs
var spec interface{}
result := ValidationResult{}
if IgnoreMissingSchemas {
log.Warn("Warning: Set to ignore missing schemas!")
log.Warn("Warning: Set to ignore missing schemas")
}
result.FileName = fileName
err := yaml.Unmarshal(data, &spec)
Expand Down
20 changes: 11 additions & 9 deletions kubeval/kubeval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,6 @@ func TestStrictCatchesAdditionalErrors(t *testing.T) {
}
}

func TestSkipCrdSchemaMiss(t *testing.T) {
IgnoreMissingSchemas = true
filePath, _ := filepath.Abs("../fixtures/test_crd.yaml")
fileContents, _ := ioutil.ReadFile(filePath)
results, _ := Validate(fileContents, "test_crd.yaml")
if len(results[0].Errors) != 0 {
t.Errorf("For custom CRD's with schema missing we should skip with SkipCrdSchemaMiss flag")
}
}

func TestValidateMultipleVersions(t *testing.T) {
Strict = true
Expand Down Expand Up @@ -170,3 +161,14 @@ func TestDetermineKind(t *testing.T) {
t.Errorf("Shouldn't be able to find a kind when passed a blank string")
}
}

func TestSkipCrdSchemaMiss(t *testing.T) {
IgnoreMissingSchemas = true
filePath, _ := filepath.Abs("../fixtures/test_crd.yaml")
fileContents, _ := ioutil.ReadFile(filePath)
results, _ := Validate(fileContents, "test_crd.yaml")
if len(results[0].Errors) != 0 {
t.Errorf("For custom CRD's with schema missing we should skip with SkipCrdSchemaMiss flag")
}
}

0 comments on commit 312975f

Please sign in to comment.