Documentation
¶
Overview ¶
Package scaffold renders custom-resource wrapper packages from embedded templates.
Index ¶
- Variables
- func Generate(data TemplateData, outDir string, force bool) ([]string, error)
- func Render(data TemplateData) (map[string][]byte, error)
- type Options
- type TemplateData
- func (d TemplateData) APIVersion() string
- func (d TemplateData) IdentityArgs() string
- func (d TemplateData) IdentityFormat() string
- func (d TemplateData) LowercaseKind() string
- func (d TemplateData) PointerType() string
- func (d TemplateData) QualifiedType() string
- func (d TemplateData) Spec() VariantSpec
- type Variant
- type VariantSpec
Constants ¶
This section is empty.
Variables ¶
var GeneratedFiles = []string{"builder.go", "builder_test.go", "mutator.go", "resource.go"}
GeneratedFiles lists the files a wrapper package consists of, in write order.
var Variants = []Variant{VariantStatic, VariantWorkload, VariantTask, VariantIntegration}
Variants lists every supported variant in flag-documentation order.
Functions ¶
func Generate ¶
func Generate(data TemplateData, outDir string, force bool) ([]string, error)
Generate renders the wrapper package described by data and writes it to outDir, returning the written file paths.
The directory is created when missing. An existing directory that already contains entries is refused unless force is true, so the CLI never overwrites silently.
Types ¶
type Options ¶
type Options struct {
// Type is the wrapped Go type as "<import-path>.<TypeName>".
Type string
// Variant is the resource category name.
Variant string
// Group is the API group. An empty Group is valid for core types, so
// GroupSet records whether the flag was provided at all.
Group string
// GroupSet reports whether --group was provided.
GroupSet bool
// Version is the API version. Derived from Type when empty.
Version string
// Kind is the kind used in the identity string. Defaults to the type name.
Kind string
// Alias is the import alias for the wrapped type's package. Derived when empty.
Alias string
// Package is the generated Go package name. Defaults to the lowercased kind.
Package string
// ClusterScoped marks the wrapped kind as cluster-scoped.
ClusterScoped bool
}
Options are the raw flag values of "ocf scaffold wrapper" before validation and defaulting.
func (Options) Resolve ¶
func (o Options) Resolve() (TemplateData, error)
Resolve validates the options and derives every unset value, returning the data the templates render from.
type TemplateData ¶
type TemplateData struct {
// Package is the Go package name of the generated package.
Package string
// ImportPath is the wrapped type's import path.
ImportPath string
// ImportAlias is the alias the generated files import ImportPath under.
ImportAlias string
// TypeName is the wrapped Go type's name.
TypeName string
// Group is the API group, empty for core types.
Group string
// Version is the API version.
Version string
// Kind is the kind used in identities and documentation.
Kind string
// ClusterScoped reports whether the wrapped kind is cluster-scoped.
ClusterScoped bool
// Variant is the resource category the wrapper belongs to.
Variant Variant
}
TemplateData is the fully resolved input to the wrapper templates. Every field is validated or derived by Options.Resolve.
func (TemplateData) APIVersion ¶
func (d TemplateData) APIVersion() string
APIVersion returns "<group>/<version>", or bare "<version>" for core types.
func (TemplateData) IdentityArgs ¶
func (d TemplateData) IdentityArgs() string
IdentityArgs returns the fmt arguments matching IdentityFormat, expressed against the identity function's parameter named o.
func (TemplateData) IdentityFormat ¶
func (d TemplateData) IdentityFormat() string
IdentityFormat returns the fmt format string for the resource identity, following the framework convention "<apiVersion>/<Kind>/<namespace>/<name>" and omitting the namespace segment for cluster-scoped kinds.
func (TemplateData) LowercaseKind ¶ added in v0.20.0
func (d TemplateData) LowercaseKind() string
LowercaseKind returns the kind in lower case, which is the value the framework uses for a resource's `resource` metric label when the wrapper's builder is not given an explicit metrics identifier.
func (TemplateData) PointerType ¶
func (d TemplateData) PointerType() string
PointerType returns a pointer to the wrapped type qualified by its import alias.
func (TemplateData) QualifiedType ¶
func (d TemplateData) QualifiedType() string
QualifiedType returns the wrapped type qualified by its import alias.
func (TemplateData) Spec ¶
func (d TemplateData) Spec() VariantSpec
Spec returns the generic-layer wiring for the data's variant.
type Variant ¶
type Variant string
Variant identifies which resource category a generated wrapper belongs to.
const ( // VariantStatic is a configuration object with no runtime health semantics. VariantStatic Variant = "static" // VariantWorkload is a long-running process with replica-based health. VariantWorkload Variant = "workload" // VariantTask is a run-to-completion workload. VariantTask Variant = "task" // VariantIntegration is an external-dependency object such as a Service or Ingress. VariantIntegration Variant = "integration" )
The four resource categories the framework defines.
func (Variant) Spec ¶
func (v Variant) Spec() VariantSpec
Spec returns the generic-layer wiring for the variant. The zero VariantSpec is returned for an unknown variant; Options.Resolve rejects those before rendering.
type VariantSpec ¶
type VariantSpec struct {
// GenericBuilder is the pkg/generic builder type, for example "WorkloadBuilder".
GenericBuilder string
// GenericConstructor is the pkg/generic builder constructor, for example "NewWorkloadBuilder".
GenericConstructor string
// GenericResource is the pkg/generic resource type, for example "WorkloadResource".
GenericResource string
// HasStatus reports whether the variant has a required status handler.
HasStatus bool
// StatusSetter is the builder method registering the status handler.
StatusSetter string
// StatusMethod is the resource method forwarding the status, always
// convergingStatusMethod.
StatusMethod string
// StatusResult is the qualified status result type.
StatusResult string
// StatusHandler is the generated default handler's name.
StatusHandler string
// StatusConstant is the qualified healthy status constant the default reports.
StatusConstant string
// StatusValue is the runtime string value of StatusConstant.
StatusValue string
// StatusNoun names the state the handler reports on, used in GoDoc.
StatusNoun string
// HasGrace reports whether the variant supports a grace status handler.
HasGrace bool
// HasSuspension reports whether the variant supports suspension handlers.
HasSuspension bool
// LifecycleInterfaces are the variant-specific bullets of the generated
// Resource's "It implements the following component interfaces" list, each
// rendered as "<interface>: <what it is for>." after the component.Resource
// bullet and before the ones every variant shares.
LifecycleInterfaces []string
}
VariantSpec describes how a variant wires into pkg/generic. Templates read it instead of branching on the variant name.