generator

package
v0.0.0-...-b4c0e7c Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const CommentBlankLine = "" // assumes comments are joined with newlines
View Source
const KubebuilderMarkStatusSubresource = "+kubebuilder:subresource:status"
View Source
const KubebuilderObjectRoot = "+kubebuilder:object:root=true"

Variables

View Source
var InvalidMRNameEmpty error = errors.New(".Name is required")
View Source
var InvalidMRPackagePathEmpty error = errors.New(".PackagePath is required")

Functions

func AttributeStatement

func AttributeStatement(f, parent Field) *j.Statement

func AttributeTypeDeclaration

func AttributeTypeDeclaration(f Field) string

func NewManagedResourceTypeDefRenderer

func NewManagedResourceTypeDefRenderer(mr *ManagedResource, tg template.TemplateGetter) *managedResourceTypeDefRenderer

func RenderKubebuilderResourceAnnotation

func RenderKubebuilderResourceAnnotation(mr *ManagedResource) string

RenderKubebuilderResourceAnnotation renderes the kubebuilder resource tag which indicates whether the resources is namespace- or cluster-scoped and sets the categories field in the CRD which allow kubectl to select sets of resources based on matching category tags.

func TypeStatement

func TypeStatement(f Field, s *j.Statement) *j.Statement

Types

type AttributeField

type AttributeField struct {
	Type         AttributeType
	MapValueType AttributeType
}

type AttributeType

type AttributeType int
const (
	AttributeTypeUnsupported AttributeType = iota
	AttributeTypeUintptr
	AttributeTypeUint8
	AttributeTypeUint64
	AttributeTypeUint32
	AttributeTypeUint16
	AttributeTypeUint
	AttributeTypeString
	AttributeTypeRune
	AttributeTypeInt8
	AttributeTypeInt64
	AttributeTypeInt32
	AttributeTypeInt16
	AttributeTypeInt
	AttributeTypeFloat64
	AttributeTypeFloat32
	AttributeTypeComplex64
	AttributeTypeComplex128
	AttributeTypeByte
	AttributeTypeBool

	// AttributeTypeMapStringKey means that the field is a map[string]<type>
	// where <type> is defined by the value of Field.AttributeField.MapValueType
	AttributeTypeMapStringKey
)

func (AttributeType) String

func (i AttributeType) String() string

type DecodeFnGenerator

type DecodeFnGenerator interface {
	GenerateDecodeFn(funcPrefix, receivedType string, f Field) string
}

type EncodeFnGenerator

type EncodeFnGenerator interface {
	GenerateEncodeFn(funcPrefix, receivedType string, f Field) string
}

type Field

type Field struct {
	Name              string
	Type              FieldType
	Fields            []Field
	StructField       StructField
	AttributeField    AttributeField
	IsSlice           bool
	Tag               *StructTag
	EncodeFnGenerator EncodeFnGenerator
	DecodeFnGenerator DecodeFnGenerator
	MergeFnGenerator  MergeFnGenerator

	// struct comment "annotations"
	Computed  bool
	Optional  bool
	Required  bool
	Sensitive bool
}

type FieldType

type FieldType int
const (
	FieldTypeStruct FieldType = iota
	FieldTypeAttribute
)

func (FieldType) String

func (i FieldType) String() string

type Fragment

type Fragment struct {
	// contains filtered or unexported fields
}

Fragment is a simple type for grouping comments with arbitrary jen statements Jen only has nice formatting for comments in the context of a File, which is a type we are trying to avoid in order to use Jen to only render more complex fragments on the assumption that go templates will be more readable for files.

func AtProviderFragments

func AtProviderFragments(mr *ManagedResource) []*Fragment

func FieldFragments

func FieldFragments(f Field) []*Fragment

func ForProviderFragments

func ForProviderFragments(mr *ManagedResource) []*Fragment

func ResourceTypeFragment

func ResourceTypeFragment(mr *ManagedResource) *Fragment

func SpecFragment

func SpecFragment(mr *ManagedResource) *Fragment

func StatusFragment

func StatusFragment(mr *ManagedResource) *Fragment

func TypeListFragment

func TypeListFragment(mr *ManagedResource) *Fragment

func (*Fragment) FormattedComments

func (f *Fragment) FormattedComments() string

FormattedComments uses a simple rendering algo of prepending every line in the set of all comments with '//' and joining them together with '\n'

func (*Fragment) Render

func (f *Fragment) Render() string

Render concats the fragment comments with each other, and the rendered Statement, in a predictable way

type ManagedResource

type ManagedResource struct {
	Name        string
	PackagePath string
	Parameters  Field
	Observation Field

	CategoryTags []string
	// contains filtered or unexported fields
}

func NewManagedResource

func NewManagedResource(name, packagePath string) *ManagedResource

func (*ManagedResource) CategoryCSV

func (mr *ManagedResource) CategoryCSV() string

CategoryTagsCSV returns a comma separated list respresenting CategoryTags this is used in the kubebuilder resource categories comment annotation eg: +kubebuilder:resource:categories={crossplane,managed,aws}

func (*ManagedResource) Namer

func (mr *ManagedResource) Namer() ResourceNamer

func (*ManagedResource) Validate

func (mr *ManagedResource) Validate() error

Validate ensures that the ManagedResource can be rendered to code

func (*ManagedResource) WithNamer

func (mr *ManagedResource) WithNamer(n ResourceNamer) *ManagedResource

type MergeFnGenerator

type MergeFnGenerator interface {
	GenerateMergeFn(funcPrefix, receivedType string, f Field, isSpec bool) string
}

type MultiError

type MultiError interface {
	Append(error)
	Errors() []error
	Error() string
}

MultiError gives client code the ability to type assert a possible multiError into a form where the individual errors can be examined.

func NewMultiError

func NewMultiError(heading string) MultiError

NewMultiError handles initializing the errors slice and allows a heading to be set. The Error() method will print this heading before listing out the individual errors.

type NamedFields

type NamedFields []Field

NamedFields implements the sort.Sort methodset, allowing you to call sort.Sort(NamedFields) on a slice of []Field

func (NamedFields) Len

func (x NamedFields) Len() int

func (NamedFields) Less

func (x NamedFields) Less(i, j int) bool

func (NamedFields) Swap

func (x NamedFields) Swap(i, j int)

type ResourceNamer

type ResourceNamer interface {
	TypeName() string
	TypeListName() string
	SpecTypeName() string
	StatusTypeName() string
	AtProviderTypeName() string
	ForProviderTypeName() string
}

func NewDefaultNamer

func NewDefaultNamer(resourceName string) ResourceNamer

type StructField

type StructField struct {
	PackagePath string
	TypeName    string
}

type StructTag

type StructTag struct {
	Json *StructTagJson
}

type StructTagJson

type StructTagJson struct {
	Name      string
	Omitempty bool
	Inline    bool
}

Jump to

Keyboard shortcuts

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