Documentation ¶
Index ¶
- Constants
- func BackendPluginMainGenerator(projectRepo, apiCodegenPath string, generatedKindsAreVersioned bool, ...) codejen.ManyToOne[codegen.Kind]
- func CRDGenerator(encoder CRDOutputEncoder, extension string) codejen.OneToOne[codegen.Kind]
- func CUEToCRDOpenAPI(v cue.Value, name, version string) (map[string]any, error)
- func CUEValueToOAPIYAML(val cue.Value, cfg CUEOpenAPIConfig) ([]byte, error)
- func CUEValueToOpenAPI(val cue.Value, cfg CUEOpenAPIConfig) (*ast.File, error)
- func CUEValueToString(v cue.Value) string
- func GetGeneratedPath(groupByKind bool, kind codegen.Kind, version string) string
- func GoTypesFromCUE(v cue.Value, cfg CUEGoConfig, maxNamingDepth int) ([]byte, error)
- func KindVersionToCRDSpecVersion(kv codegen.KindVersion, kindName string, stored bool) (k8s.CustomResourceDefinitionSpecVersion, error)
- func OperatorMainJenny(projectRepo, codegenPath string, generatedKindsAreVersioned bool, ...) codejen.ManyToOne[codegen.Kind]
- func RouterCodeGenerator(projectRepo string) codejen.ManyToOne[codegen.Kind]
- func RouterHandlerCodeGenerator(projectRepo, apiCodegenPath string, generatedKindsAreVersioned bool, ...) codejen.OneToOne[codegen.Kind]
- func SelEq(s1, s2 cue.Selector) bool
- func StaticManyToOneGenerator[Input any](file codejen.File) codejen.ManyToOne[Input]
- func ToPackageName(input string) string
- func TrimPathPrefix(path, prefix cue.Path) cue.Path
- func WatcherJenny(projectRepo, codegenPath string, generatedKindsAreVersioned bool, ...) codejen.OneToOne[codegen.Kind]
- type AppGenerator
- type CRDOutputEncoder
- type CUEGoConfig
- type CUEOpenAPIConfig
- type CodecGenerator
- type GoFile
- type GoTypes
- type ManifestGenerator
- type ManifestGoGenerator
- type ManifestOutputEncoder
- type OpenAPI
- type OperatorConfigJenny
- type OperatorKubeConfigJenny
- type ResourceObjectGenerator
- type SchemaGenerator
- type TypeScriptResourceTypes
- type TypeScriptTypes
Constants ¶
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 CUEToCRDOpenAPI ¶
func CUEValueToOAPIYAML ¶
func CUEValueToOAPIYAML(val cue.Value, cfg CUEOpenAPIConfig) ([]byte, error)
func CUEValueToOpenAPI ¶
CUEValueToOpenAPI converts a cue.Value into an OpenAPI ast.File
func CUEValueToString ¶
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
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 KindVersionToCRDSpecVersion ¶
func KindVersionToCRDSpecVersion(kv codegen.KindVersion, kindName string, stored bool) (k8s.CustomResourceDefinitionSpecVersion, error)
func OperatorMainJenny ¶
func RouterCodeGenerator ¶
func SelEq ¶
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 ToPackageName ¶
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.
Types ¶
type AppGenerator ¶ added in v0.23.0
type AppGenerator struct { GroupByKind bool ProjectRepo string ProjectName string CodegenPath string }
func (*AppGenerator) JennyName ¶ added in v0.23.0
func (*AppGenerator) JennyName() string
type CRDOutputEncoder ¶
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 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
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 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.
type ManifestGenerator ¶ added in v0.20.0
type ManifestGenerator struct { Encoder ManifestOutputEncoder FileExtension string AppName string }
ManifestGenerator generates a JSON/YAML App Manifest.
func (*ManifestGenerator) Generate ¶ added in v0.20.0
Generate creates one or more codec go files for the provided Kind nolint:dupl
func (*ManifestGenerator) JennyName ¶ added in v0.20.0
func (*ManifestGenerator) JennyName() string
type ManifestGoGenerator ¶ added in v0.20.0
func (*ManifestGoGenerator) JennyName ¶ added in v0.20.0
func (*ManifestGoGenerator) JennyName() string
type ManifestOutputEncoder ¶ added in v0.20.0
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.
type OperatorConfigJenny ¶
type OperatorConfigJenny struct { }
func (*OperatorConfigJenny) JennyName ¶
func (*OperatorConfigJenny) JennyName() string
type OperatorKubeConfigJenny ¶
type OperatorKubeConfigJenny struct { }
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) 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 ¶
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) 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) JennyName ¶
func (TypeScriptTypes) JennyName() string