1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-10 01:46:55 +00:00
kyverno/cmd/cli/kubectl-kyverno/utils/values/load.go

34 lines
671 B
Go
Raw Normal View History

package values
import (
"io"
"os"
"github.com/go-git/go-billy/v5"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/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
}