[Chore] update to cue v0.4.0 (#39641)

* change global flag to flagset

* update pr with comments

* replace flag.args by flagset

* fix build

* migrate the schema package to use cue 4.0

* fix the load package
This commit is contained in:
ying-jeanne
2021-09-28 11:09:09 -04:00
committed by GitHub
parent 05bb451a1d
commit 580cdc46fc
10 changed files with 85 additions and 74 deletions
+9 -7
View File
@@ -12,11 +12,11 @@ import (
// definitions on which all Grafana scuemata rely.
//
// TODO probably cache this or something
func getBaseScuemata(p BaseLoadPaths) (*cue.Instance, error) {
func getBaseScuemata(p BaseLoadPaths) (cue.Value, error) {
overlay := make(map[string]load.Source)
if err := toOverlay(filepath.Join(prefix, "grafana"), p.BaseCueFS, overlay); err != nil {
return nil, err
return cue.Value{}, err
}
cfg := &load.Config{
@@ -37,10 +37,12 @@ func getBaseScuemata(p BaseLoadPaths) (*cue.Instance, error) {
// this "/".
Dir: prefix,
}
return rt.Build(load.Instances([]string{
res := ctx.BuildInstance(load.Instances([]string{
filepath.Join(prefix, "grafana", "cue", "scuemata", "scuemata.cue"),
filepath.Join(prefix, "grafana", "cue", "scuemata", "panel-plugin.cue"),
}, cfg)[0])
return res, res.Err()
}
func buildGenericScuemata(famval cue.Value) (schema.VersionedCueSchema, error) {
@@ -106,11 +108,11 @@ func (gvs *genericVersionedSchema) Validate(r schema.Resource) error {
if name == "" {
name = "resource"
}
rv, err := rt.Compile(name, r.Value)
if err != nil {
return err
rv := ctx.CompileString(r.Value.(string), cue.Filename(name))
if rv.Err() != nil {
return rv.Err()
}
return gvs.actual.Unify(rv.Value()).Validate(cue.Concrete(true))
return gvs.actual.Unify(rv).Validate(cue.Concrete(true))
}
// CUE returns the cue.Value representing the actual schema.