Chore: Remove CRD generation (#67286)

This commit is contained in:
Todd Treece
2023-04-26 09:52:13 -04:00
committed by GitHub
parent 4b3aead2d0
commit a420040c73
27 changed files with 0 additions and 1456 deletions

View File

@@ -1,66 +0,0 @@
package {{ .PackageName }}
import (
"encoding/json"
"fmt"
{{range .Kinds }}
{{ .Props.MachineName }} "{{ $.KindPackagePrefix }}/{{ .Props.MachineName }}/crd"{{end}}
"github.com/grafana/kindsys"
"github.com/grafana/kindsys/k8ssys"
"github.com/grafana/grafana/pkg/registry/corekind"
"gopkg.in/yaml.v3"
)
// Registry is a list of all of Grafana's core structured kinds, wrapped in a
// standard [k8ssys.CRD] interface that makes them usable for interactions
// with certain Kubernetes controller and apimachinery libraries.
//
// There are two access methods: individually via literal named methods, or as
// a slice returned from All() method.
//
// Prefer the individual named methods for use cases where the particular kind(s)
// that are needed are known to the caller. Prefer All() when performing operations
// generically across all kinds.
type Registry struct {
all [{{ len .Kinds }}]k8ssys.Kind
}
{{range $i, $k := .Kinds }}
// {{ .Props.Name }} returns the [k8ssys.Kind] instance for the {{ .Props.Name }} kind.
func (r *Registry) {{ .Props.Name }}() k8ssys.Kind {
return r.all[{{ $i }}]
}
{{end}}
func doNewRegistry(breg *corekind.Base) *Registry {
var err error
var b []byte
var kk k8ssys.Kind
reg := &Registry{}
{{range $i, $k := .Kinds }}
kk = k8ssys.Kind{
GrafanaKind: breg.{{ $k.Props.Name }}(),
Object: &{{ $k.Props.MachineName }}.{{ $k.Props.Name }}{},
ObjectList: &{{ $k.Props.MachineName }}.{{ $k.Props.Name }}List{},
}
// TODO Having the committed form on disk in YAML is worth doing this for now...but fix this silliness
map{{ $i }} := make(map[string]any)
err = yaml.Unmarshal({{ $k.Props.MachineName }}.CRDYaml, map{{ $i }})
if err != nil {
panic(fmt.Sprintf("generated CRD YAML for {{ $k.Props.Name }} failed to unmarshal: %s", err))
}
b, err = json.Marshal(map{{ $i }})
if err != nil {
panic(fmt.Sprintf("could not re-marshal CRD JSON for {{ $k.Props.Name }}: %s", err))
}
err = json.Unmarshal(b, &kk.Schema)
if err != nil {
panic(fmt.Sprintf("could not unmarshal CRD JSON for {{ $k.Props.Name }}: %s", err))
}
reg.all[{{ $i }}] = kk
{{end}}
return reg
}

View File

@@ -1,25 +0,0 @@
package crd
import (
_ "embed"
"github.com/grafana/grafana/pkg/kinds/{{ .Props.MachineName }}"
"github.com/grafana/kindsys/k8ssys"
)
// The CRD YAML representation of the {{ .Props.Name }} kind.
//
//go:embed {{ .Props.MachineName }}.crd.yml
var CRDYaml []byte
// {{ .Props.Name }} is the Go CRD representation of a single {{ .Props.Name }} object.
// It implements [runtime.Object], and is used in k8s scheme construction.
type {{ .Props.Name }} struct {
k8ssys.Base[{{ .Props.MachineName }}.{{ .Props.Name }}]
}
// {{ .Props.Name }}List is the Go CRD representation of a list {{ .Props.Name }} objects.
// It implements [runtime.Object], and is used in k8s scheme construction.
type {{ .Props.Name }}List struct {
k8ssys.ListBase[{{ .Props.MachineName }}.{{ .Props.Name }}]
}