1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-09 09:26:54 +00:00
kyverno/cmd/cli/kubectl-kyverno/variables/new.go

30 lines
844 B
Go
Raw Normal View History

package variables
import (
"fmt"
"io"
"path/filepath"
"github.com/go-git/go-billy/v5"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/apis/v1alpha1"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/deprecations"
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/values"
)
func New(out io.Writer, fs billy.Filesystem, resourcePath string, path string, vals *v1alpha1.ValuesSpec, vars ...string) (*Variables, error) {
// if we already have values, skip the file
if vals == nil && path != "" {
v, err := values.Load(fs, filepath.Join(resourcePath, path))
if err != nil {
return nil, fmt.Errorf("unable to load variable file: %s (%w)", path, err)
}
deprecations.CheckValues(out, path, v)
vals = &v.ValuesSpec
}
variables := Variables{
values: vals,
variables: parse(vars...),
}
return &variables, nil
}