codegen

package
v0.46.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

README

codegen

The codegen package (and its child packages) is responsible for all app-sdk code generation.

A diagram of how aspects of a kind are encapsulated

To add new codegen functionality, you will need to add a jenny in codegen/jennies, and then add that jenny to a generator function for each source type (right now, only cuekind/generators.go). If you create a new generator function, you will want to add usage of that function in the CLI in the cmd/grafana-app-sdk package.

To add a new available source type, create a package for that type and have it provide a Parser for Kind and AppManifest, as well as functions to return JennyList items for usage with the Generator type. You can reference the cuekind package as an example.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdditionalPrinterColumn added in v0.21.0

type AdditionalPrinterColumn struct {
	Name        string  `json:"name"`
	Type        string  `json:"type"`
	Format      *string `json:"format,omitempty"`
	Description *string `json:"description,omitempty"`
	Priority    *int32  `json:"priority"`
	JSONPath    string  `json:"jsonPath"`
}

type AnyKind added in v0.14.0

type AnyKind struct {
	Props       KindProperties
	AllVersions []KindVersion
}

AnyKind is a simple implementation of Kind

func (*AnyKind) Name added in v0.14.0

func (a *AnyKind) Name() string

func (*AnyKind) Properties added in v0.14.0

func (a *AnyKind) Properties() KindProperties

func (*AnyKind) Version added in v0.14.0

func (a *AnyKind) Version(v string) *KindVersion

func (*AnyKind) Versions added in v0.14.0

func (a *AnyKind) Versions() []KindVersion

type AppManifest added in v0.27.0

type AppManifest interface {
	Name() string
	Kinds() []Kind
	Versions() []Version
	Properties() AppManifestProperties
}

type AppManifestKindPermission added in v0.27.0

type AppManifestKindPermission struct {
	Group    string   `json:"group"`
	Resource string   `json:"resource"`
	Actions  []string `json:"actions"`
}

type AppManifestProperties added in v0.27.0

type AppManifestProperties struct {
	AppName          string                                `json:"appName"`
	Group            string                                `json:"group"`
	FullGroup        string                                `json:"fullGroup"`
	ExtraPermissions AppManifestPropertiesExtraPermissions `json:"extraPermissions"`
	OperatorURL      *string                               `json:"operatorURL,omitempty"`
	PreferredVersion string                                `json:"preferredVersion"`
}

type AppManifestPropertiesExtraPermissions added in v0.27.0

type AppManifestPropertiesExtraPermissions struct {
	AccessKinds []AppManifestKindPermission `json:"accessKinds,omitempty"`
}

type ConversionWebhookProperties added in v0.26.0

type ConversionWebhookProperties struct {
	URL string `json:"url"`
}

type CustomRoute added in v0.38.0

type CustomRoute struct {
	Name     string              `json:"name"`
	Request  CustomRouteRequest  `json:"request"`
	Response CustomRouteResponse `json:"response"`
}

CustomRoute represents a single custom route definition for a specific HTTP method.

type CustomRouteRequest added in v0.38.0

type CustomRouteRequest struct {
	Query cue.Value `json:"query,omitempty"`
	Body  cue.Value `json:"body,omitempty"`
}

CustomRouteRequest represents the request part of a custom route definition.

type CustomRouteResponse added in v0.38.0

type CustomRouteResponse struct {
	Schema   cue.Value                   `json:"schema,omitempty"`
	Metadata CustomRouteResponseMetadata `json:"metadata,omitempty"`
}

CustomRouteResponse represents the response part of a custom route definition.

type CustomRouteResponseMetadata added in v0.46.0

type CustomRouteResponseMetadata struct {
	TypeMeta   bool `json:"typeMeta"`
	ListMeta   bool `json:"listMeta"`
	ObjectMeta bool `json:"objectMeta"`
}

type Generator

type Generator[T any] struct {
	// contains filtered or unexported fields
}

func NewGenerator added in v0.14.0

func NewGenerator[T any](parser Parser[T], files fs.FS) (*Generator[T], error)

func (*Generator[T]) FilteredGenerate added in v0.14.0

func (g *Generator[T]) FilteredGenerate(jennies JennyList[T], filterFunc func(T) bool, selectors ...string) (codejen.Files, error)

func (*Generator[T]) Generate

func (g *Generator[T]) Generate(jennies JennyList[T], selectors ...string) (codejen.Files, error)

type JennyList added in v0.14.0

type JennyList[T any] interface {
	Generate(...T) (codejen.Files, error)
}

type Kind added in v0.14.0

type Kind interface {
	Name() string
	Properties() KindProperties
	Versions() []KindVersion
	Version(version string) *KindVersion
}

Kind is a common interface declaration for code generation. Any type parser should be able to parse a kind into this definition to supply to various common Jennies in the codegen package.

type KindAdmissionCapability added in v0.20.0

type KindAdmissionCapability struct {
	Operations []KindAdmissionCapabilityOperation `json:"operations"`
}

type KindAdmissionCapabilityOperation added in v0.20.0

type KindAdmissionCapabilityOperation string
const (
	AdmissionCapabilityOperationCreate  KindAdmissionCapabilityOperation = "CREATE"
	AdmissionCapabilityOperationUpdate  KindAdmissionCapabilityOperation = "UPDATE"
	AdmissionCapabilityOperationDelete  KindAdmissionCapabilityOperation = "DELETE"
	AdmissionCapabilityOperationConnect KindAdmissionCapabilityOperation = "CONNECT"
	AdmissionCapabilityOperationAny     KindAdmissionCapabilityOperation = "*"
)

type KindCodegenGoConfig added in v0.34.0

type KindCodegenGoConfig struct {
}

KindCodegenGoConfig is the Go configuration options for codegen, modeled after the cog Go codegen options.

type KindCodegenLanguageProperties added in v0.32.0

type KindCodegenLanguageProperties[T any] struct {
	Enabled bool `json:"enabled"`
	Config  T    `json:"config"`
}

type KindCodegenProperties added in v0.14.0

type KindCodegenProperties struct {
	TS KindCodegenLanguageProperties[KindCodegenTSConfig] `json:"ts"`
	Go KindCodegenLanguageProperties[KindCodegenGoConfig] `json:"go"`
}

KindCodegenProperties contains code generation directives for a Kind or KindVersion

type KindCodegenTSConfig added in v0.32.0

type KindCodegenTSConfig struct {
	ImportsMap        map[string]string `json:"importsMap"`
	EnumsAsUnionTypes bool              `json:"enumsAsUnionTypes"`
}

KindCodegenTSConfig is the TypeScript configuration options for codegen, modeled after the cog TS codegen options.

type KindProperties added in v0.14.0

type KindProperties struct {
	// Kind is the unique-within-the-group name of the kind
	Kind string `json:"kind"`
	// Group is the group the Kind is a part of
	Group string `json:"group"`
	// ManifestGroup is the group shortname used by the AppManifest this Kind belongs to
	ManifestGroup string `json:"manifestGroup"`
	// MachineName is the machine version of the Kind, which follows the regex: /^[a-z]+[a-z0-9]*$/
	MachineName string `json:"machineName"`
	// PluralMachineName is the plural of the MachineName
	PluralMachineName string `json:"pluralMachineName"`
	// PluralName is the plural of the Kind
	PluralName string `json:"pluralName"`
	// Current is the version string of the version considered to be "current".
	// This does not have to be the latest, but determines preference when generating code.
	Current                string                      `json:"current"`
	Scope                  string                      `json:"scope"`
	Validation             KindAdmissionCapability     `json:"validation"`
	Mutation               KindAdmissionCapability     `json:"mutation"`
	Conversion             bool                        `json:"conversion"`
	ConversionWebhookProps ConversionWebhookProperties `json:"conversionWebhookProps"`
	// Codegen contains code-generation directives for the codegen pipeline
	Codegen KindCodegenProperties `json:"codegen"`
}

KindProperties is the collection of properties for a Kind which are used for code generation

type KindVersion added in v0.14.0

