jennies

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const GoTypesMaxDepth = 5

Variables

This section is empty.

Functions

func BackendPluginMainGenerator

func BackendPluginMainGenerator(projectRepo, apiCodegenPath string, generatedKindsAreVersioned bool, groupByKind bool) codejen.ManyToOne[codegen.Kind]

BackendPluginMainGenerator returns a many-to-one jenny which generates the `main.go` file needed to run the backend plugin.

func CRDGenerator

func CRDGenerator(encoder CRDOutputEncoder, extension string) codejen.OneToOne[codegen.Kind]

func CUEToCRDOpenAPI

func CUEToCRDOpenAPI(v cue.Value, name, version string) (map[string]any, error)

func CUEValueToOAPIYAML

func CUEValueToOAPIYAML(val cue.Value, cfg CUEOpenAPIConfig) ([]byte, error)

func CUEValueToOpenAPI

func CUEValueToOpenAPI(val cue.Value, cfg CUEOpenAPIConfig) (*ast.File, error)

CUEValueToOpenAPI converts a cue.Value into an OpenAPI ast.File

func CUEValueToString

func CUEValueToString(v cue.Value) string

CUEValueToString returns a formatted string output of a cue.Value. This is a more detailed string than using fmt.Println(v), as it will include optional fields and definitions.

func GetGeneratedPath added in v0.16.0

func GetGeneratedPath(groupByKind bool, kind codegen.Kind, version string) string

GetGeneratedPath returns the correct codegen path based on the kind, version, and whether or not the generated code should be grouped by kind or by GroupVersion. When groupByKind is true, the path will be <kind>/<version>. When groupByKind is false, the path will be <group>/<version>.

func GoTypesFromCUE

func GoTypesFromCUE(v cue.Value, cfg CUEGoConfig, maxNamingDepth int) ([]byte, error)

func KindVersionToCRDSpecVersion

func KindVersionToCRDSpecVersion(kv codegen.KindVersion, kindName string, stored bool) (k8s.CustomResourceDefinitionSpecVersion, error)

func OperatorMainJenny

func OperatorMainJenny(projectRepo, codegenPath string, generatedKindsAreVersioned bool, groupByKind bool) codejen.ManyToOne[codegen.Kind]

func RouterCodeGenerator

func RouterCodeGenerator(projectRepo string) codejen.ManyToOne[codegen.Kind]

func RouterHandlerCodeGenerator

func RouterHandlerCodeGenerator(projectRepo, apiCodegenPath string, generatedKindsAreVersioned bool, groupByKind bool) codejen.OneToOne[codegen.Kind]

func SelEq

func SelEq(s1, s2 cue.Selector) bool

SelEq indicates whether two selectors are equivalent. Selectors are equivalent if they are either exactly equal, or if they are equal ignoring path optionality.

func StaticManyToOneGenerator

func StaticManyToOneGenerator[Input any](file codejen.File) codejen.ManyToOne[Input]

func ToPackageName

func ToPackageName(input string) string

ToPackageName sanitizes an input into a deterministic allowed go package name. It is used to turn kind names or versions into package names when performing go code generation.

func TrimPathPrefix

func TrimPathPrefix(path, prefix cue.Path) cue.Path

func WatcherJenny

func WatcherJenny(projectRepo, codegenPath string, generatedKindsAreVersioned bool, groupByKind bool) codejen.OneToOne[codegen.Kind]

Types

type CRDOutputEncoder

type CRDOutputEncoder func(any) ([]byte, error)

CRDOutputEncoder is a function which marshals an object into a desired output format

type CUEGoConfig

type CUEGoConfig struct {
	PackageName             string
	Name                    string
	Version                 string
	IgnoreDiscoveredImports bool

	// ApplyFuncs is a slice of AST manipulation funcs that will be executed against
	// the generated Go file prior to running it through goimports. For each slice
	// element, [dstutil.Apply] is called with the element as the "pre" parameter.
	ApplyFuncs []dstutil.ApplyFunc

	// UseGoDeclInComments sets the name of the fields and structs at the beginning of each comment.
	UseGoDeclInComments bool

	// NamePrefix prefixes all generated types with the provided NamePrefix
	NamePrefix string
}

type CUEOpenAPIConfig

type CUEOpenAPIConfig struct {
	Name             string
	Version          string
	ExpandReferences bool
	NameFunc         func(cue.Value, cue.Path) string
}

type CodecGenerator added in v0.15.0

