mirror of
https://github.com/yannh/kubeconform.git
synced 2026-04-08 06:34:16 +00:00
Add example how to use kubeconform as a library
This commit is contained in:
parent
4672ded043
commit
4e96b44a8b
7 changed files with 93 additions and 18 deletions
26
examples/main.go
Normal file
26
examples/main.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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 := validator.New(nil, validator.Opts{Strict: true})
|
||||
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.Valid && res.Status != validator.Empty {
|
||||
log.Fatalf("resource %d in file %s is not valid: %d, %s", i, filepath, res.Status, res.Err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue