extract kindsys to external library (#64562)

* extract kindsys

* reinstate kindsys report

This may end up living somewhere else (or not! who knows!), but the important part is that I don't get rid of it right now :)

I hate the package layout (kindsysreport/codegen) for the main function and will take pretty much any alternative suggestion, but we can change also change it later.

Note that the generated report.json is in a different location - anything using this (ops something) needs to be updated.

* kindsysreport in codeowners
This commit is contained in:
Kristin Laemmert
2023-03-15 12:04:28 -04:00
committed by GitHub
parent 3f5acf346d
commit 8745d7ef1b
70 changed files with 390 additions and 1515 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"path/filepath"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/kindsys"
"github.com/grafana/thema"
)
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"path/filepath"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/kindsys"
)
// BaseCoreRegistryJenny generates a static registry for core kinds that
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"path/filepath"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/kindsys"
)
// CoreKindJenny generates the implementation of [kindsys.Core] for the provided
+4 -2
View File
@@ -6,7 +6,9 @@ import (
"path/filepath"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/kindsys"
"github.com/grafana/grafana/pkg/cuectx"
)
// CRDKindRegistryJenny generates a static registry of the CRD representations
@@ -43,7 +45,7 @@ func (j *crdregjenny) Generate(kinds ...kindsys.Kind) (*codejen.File, error) {
buf := new(bytes.Buffer)
if err := tmpls.Lookup("core_crd_registry.tmpl").Execute(buf, tvars_kind_registry{
PackageName: "corecrd",
KindPackagePrefix: filepath.ToSlash(filepath.Join("github.com/grafana/grafana", kindsys.GoCoreKindParentPath)),
KindPackagePrefix: filepath.ToSlash(filepath.Join("github.com/grafana/grafana", cuectx.GoCoreKindParentPath)),
Kinds: cores,
}); err != nil {
return nil, fmt.Errorf("failed executing core crd registry template: %w", err)
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"path/filepath"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/kindsys"
)
// CRDTypesJenny generates the OpenAPI CRD representation for a core
+3 -2
View File
@@ -10,10 +10,11 @@ import (
"cuelang.org/go/encoding/openapi"
cueyaml "cuelang.org/go/pkg/encoding/yaml"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/grafana/pkg/kindsys/k8ssys"
"github.com/grafana/kindsys/k8ssys"
"github.com/grafana/thema"
goyaml "gopkg.in/yaml.v3"
"github.com/grafana/kindsys"
)
// TODO this jenny is quite sloppy, having been quickly adapted from app-sdk. It needs love
+3 -2
View File
@@ -15,11 +15,12 @@ import (
"cuelang.org/go/cue/cuecontext"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/kindsys"
"github.com/grafana/thema/encoding/jsonschema"
"github.com/olekukonko/tablewriter"
"github.com/xeipuuv/gojsonpointer"
"github.com/grafana/grafana/pkg/components/simplejson"
)
func DocsJenny(docsPath string) OneToOne {
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"path/filepath"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/kindsys"
)
// LatestMajorsOrXJenny returns a jenny that repeats the input for the latest in each major version,
+1 -1
View File
@@ -11,7 +11,7 @@ import (
"github.com/grafana/codejen"
"github.com/grafana/cuetsy/ts"
"github.com/grafana/cuetsy/ts/ast"
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/kindsys"
"github.com/grafana/thema"
"github.com/grafana/thema/encoding/typescript"
)
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"path/filepath"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/kindsys"
)
// LatestJenny returns a jenny that runs another jenny for only the latest
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"time"
"github.com/grafana/codejen"
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/kindsys"
)
// All the parsed templates in the tmpl subdirectory
+2 -2
View File
@@ -6,8 +6,8 @@ import (
{{range .Kinds }}
{{ .Props.MachineName }} "{{ $.KindPackagePrefix }}/{{ .Props.MachineName }}/crd"{{end}}
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/grafana/pkg/kindsys/k8ssys"
"github.com/grafana/kindsys"
"github.com/grafana/kindsys/k8ssys"
"github.com/grafana/grafana/pkg/registry/corekind"
"gopkg.in/yaml.v3"
)
+1 -1
View File
@@ -4,7 +4,7 @@ import (
_ "embed"
"github.com/grafana/grafana/pkg/kinds/{{ .Props.MachineName }}"
"github.com/grafana/grafana/pkg/kindsys/k8ssys"
"github.com/grafana/kindsys/k8ssys"
)
// The CRD YAML representation of the {{ .Props.Name }} kind.
+4 -2
View File
@@ -1,9 +1,11 @@
package {{ .Props.MachineName }}
import (
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/kindsys"
"github.com/grafana/thema"
"github.com/grafana/thema/vmux"
"github.com/grafana/grafana/pkg/cuectx"
)
// rootrel is the relative path from the grafana repository root to the
@@ -25,7 +27,7 @@ var _ kindsys.Core = &Kind{}
// TODO standard generated docs
func NewKind(rt *thema.Runtime, opts ...thema.BindOption) (*Kind, error) {
def, err := kindsys.LoadCoreKindDef(rootrel, rt.Context(), nil)
def, err := cuectx.LoadCoreKindDef(rootrel, rt.Context(), nil)
if err != nil {
return nil, err
}
+1 -1
View File
@@ -7,7 +7,7 @@ import (
{{range .Kinds }}
"{{ $.KindPackagePrefix }}/{{ .Props.MachineName }}"{{end}}
"github.com/grafana/grafana/pkg/cuectx"
"github.com/grafana/grafana/pkg/kindsys"
"github.com/grafana/kindsys"
"github.com/grafana/thema"
)
+2 -1
View File
@@ -7,9 +7,10 @@ import (
"path/filepath"
"sync"
"github.com/grafana/thema"
"github.com/grafana/grafana/pkg/cuectx"
"github.com/grafana/grafana/pkg/plugins/pfs"
"github.com/grafana/thema"
)
var parseOnce sync.Once