type CodecGenerator struct {
	// This flag exists for compatibility with thema codegen, which only generates code for the current/latest version of the kind
	OnlyUseCurrentVersion bool

	// GroupByKind determines whether kinds are grouped by GroupVersionKind or just GroupVersion.
	// If GroupByKind is true, generated paths are <kind>/<version>/<file>, instead of the default <version>/<file>.
	// When GroupByKind is false, the generated Codec type names are prefixed with the kind name,
	// i.e. FooJSONCodec for kind.Name()="Foo"
	GroupByKind bool
}

func (*CodecGenerator) Generate added in v0.15.0

func (c *CodecGenerator) Generate(kind codegen.Kind) (codejen.Files, error)

Generate creates one or more codec go files for the provided Kind nolint:dupl

func (*CodecGenerator) JennyName added in v0.15.0

func (*CodecGenerator) JennyName() string

type GoFile added in v0.16.0

type GoFile struct {
	FS     *codejen.FS
	Source codejen.NamedJenny
}

func (*GoFile) AssembleFile added in v0.16.0

func (g *GoFile) AssembleFile(f *generator.File, _ string) error

type GoTypes

type GoTypes struct {
	// GenerateOnlyCurrent should be set to true if you only want to generate code for the kind.Properties().Current version.
	// This will affect the package and path(s) of the generated file(s).
	GenerateOnlyCurrent bool

	// Depth represents the tree depth for creating go types from fields. A Depth of 0 will return one go type
	// (plus any definitions used by that type), a Depth of 1 will return a file with a go type for each top-level field
	// (plus any definitions encompassed by each type), etc. Note that types are _not_ generated for fields above the Depth
	// level--i.e. a Depth of 1 will generate go types for each field within the KindVersion.Schema, but not a type for the
	// Schema itself. Because Depth results in recursive calls, the highest value is bound to a max of GoTypesMaxDepth.
	Depth int

	// NamingDepth determines how types are named in relation to Depth. If Depth <= NamingDepth, the go types are named
	// using the field name of the type. Otherwise, Names used are prefixed by field names between Depth and NamingDepth.
	// Typically, a value of 0 is "safest" for NamingDepth, as it prevents overlapping names for types.
	// However, if you know that your fields have unique names up to a certain depth, you may configure this to be higher.
	NamingDepth int

	// AddKubernetesCodegen toggles whether kubernetes codegen comments are added to the go types generated by this jenny.
	// The codegen comments can then be used with the OpenAPI jenny, or with the kubernetes codegen tooling.
	AddKubernetesCodegen bool

	// GroupByKind determines whether kinds are grouped by GroupVersionKind or just GroupVersion.
	// If GroupByKind is true, generated paths are <kind>/<version>/<file>, instead of the default <version>/<file>.
	// When GroupByKind is false, subresource types (such as spec and status) are prefixed with the kind name,
	// i.e. generating FooSpec instead of Spec for kind.Name() = "Foo" and Depth=1
	GroupByKind bool
}

GoTypes is a Jenny for turning a codegen.Kind into go types according to its codegen settings.

func (*GoTypes) Generate

func (g *GoTypes) Generate(kind codegen.Kind) (codejen.Files, error)

func (*GoTypes) JennyName

func (*GoTypes) JennyName() string

type OpenAPI added in v0.16.0

type OpenAPI struct {
	// GenerateOnlyCurrent should be set to true if you only want to generate code for the kind.Properties().Current version.
	// This will affect the package and path(s) of the generated file(s).
	GenerateOnlyCurrent bool

	GoModName string
	GoGenPath string

	// GroupByKind determines whether kinds are grouped by GroupVersionKind or just GroupVersion.
	// If GroupByKind is true, generated paths are <kind>/<version>/<file>, instead of the default <version>/<file>.
	// When GroupByKind is false, only one generated OpenAPI file will exist for the entire GroupVersion.
	GroupByKind bool
}

OpenAPI jenny uses kube-openapi to build OpenAPI spec. Because k8s.io/gengo doesn't allow you to use in-memory files (as the Overlay in the config is not accessible), this jenny must be run _after_ the go type has been written to disk.

func (*OpenAPI) Generate added in v0.16.0

func (o *OpenAPI) Generate(kinds ...codegen.Kind) (codejen.Files, error)

func (*OpenAPI) JennyName added in v0.16.0

func (*OpenAPI) JennyName() string

type OperatorConfigJenny

type OperatorConfigJenny struct {
}

func (*OperatorConfigJenny) Generate

func (o *OperatorConfigJenny) Generate(_ ...codegen.Kind) (*codejen.File, error)

func (*OperatorConfigJenny) JennyName

func (*OperatorConfigJenny) JennyName() string

type OperatorKubeConfigJenny

type OperatorKubeConfigJenny struct {
}

