Kinds: Use apimachinery ObjectMeta for metadata (#68668)
This commit is contained in:
@@ -48,6 +48,7 @@ func (ag *ResourceGoTypesJenny) Generate(kind kindsys.Kind) (*codejen.File, erro
|
||||
if err := tmpls.Lookup("core_resource.tmpl").Execute(buf, tvars_resource{
|
||||
PackageName: mname,
|
||||
KindName: kind.Props().Common().Name,
|
||||
Version: sch.Version().String(),
|
||||
SubresourceNames: subr,
|
||||
}); err != nil {
|
||||
return nil, fmt.Errorf("failed executing core resource template: %w", err)
|
||||
|
||||
@@ -41,6 +41,7 @@ type (
|
||||
tvars_resource struct {
|
||||
PackageName string
|
||||
KindName string
|
||||
Version string
|
||||
SubresourceNames []string
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,6 +1,29 @@
|
||||
package {{ .PackageName }}
|
||||
|
||||
// Resource is the wire representation of {{ .KindName }}. (TODO be better)
|
||||
import (
|
||||
"github.com/grafana/grafana/pkg/kinds"
|
||||
)
|
||||
|
||||
// Resource is the kubernetes style representation of {{ .KindName }}. (TODO be better)
|
||||
type K8sResource = kinds.GrafanaResource[Spec, Status]
|
||||
|
||||
// NewResource creates a new instance of the resource with a given name (UID)
|
||||
func NewK8sResource(name string, s *Spec) K8sResource {
|
||||
return K8sResource{
|
||||
Kind: "{{ .KindName }}",
|
||||
APIVersion: "v{{ .Version }}-alpha",
|
||||
Metadata: kinds.GrafanaResourceMetadata{
|
||||
Name: name,
|
||||
Annotations: make(map[string]string),
|
||||
Labels: make(map[string]string),
|
||||
},
|
||||
Spec: s,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Resource is the wire representation of {{ .KindName }}.
|
||||
// It currently will soon be merged into the k8s flavor (TODO be better)
|
||||
type Resource struct {
|
||||
{{- range .SubresourceNames }}
|
||||
{{ . }} {{ . }} `json:"{{ . | ToLower }}"`{{end}}
|
||||
|
||||
Reference in New Issue
Block a user