type KindVersion struct {
	Version string `json:"version"`
	// Schema is the CUE schema for the version
	// This should eventually be changed to JSONSchema/OpenAPI(/AST?)
	Schema                   cue.Value                         `json:"schema"` // TODO: this should eventually be OpenAPI/JSONSchema (ast or bytes?)
	Codegen                  KindCodegenProperties             `json:"codegen"`
	Served                   bool                              `json:"served"`
	SelectableFields         []string                          `json:"selectableFields"`
	Validation               KindAdmissionCapability           `json:"validation"`
	Mutation                 KindAdmissionCapability           `json:"mutation"`
	AdditionalPrinterColumns []AdditionalPrinterColumn         `json:"additionalPrinterColumns"`
	Routes                   map[string]map[string]CustomRoute `json:"routes"`
}

type Parser added in v0.14.0

type Parser[T any] interface {
	Parse(fs.FS, ...string) ([]T, error)
}

type SimpleManifest added in v0.27.0

type SimpleManifest struct {
	Props       AppManifestProperties
	AllVersions []Version
}

func (*SimpleManifest) Kinds added in v0.27.0

func (m *SimpleManifest) Kinds() []Kind

func (*SimpleManifest) Name added in v0.27.0

func (m *SimpleManifest) Name() string

func (*SimpleManifest) Properties added in v0.27.0

func (m *SimpleManifest) Properties() AppManifestProperties

func (*SimpleManifest) Versions added in v0.40.0

func (m *SimpleManifest) Versions() []Version

type SimpleVersion added in v0.40.0

type SimpleVersion struct {
	Props        VersionProperties
	AllKinds     []VersionedKind
	CustomRoutes VersionCustomRoutes
}

func (*SimpleVersion) Kinds added in v0.40.0

func (v *SimpleVersion) Kinds() []VersionedKind

func (*SimpleVersion) Name added in v0.40.0

func (v *SimpleVersion) Name() string

func (*SimpleVersion) Properties added in v0.40.0

func (v *SimpleVersion) Properties() VersionProperties

func (*SimpleVersion) Routes added in v0.46.0

func (v *SimpleVersion) Routes() VersionCustomRoutes

type Version added in v0.40.0

type Version interface {
	Name() string
	Properties() VersionProperties
	Kinds() []VersionedKind
	Routes() VersionCustomRoutes
}

type VersionCustomRoutes added in v0.46.0

type VersionCustomRoutes struct {
	Namespaced map[string]map[string]CustomRoute `json:"namespaced"`
	Cluster    map[string]map[string]CustomRoute `json:"cluster"`
}

type VersionProperties added in v0.40.0

type VersionProperties struct {
	Name    string                `json:"name"`
	Served  bool                  `json:"served"`
	Codegen KindCodegenProperties `json:"codegen"`
}

type VersionedKind added in v0.40.0

type VersionedKind struct {
	// Kind is the unique-within-the-group name of the kind
	Kind string `json:"kind"`
	// MachineName is the machine version of the Kind, which follows the regex: /^[a-z]+[a-z0-9]*$/
	MachineName string `json:"machineName"`
	// PluralMachineName is the plural of the MachineName
	PluralMachineName string `json:"pluralMachineName"`
	// PluralName is the plural of the Kind
	PluralName             string                      `json:"pluralName"`
	Scope                  string                      `json:"scope"`
	Validation             KindAdmissionCapability     `json:"validation"`
	Mutation               KindAdmissionCapability     `json:"mutation"`
	Conversion             bool                        `json:"conversion"`
	ConversionWebhookProps ConversionWebhookProperties `json:"conversionWebhookProps"`
	// Codegen contains code-generation directives for the codegen pipeline
	Codegen                  KindCodegenProperties     `json:"codegen"`
	Served                   bool                      `json:"served"`
	SelectableFields         []string                  `json:"selectableFields"`
	AdditionalPrinterColumns []AdditionalPrinterColumn `json:"additionalPrinterColumns"`
	// Schema is the CUE schema for the version
	// This should eventually be changed to JSONSchema/OpenAPI(/AST?)
	Schema cue.Value                         `json:"schema"` // TODO: this should eventually be OpenAPI/JSONSchema (ast or bytes?)
	Routes map[string]map[string]CustomRoute `json:"routes"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL