Kindsys: Remove defs, Slot->SchemaInterface (#61069)
* kindsys: Remove defs, Slot->SchemaInterface * Remove excess file * Fix up tests * Regenerate kinds report * Final bits of cleanup * Stop complaining, linter * Update pkg/kindsys/kindcat_composable.cue Co-authored-by: Tania <yalyna.ts@gmail.com> Co-authored-by: Tania <yalyna.ts@gmail.com>
This commit is contained in:
@@ -37,7 +37,7 @@ func (j *pgoJenny) Generate(decl *pfs.PluginDecl) (*codejen.File, error) {
|
||||
}
|
||||
|
||||
pluginfolder := filepath.Base(decl.PluginPath)
|
||||
slotname := strings.ToLower(decl.Slot.Name())
|
||||
slotname := strings.ToLower(decl.SchemaInterface.Name())
|
||||
filename := fmt.Sprintf("types_%s_gen.go", slotname)
|
||||
f.RelativePath = filepath.Join(j.root, pluginfolder, filename)
|
||||
f.From = append(f.From, j)
|
||||
|
||||
@@ -40,7 +40,7 @@ func (j *ptsJenny) Generate(decl *pfs.PluginDecl) (*codejen.File, error) {
|
||||
}
|
||||
}
|
||||
|
||||
slotname := decl.Slot.Name()
|
||||
slotname := decl.SchemaInterface.Name()
|
||||
v := decl.Lineage.Latest().Version()
|
||||
|
||||
tsf.Nodes = append(tsf.Nodes, tsast.Raw{
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package grafanaplugin
|
||||
import "github.com/grafana/thema"
|
||||
|
||||
Query: thema.#Lineage & {
|
||||
name: "missing_slot_impl"
|
||||
name: "missing_kind_datasource"
|
||||
seqs: [
|
||||
{
|
||||
schemas: [
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"type": "datasource",
|
||||
"name": "Missing slot impl",
|
||||
"id": "missing-slot-datasource",
|
||||
"name": "Missing kind impl",
|
||||
"id": "missing-kind-datasource",
|
||||
"backend": true,
|
||||
"state": "alpha",
|
||||
"info": {
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
)
|
||||
|
||||
type PluginDecl struct {
|
||||
Slot *kindsys.Slot
|
||||
Lineage thema.Lineage
|
||||
Imports []*ast.ImportSpec
|
||||
PluginPath string
|
||||
PluginMeta plugindef.PluginDef
|
||||
SchemaInterface *kindsys.SchemaInterface
|
||||
Lineage thema.Lineage
|
||||
Imports []*ast.ImportSpec
|
||||
PluginPath string
|
||||
PluginMeta plugindef.PluginDef
|
||||
}
|
||||
|
||||
func EmptyPluginDecl(path string, meta plugindef.PluginDef) *PluginDecl {
|
||||
@@ -24,5 +24,5 @@ func EmptyPluginDecl(path string, meta plugindef.PluginDef) *PluginDecl {
|
||||
}
|
||||
|
||||
func (decl *PluginDecl) HasSchema() bool {
|
||||
return decl.Lineage != nil && decl.Slot != nil
|
||||
return decl.Lineage != nil && decl.SchemaInterface != nil
|
||||
}
|
||||
|
||||
@@ -54,17 +54,17 @@ func (psr *declParser) Parse(root fs.FS) ([]*PluginDecl, error) {
|
||||
}
|
||||
|
||||
for slotName, lin := range slots {
|
||||
slot, err := kindsys.FindSlot(slotName)
|
||||
slot, err := kindsys.FindSchemaInterface(slotName)
|
||||
if err != nil {
|
||||
log.Println(fmt.Errorf("parsing plugin failed for %s: %s", dir, err))
|
||||
continue
|
||||
}
|
||||
decls = append(decls, &PluginDecl{
|
||||
Slot: slot,
|
||||
Lineage: lin,
|
||||
Imports: p.CUEImports(),
|
||||
PluginMeta: p.Meta(),
|
||||
PluginPath: path,
|
||||
SchemaInterface: &slot,
|
||||
Lineage: lin,
|
||||
Imports: p.CUEImports(),
|
||||
PluginMeta: p.Meta(),
|
||||
PluginPath: path,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+15
-11
@@ -43,7 +43,7 @@ var allowedImportsStr string
|
||||
|
||||
type slotandname struct {
|
||||
name string
|
||||
slot *kindsys.Slot
|
||||
slot kindsys.SchemaInterface
|
||||
}
|
||||
|
||||
var allslots []slotandname
|
||||
@@ -55,7 +55,7 @@ func init() {
|
||||
}
|
||||
allowedImportsStr = strings.Join(all, "\n")
|
||||
|
||||
for n, s := range kindsys.AllSlots(nil) {
|
||||
for n, s := range kindsys.SchemaInterfaces(nil) {
|
||||
allslots = append(allslots, slotandname{
|
||||
name: n,
|
||||
slot: s,
|
||||
@@ -93,7 +93,7 @@ func (t *Tree) SubPlugins() map[string]PluginInfo {
|
||||
type TreeList []*Tree
|
||||
|
||||
// LineagesForSlot returns the set of plugin-defined lineages that implement a
|
||||
// particular named Grafana slot (See ["github.com/grafana/grafana/pkg/framework/coremodel".Slot]).
|
||||
// particular named Grafana slot (See ["github.com/grafana/grafana/pkg/framework/coremodel".SchemaInterface]).
|
||||
func (tl TreeList) LineagesForSlot(slotname string) map[string]thema.Lineage {
|
||||
m := make(map[string]thema.Lineage)
|
||||
for _, tree := range tl {
|
||||
@@ -218,12 +218,14 @@ func ParsePluginFS(f fs.FS, rt *thema.Runtime) (*Tree, error) {
|
||||
}
|
||||
for _, s := range allslots {
|
||||
iv := val.LookupPath(cue.ParsePath(s.slot.Name()))
|
||||
lin, err := bindSlotLineage(iv, s.slot, r.meta, rt)
|
||||
if lin != nil {
|
||||
r.slotimpls[s.slot.Name()] = lin
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if iv.Exists() {
|
||||
lin, err := bindSlotLineage(iv, s.slot, r.meta, rt)
|
||||
if lin != nil {
|
||||
r.slotimpls[s.slot.Name()] = lin
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -231,8 +233,10 @@ func ParsePluginFS(f fs.FS, rt *thema.Runtime) (*Tree, error) {
|
||||
return tree, nil
|
||||
}
|
||||
|
||||
func bindSlotLineage(v cue.Value, s *kindsys.Slot, meta plugindef.PluginDef, rt *thema.Runtime, opts ...thema.BindOption) (thema.Lineage, error) {
|
||||
accept, required := s.ForPluginType(string(meta.Type))
|
||||
func bindSlotLineage(v cue.Value, s kindsys.SchemaInterface, meta plugindef.PluginDef, rt *thema.Runtime, opts ...thema.BindOption) (thema.Lineage, error) {
|
||||
// temporarily keep this around, there are IMMEDIATE plans to refactor
|
||||
var required bool
|
||||
accept := s.Should(string(meta.Type))
|
||||
exists := v.Exists()
|
||||
|
||||
if !accept {
|
||||
|
||||
@@ -115,9 +115,7 @@ func TestParseTreeTestdata(t *testing.T) {
|
||||
"wrong-slot-panel": {
|
||||
err: ErrImplementedSlots,
|
||||
},
|
||||
"missing-slot-impl": {
|
||||
err: ErrImplementedSlots,
|
||||
},
|
||||
"missing-kind-datasource": {},
|
||||
"panel-conflicting-joinschema": {
|
||||
err: ErrInvalidLineage,
|
||||
skip: "TODO implement BindOption in thema, SatisfiesJoinSchema, then use it here",
|
||||
|
||||
Reference in New Issue
Block a user