Documentation ¶
Overview ¶
Package definition contains some helper functions used in vela CLI and vela addon mechanism
Index ¶
- Constants
- Variables
- func GenGoCodeFromParams(parameters []StructParameter) (string, error)
- func GetDefinitionDefaultSpec(kind string) map[string]interface{}
- func PrintParamGosStruct(parameters []StructParameter)
- func SearchDefinition(c client.Client, definitionType, namespace string, ...) ([]unstructured.Unstructured, error)
- func SearchDefinitionRevisions(ctx context.Context, c client.Client, namespace string, defName string, ...) ([]v1beta1.DefinitionRevision, error)
- func SplitComponents(name string) []string
- func ValidDefinitionTypes() []string
- type AbbrFieldNamer
- type Definition
- func (def *Definition) FromCUE(val *cue.Value, templateString string) error
- func (def *Definition) FromCUEString(cueString string, config *rest.Config) error
- func (def *Definition) FromYAML(data []byte) error
- func (def *Definition) GetType() string
- func (def *Definition) SetGVK(kind string)
- func (def *Definition) SetType(t string) error
- func (def *Definition) ToCUE() (*cue.Value, string, error)
- func (def *Definition) ToCUEString() (string, error)
- type Field
- type FieldNamer
- type StructParameter
Constants ¶
const ( // DescriptionKey the key for accessing definition description DescriptionKey = "definition.oam.dev/description" // AliasKey the key for accessing definition alias AliasKey = "definition.oam.dev/alias" // UserPrefix defines the prefix of user customized label or annotation UserPrefix = "custom.definition.oam.dev/" // DefinitionAlias is alias of definition DefinitionAlias = "alias.config.oam.dev" // DefinitionType marks definition's usage type, like image-registry DefinitionType = "type.config.oam.dev" // ConfigCatalog marks definition is a catalog ConfigCatalog = "catalog.config.oam.dev" )
Variables ¶
var ( // DefinitionTemplateKeys the keys for accessing definition template DefinitionTemplateKeys = []string{"spec", "schematic", "cue", "template"} // DefinitionTypeToKind maps the definition types to corresponding kinds DefinitionTypeToKind = map[string]string{ "component": v1beta1.ComponentDefinitionKind, "trait": v1beta1.TraitDefinitionKind, "policy": v1beta1.PolicyDefinitionKind, "workload": v1beta1.WorkloadDefinitionKind, "scope": v1beta1.ScopeDefinitionKind, "workflow-step": v1beta1.WorkflowStepDefinitionKind, } // StringToDefinitionType converts user input to DefinitionType used in DefinitionRevisions StringToDefinitionType = map[string]common.DefinitionType{ "component": common.ComponentType, "trait": common.TraitType, "policy": common.PolicyType, "workflow-step": common.WorkflowStepType, } // DefinitionKindToNameLabel records DefinitionRevision types and labels to search its name DefinitionKindToNameLabel = map[common.DefinitionType]string{ common.ComponentType: oam.LabelComponentDefinitionName, common.TraitType: oam.LabelTraitDefinitionName, common.PolicyType: oam.LabelPolicyDefinitionName, common.WorkflowStepType: oam.LabelWorkflowStepDefinitionName, } )
Functions ¶
func GenGoCodeFromParams ¶ added in v1.4.0
func GenGoCodeFromParams(parameters []StructParameter) (string, error)
GenGoCodeFromParams generates go code from parameters
func GetDefinitionDefaultSpec ¶
GetDefinitionDefaultSpec returns the default spec of Definition with given kind. This may be implemented with cue in the future.
func PrintParamGosStruct ¶ added in v1.4.0
func PrintParamGosStruct(parameters []StructParameter)
PrintParamGosStruct prints the StructParameter in Golang struct format
func SearchDefinition ¶
func SearchDefinition(c client.Client, definitionType, namespace string, additionalFilters ...filters.Filter) ([]unstructured.Unstructured, error)
SearchDefinition search the Definition in k8s by traversing all possible results across types or namespaces
func SearchDefinitionRevisions ¶ added in v1.5.0
func SearchDefinitionRevisions(ctx context.Context, c client.Client, namespace string, defName string, defType common.DefinitionType, rev int64) ([]v1beta1.DefinitionRevision, error)
SearchDefinitionRevisions finds DefinitionRevisions. Use defName to filter DefinitionRevisions using the name of the underlying Definition. Empty defName will keep everything. Use defType to only keep DefinitionRevisions of the specified DefinitionType. Empty defType will search every possible type. Use rev to only keep the revision you want. rev=0 will keep every revision.
func SplitComponents ¶ added in v1.4.0
SplitComponents splits name into components. name may be kebab case, snake case, or camel case.
func ValidDefinitionTypes ¶
func ValidDefinitionTypes() []string
ValidDefinitionTypes return the list of valid definition types
Types ¶
type AbbrFieldNamer ¶ added in v1.4.0
type AbbrFieldNamer struct { // Prefix is a prefix to add to all field names with first char capitalized automatically. Prefix string Abbreviations map[string]bool // contains filtered or unexported fields }
An AbbrFieldNamer generates Go field names from Go struct field while keeping abbreviations uppercased.
func (*AbbrFieldNamer) FieldName ¶ added in v1.4.0
func (a *AbbrFieldNamer) FieldName(field string) string
FieldName implements FieldNamer.FieldName.
func (*AbbrFieldNamer) SetPrefix ¶ added in v1.4.0
func (a *AbbrFieldNamer) SetPrefix(s string)
SetPrefix set a prefix to namer.
type Definition ¶
type Definition struct {
unstructured.Unstructured
}
Definition the general struct for handling all kinds of definitions like ComponentDefinition or TraitDefinition
func GetDefinitionFromDefinitionRevision ¶ added in v1.5.0
func GetDefinitionFromDefinitionRevision(rev *v1beta1.DefinitionRevision) (*Definition, error)
GetDefinitionFromDefinitionRevision will extract the underlying Definition from a DefinitionRevision.
func (*Definition) FromCUE ¶
func (def *Definition) FromCUE(val *cue.Value, templateString string) error
FromCUE converts CUE value (predefined Definition's cue format) to Definition nolint:gocyclo,staticcheck
func (*Definition) FromCUEString ¶
func (def *Definition) FromCUEString(cueString string, config *rest.Config) error
FromCUEString converts cue string into Definition
func (*Definition) FromYAML ¶ added in v1.5.0
func (def *Definition) FromYAML(data []byte) error
FromYAML converts yaml into Definition
func (*Definition) GetType ¶
func (def *Definition) GetType() string
GetType gets the type of Definition
func (*Definition) SetGVK ¶
func (def *Definition) SetGVK(kind string)
SetGVK set the GroupVersionKind of Definition
func (*Definition) SetType ¶
func (def *Definition) SetType(t string) error
SetType sets the type of Definition
func (*Definition) ToCUE ¶
func (def *Definition) ToCUE() (*cue.Value, string, error)
ToCUE converts Definition to CUE value (with predefined Definition's cue format) nolint:staticcheck
func (*Definition) ToCUEString ¶
func (def *Definition) ToCUEString() (string, error)
ToCUEString converts definition to CUE value and then encode to string
type Field ¶ added in v1.4.0
type Field struct { Name string // GoType is the same to parameter.Type but can be print in Go GoType string OmitEmpty bool }
Field is a field of a struct.
type FieldNamer ¶ added in v1.4.0
A FieldNamer generates a Go field name from a CUE label.
func NewFieldNamer ¶ added in v1.4.0
func NewFieldNamer(prefix string) FieldNamer
NewFieldNamer returns a new FieldNamer.
type StructParameter ¶ added in v1.4.0
type StructParameter struct { types.Parameter // GoType is the same to parameter.Type but can be print in Go GoType string Fields []Field }
StructParameter is a parameter that can be printed as a struct.
func GeneratorParameterStructs ¶ added in v1.4.0
func GeneratorParameterStructs(param cue.Value) ([]StructParameter, error)
GeneratorParameterStructs generates structs for parameters in cue.
func NewStructParameter ¶ added in v1.4.0
func NewStructParameter() StructParameter
NewStructParameter creates a StructParameter