func (*OperatorKubeConfigJenny) Generate

func (o *OperatorKubeConfigJenny) Generate(_ ...codegen.Kind) (*codejen.File, error)

func (*OperatorKubeConfigJenny) JennyName

func (*OperatorKubeConfigJenny) JennyName() string

type ResourceObjectGenerator

type ResourceObjectGenerator struct {
	// This flag exists for compatibility with thema codegen, which only generates code for the current/latest version of the kind
	OnlyUseCurrentVersion bool

	// SubresourceTypesArePrefixed should be set to true if the subresource go types (such as spec or status)
	// are prefixed with the exported Kind name. Generally, if you generated go types with Depth: 1 and PrefixWithKindName: true,
	// then you should set this value to true as well.
	SubresourceTypesArePrefixed bool

	// GroupByKind determines whether kinds are grouped by GroupVersionKind or just GroupVersion.
	// If GroupByKind is true, generated paths are <kind>/<version>/<file>, instead of the default <version>/<file>.
	// When GroupByKind is false, subresource types (such as spec and status) are assumed to be prefixed with the
	// kind name, which can be accomplished by setting GroupByKind=false on the GoTypesGenerator.
	GroupByKind bool
}

func (*ResourceObjectGenerator) Generate

func (r *ResourceObjectGenerator) Generate(kind codegen.Kind) (codejen.Files, error)

func (*ResourceObjectGenerator) JennyName

func (*ResourceObjectGenerator) JennyName() string

type SchemaGenerator

type SchemaGenerator struct {
	// This flag exists for compatibility with thema codegen, which only generates code for the current/latest version of the kind
	OnlyUseCurrentVersion bool

	// GroupByKind determines whether kinds are grouped by GroupVersionKind or just GroupVersion.
	// If GroupByKind is true, generated paths are <kind>/<version>/<file>, instead of the default <version>/<file>.
	// When GroupByKind is false, the Kind() and Schema() functions are prefixed with the kind name,
	// i.e. FooKind() and FooSchema() for kind.Name()="Foo"
	GroupByKind bool
}

func (*SchemaGenerator) Generate

func (s *SchemaGenerator) Generate(kind codegen.Kind) (codejen.Files, error)

Generate creates one or more schema go files for the provided Kind nolint:dupl

func (*SchemaGenerator) JennyName

func (*SchemaGenerator) JennyName() string

type TypeScriptResourceTypes added in v0.15.0

type TypeScriptResourceTypes struct {
	GenerateOnlyCurrent bool
}

func (*TypeScriptResourceTypes) Generate added in v0.15.0

func (t *TypeScriptResourceTypes) Generate(kind codegen.Kind) (codejen.Files, error)

func (*TypeScriptResourceTypes) JennyName added in v0.15.0

func (*TypeScriptResourceTypes) JennyName() string

type TypeScriptTypes

type TypeScriptTypes struct {
	// GenerateOnlyCurrent should be set to true if you only want to generate code for the kind.Properties().Current version.
	// This will affect the package and path(s) of the generated file(s).
	GenerateOnlyCurrent bool

	// Depth represents the tree depth for creating go types from fields. A Depth of 0 will return one go type
	// (plus any definitions used by that type), a Depth of 1 will return a file with a go type for each top-level field
	// (plus any definitions encompassed by each type), etc. Note that types are _not_ generated for fields above the Depth
	// level--i.e. a Depth of 1 will generate go types for each field within the KindVersion.Schema, but not a type for the
	// Schema itself. Because Depth results in recursive calls, the highest value is bound to a max of GoTypesMaxDepth.
	Depth int

	// NamingDepth determines how types are named in relation to Depth. If Depth <= NamingDepth, the go types are named
	// using the field name of the type. Otherwise, Names used are prefixed by field names between Depth and NamingDepth.
	// Typically, a value of 0 is "safest" for NamingDepth, as it prevents overlapping names for types.
	// However, if you know that your fields have unique names up to a certain depth, you may configure this to be higher.
	NamingDepth int
}

TypeScriptTypes is a one-to-many jenny that generates one or more TypeScript types for a kind. Each type is a specific version of the kind where codegen.frontend is true. If GenerateOnlyCurrent is true, then all other versions of the kind will be ignored and only the kind.Propertoes().Current version will be used for TypeScript type generation (this will impact the generated file path).

func (TypeScriptTypes) Generate

func (j TypeScriptTypes) Generate(kind codegen.Kind) (codejen.Files, error)

func (TypeScriptTypes) JennyName

func (TypeScriptTypes) JennyName() string

Jump to

Keyboard shortcuts

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