forked from yannh/kubeconform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
32 lines (28 loc) · 883 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main
// WARNING: API of Kubeconform is still under development and not yet
// considered stable
import (
"github.com/yannh/kubeconform/pkg/validator"
"log"
"os"
)
func main() {
filepath := "../fixtures/valid.yaml"
f, err := os.Open(filepath)
if err != nil {
log.Fatalf("failed opening %s: %s", filepath, err)
}
v, err := validator.New(nil, validator.Opts{Strict: true})
if err != nil {
log.Fatalf("failed initializing validator: %s", err)
}
for i, res := range v.Validate(filepath, f) { // A file might contain multiple resources
// File starts with ---, the parser assumes a first empty resource
if res.Status == validator.Invalid {
log.Fatalf("resource %d in file %s is not valid: %s", i, filepath, res.Err)
}
if res.Status == validator.Error {
log.Fatalf("error while processing resource %d in file %s: %s", i, filepath, res.Err)
}
}
}