1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-09 17:37:12 +00:00
kyverno/cmd/cli/kubectl-kyverno/utils/values/load.go
Charles-Edouard Brétéché cef4a9b546
refactor: move all cli commands in a commands package (#8231)
* chore: name all cli command files the same

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* refactor: move all cli commands in a commands package

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

* root

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>

---------

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-09-04 15:15:55 +00:00

33 lines
680 B
Go

package values
import (
"io"
"os"
"github.com/go-git/go-billy/v5"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
"k8s.io/apimachinery/pkg/util/yaml"
)
func readFile(f billy.Filesystem, filepath string) ([]byte, error) {
if f != nil {
filep, err := f.Open(filepath)
if err != nil {
return nil, err
}
return io.ReadAll(filep)
}
return os.ReadFile(filepath)
}
func Load(f billy.Filesystem, filepath string) (*api.Values, error) {
yamlBytes, err := readFile(f, filepath)
if err != nil {
return nil, err
}
vals := &api.Values{}
if err := yaml.UnmarshalStrict(yamlBytes, vals); err != nil {
return nil, err
}
return vals, nil
}