2023-07-03 15:22:05 +02:00
|
|
|
package values
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/go-git/go-billy/v5"
|
2023-09-17 22:50:17 +02:00
|
|
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/apis/v1alpha1"
|
2023-07-03 15:22:05 +02:00
|
|
|
"k8s.io/apimachinery/pkg/util/yaml"
|
|
|
|
)
|
|
|
|
|
2023-09-17 22:50:17 +02:00
|
|
|
func Load(f billy.Filesystem, filepath string) (*v1alpha1.Values, error) {
|
2023-07-03 15:22:05 +02:00
|
|
|
yamlBytes, err := readFile(f, filepath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-09-17 22:50:17 +02:00
|
|
|
vals := &v1alpha1.Values{}
|
2023-08-30 18:17:28 +02:00
|
|
|
if err := yaml.UnmarshalStrict(yamlBytes, vals); err != nil {
|
2023-07-03 15:22:05 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return vals, nil
|
|
|
|
}
|
2023-09-06 16:03:51 +02:00
|
|
|
|
|
|
|
func readFile(f billy.Filesystem, filepath string) ([]byte, error) {
|
|
|
|
if f != nil {
|
|
|
|
file, err := f.Open(filepath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
return io.ReadAll(file)
|
|
|
|
}
|
|
|
|
return os.ReadFile(filepath)
|
|
|
|
}
|