mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-11 14:09:21 +00:00
files to validate should be passed without -file, for ease of use with xargs
This commit is contained in:
parent
8fed078b9e
commit
dcaf1bc608
3 changed files with 26 additions and 15 deletions
11
Readme.md
11
Readme.md
|
|
@ -19,8 +19,8 @@ $ ./bin/kubeconform -h
|
|||
Usage of ./bin/kubeconform:
|
||||
-dir value
|
||||
directory to validate (can be specified multiple times)
|
||||
-file value
|
||||
file to validate (can be specified multiple times)
|
||||
-ignore-missing-schemas
|
||||
skip files with missing schemas instead of failing
|
||||
-k8sversion string
|
||||
version of Kubernetes to test against (default "1.18.0")
|
||||
-n int
|
||||
|
|
@ -80,6 +80,13 @@ fixtures/invalid.yaml - ReplicationController is invalid: Invalid type. Expected
|
|||
Run summary - Valid: 40, Invalid: 2, Errors: 0 Skipped: 6
|
||||
```
|
||||
|
||||
* Validating a custom resources, using a local schema
|
||||
|
||||
```
|
||||
$ bin/kubeconform -file fixtures/test_crd.yaml -schema fixtures/crd_schema.yaml -verbose
|
||||
fixtures/test_crd.yaml - TrainingJob is valid
|
||||
```
|
||||
|
||||
### Credits
|
||||
|
||||
* @garethr for the [Kubeval](https://github.com/instrumenta/kubeval) and
|
||||
|
|
|
|||
|
|
@ -1,61 +1,61 @@
|
|||
#!/usr/bin/env bats
|
||||
|
||||
@test "Pass when parsing a valid Kubernetes config YAML file" {
|
||||
run bin/kubeconform -file fixtures/valid.yaml -summary
|
||||
run bin/kubeconform -summary fixtures/valid.yaml
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "Summary: 1 resource found in 1 file - Valid: 1, Invalid: 0, Errors: 0 Skipped: 0" ]
|
||||
}
|
||||
|
||||
@test "Pass when parsing a Kubernetes file with string and integer quantities" {
|
||||
run bin/kubeconform -verbose -file fixtures/quantity.yaml
|
||||
run bin/kubeconform -verbose fixtures/quantity.yaml
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "fixtures/quantity.yaml - LimitRange is valid" ]
|
||||
}
|
||||
|
||||
@test "Pass when parsing a valid Kubernetes config file with null arrays" {
|
||||
run bin/kubeconform -verbose -file fixtures/null_string.yaml
|
||||
run bin/kubeconform -verbose fixtures/null_string.yaml
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "fixtures/null_string.yaml - Service is valid" ]
|
||||
}
|
||||
|
||||
@test "Pass when parsing a multi-document config file" {
|
||||
run bin/kubeconform -summary -file fixtures/multi_valid.yaml
|
||||
run bin/kubeconform -summary fixtures/multi_valid.yaml
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "Summary: 6 resources found in 1 file - Valid: 6, Invalid: 0, Errors: 0 Skipped: 0" ]
|
||||
}
|
||||
|
||||
@test "Fail when parsing a multi-document config file with one invalid resource" {
|
||||
run bin/kubeconform -file fixtures/multi_invalid.yaml
|
||||
run bin/kubeconform fixtures/multi_invalid.yaml
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "Fail when parsing an invalid Kubernetes config file" {
|
||||
run bin/kubeconform -file fixtures/invalid.yaml
|
||||
run bin/kubeconform fixtures/invalid.yaml
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "Return relevant error for non-existent file" {
|
||||
run bin/kubeconform -file fixtures/not-here
|
||||
run bin/kubeconform fixtures/not-here
|
||||
[ "$status" -eq 1 ]
|
||||
[ $(expr "$output" : "^failed opening fixtures/not-here") -ne 0 ]
|
||||
}
|
||||
|
||||
@test "Fail when parsing a config with additional properties and strict set" {
|
||||
run bin/kubeconform -strict -k8sversion 1.16.0 -file fixtures/extra_property.yaml
|
||||
run bin/kubeconform -strict -k8sversion 1.16.0 fixtures/extra_property.yaml
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "Fail when parsing a config with CRD" {
|
||||
run bin/kubeconform -file fixtures/test_crd.yaml
|
||||
run bin/kubeconform fixtures/test_crd.yaml
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "Pass when parsing a config with CRD and ignoring missing schemas" {
|
||||
run bin/kubeconform -file fixtures/test_crd.yaml -ignore-missing-schemas
|
||||
run bin/kubeconform -ignore-missing-schemas fixtures/test_crd.yaml
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "Succeed parsing a CRD when additional schema passed" {
|
||||
run bin/kubeconform -file fixtures/test_crd.yaml -schema fixtures/crd_schema.yaml
|
||||
run bin/kubeconform -schema fixtures/crd_schema.yaml fixtures/test_crd.yaml
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
|
|
|||
8
main.go
8
main.go
|
|
@ -178,14 +178,14 @@ func processResults(o output.Output, validationResults chan []validationResult,
|
|||
}
|
||||
|
||||
func realMain() int {
|
||||
var files, dirs, schemas arrayParam
|
||||
var dirs, schemas arrayParam
|
||||
var skipKindsCSV, k8sVersion, outputFormat string
|
||||
var summary, strict, verbose, ignoreMissingSchemas bool
|
||||
var nWorkers int
|
||||
var err error
|
||||
var files []string
|
||||
|
||||
flag.StringVar(&k8sVersion, "k8sversion", "1.18.0", "version of Kubernetes to test against")
|
||||
flag.Var(&files, "file", "file to validate (can be specified multiple times)")
|
||||
flag.Var(&dirs, "dir", "directory to validate (can be specified multiple times)")
|
||||
flag.Var(&schemas, "schema", "file containing an additional Schema (can be specified multiple times)")
|
||||
flag.BoolVar(&ignoreMissingSchemas, "ignore-missing-schemas", false, "skip files with missing schemas instead of failing")
|
||||
|
|
@ -199,6 +199,10 @@ func realMain() int {
|
|||
|
||||
skipKinds := skipKindsMap(skipKindsCSV)
|
||||
|
||||
for _, file := range flag.Args() {
|
||||
files = append(files, file)
|
||||
}
|
||||
|
||||
filter := func(signature resource.Signature) bool {
|
||||
isSkipKind, ok := skipKinds[signature.Kind]
|
||||
return ok && isSkipKind
|
||||
|
|
|
|||
Loading…
Reference in a new issue