appfile

package
v1.12.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 73 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// WriteConnectionSecretToRefKey is used to create a secret for cloud resource connection
	WriteConnectionSecretToRefKey = "writeConnectionSecretToRef"
	// RegionKey is the region of a Cloud Provider
	// It's used to override the region of a Cloud Provider
	// Refer to https://github.com/oam-dev/terraform-controller/blob/master/api/v1beta2/configuration_types.go#L66 for details
	RegionKey = "customRegion"
	// ProviderRefKey is the reference of a Provider
	ProviderRefKey = "providerRef"
	// ForceDeleteKey is used to force delete Configuration
	ForceDeleteKey = "forceDelete"
	// GitCredentialsSecretReferenceKey is the reference to a secret with git ssh private key & known hosts
	GitCredentialsSecretReferenceKey = "gitCredentialsSecretReference"
)
View Source
const (
	// UsageTag is usage comment annotation
	UsageTag = "+usage="
	// ShortTag is the short alias annotation
	ShortTag = "+short"
	// ImmutableTag marks a parameter field as immutable
	ImmutableTag = "+immutable"
)
View Source
const MaxInheritanceDepth = 8

MaxInheritanceDepth caps how far a chain of `extends` may run. A backstop rather than a cost control: rendering stays linear in the depth, but a definition assembled from more places than this is not one anybody can reason about.

Variables

View Source
var ErrNoDefinition = errors.New("no definition found")

ErrNoDefinition is wrapped by the error ResolveModuleType returns when no definition matches. It lets a caller tell a confirmed absence apart from a failed lookup: the webhook's abstract check may wave the first through, since a type that does not exist is not abstract, but must not take the second as permission.

Functions

func ComponentAncestors

func ComponentAncestors(ctx context.Context, cli client.Client, cd *v1beta1.ComponentDefinition) ([]inherit.Level, error)

ComponentAncestors resolves what a ComponentDefinition extends, for a caller wanting the chain rather than a Template. Admission uses it, so a broken chain is refused when the definition is written.

func ConvertTemplateJSON2Object added in v1.0.3

func ConvertTemplateJSON2Object(capabilityName string, in *runtime.RawExtension, schematic *common.Schematic) (types.Capability, error)

ConvertTemplateJSON2Object convert spec.extension or spec.schematic to object

func DefinitionExists

func DefinitionExists(ctx context.Context, cli client.Reader, name string, capType types.CapType) error

DefinitionExists verifies that the resolved definition name exists in the app namespace or vela-system. Used by the webhook to catch Form 3 references where resolution is pure string math and does not touch the cluster.

func FilteredAnnotationKeys added in v1.11.1

func FilteredAnnotationKeys(appAnnotations map[string]string) []string

FilteredAnnotationKeys returns the annotation keys an Application with appAnnotations does not pass down to the resources it renders: the defaults in types.DefaultFilterAnnots and those listed in filter.oam.dev/annotation-keys.

func FilteredLabelKeys added in v1.11.1

func FilteredLabelKeys(appAnnotations map[string]string) []string

FilteredLabelKeys returns the label keys an Application with appAnnotations does not pass down to the resources it renders (filter.oam.dev/label-keys).

func GenerateContextDataFromAppFile added in v1.2.5

func GenerateContextDataFromAppFile(appfile *Appfile, wlName string) velaprocess.ContextData

GenerateContextDataFromAppFile generates process context data from app file

func HasComponentParamsSuppliedAtRuntime

func HasComponentParamsSuppliedAtRuntime(app *Appfile, componentName string) bool

HasComponentParamsSuppliedAtRuntime reports whether the named component takes runtime-only parameter input directly, through an apply-component workflow step, or through an override policy. The component-local check avoids suppressing health failures for unrelated components.

func HasParamsSuppliedAtRuntime

func HasParamsSuppliedAtRuntime(app *Appfile) bool

HasParamsSuppliedAtRuntime reports whether any component parameter of this Application is filled in at runtime rather than written in the spec. Such a component cannot be rendered outside the workflow that supplies the value, so a caller that renders components on its own has to expect an incomplete parameter and cannot read that failure as a fault of the component.

func IsBuiltinPolicyType

func IsBuiltinPolicyType(policyType string) bool

IsBuiltinPolicyType reports a policy KubeVela consumes rather than renders.

Such a policy has no render, so its properties are substituted while the appfile is built, from what the Appfile carries - and it can never read a source, because there is no resolver on that path.

func IsNotFoundInAppFile added in v1.8.0

func IsNotFoundInAppFile(err error) bool

IsNotFoundInAppFile check if the target error is `not found in appfile`

func IsNotFoundInAppRevision added in v1.8.0

func IsNotFoundInAppRevision(err error) bool

IsNotFoundInAppRevision check if the error is `not found in app revision`

func NewBasicContext added in v1.0.5

func NewBasicContext(contextData velaprocess.ContextData, params map[string]interface{}) process.Context

NewBasicContext prepares a basic DSL process Context

func PolicyContextSchema

func PolicyContextSchema(policyType string, appScoped bool) propexpr.ContextSchema

PolicyContextSchema is the context a policy is evaluated against.

Paired with PolicySurface for the same reason: the surface and the schema describe one call site, and picking them independently is how they came to disagree before.

func PolicySurface

func PolicySurface(policyType string, appScoped bool) string

PolicySurface names the surface a policy's property expressions live on.

There are three kinds, not two, and the middle one is easy to miss: an Application-scoped PolicyDefinition is not built-in, but it does not render through the workload engine either. Classifying it as rendered skips the parse-time substitution it depends on, and its expressions reach the scoped render as literal text - which is exactly what happened, and what the e2e spec for scoped policies caught.

appScoped cannot be derived from the type alone: it is spec.scope on the PolicyDefinition, so every caller must look it up. Built-in types never have a definition, so they are settled before the question arises.

Five places need this answer - the parser's surface check and substitution pass, and admission's three - and they must all give the same one, or a policy is accepted by admission and refused by the parser.

func PrepareProcessContext added in v0.3.1

func PrepareProcessContext(comp *Component, ctxData velaprocess.ContextData) (process.Context, error)

PrepareProcessContext prepares a DSL process Context

func ReadsPolicyContext

func ReadsPolicyContext(af *Appfile) bool

ReadsPolicyContext reports whether a template of any component, its ancestors or its traits reads a key of context.custom: if none does, there is nothing to judge against the policies' schemas.

func ResolveModuleType

func ResolveModuleType(ctx context.Context, cli client.Reader, typeName string, capType types.CapType) (string, error)

ResolveModuleType translates a KEP-2.20 Form 1/3 type string to the installed Kubernetes definition name. Form 1 names that already exist as legacy definitions are returned unchanged so the existing GetCapabilityDefinition path handles them as before.

func TraitAncestors

func TraitAncestors(ctx context.Context, cli client.Client, td *v1beta1.TraitDefinition) ([]inherit.Level, error)

TraitAncestors is ComponentAncestors for a TraitDefinition.

func ValidateComponentReads

func ValidateComponentReads(spec v1beta1.ApplicationSpec) error

ValidateComponentReads checks every component read in an Application against what a render can honour.

A read names a component in the same Application other than the reader, and either its workload output or a named trait resource, those being what a component's output view holds. A placement is named straight after the component, with literal arguments. Reads, dependsOn and explicit inputs together must not form a cycle, which would leave every component in it waiting on another; a read naming a placement counts too, as its reader waits on it just the same.

func ValidateDependencyCycles

func ValidateDependencyCycles(spec v1beta1.ApplicationSpec) error

ValidateDependencyCycles checks the waiting an Application declares outright, dependsOn and an input naming another component's output, for a cycle.

Runs whatever the expressions opt-in says, because this waiting is declared in the spec and is not an expression. ValidateComponentReads adds read edges to the same graph where expressions are on.

func WorkflowContextData

func WorkflowContextData(goCtx context.Context, app *v1beta1.Application, appRev string) velaprocess.ContextData

WorkflowContextData builds the process context for workflow (non-component) execution: what a workflow step's template sees as its context, before the engine adds the step it is running. The goCtx parameter should contain any policy additionalContext stored by ApplyApplicationScopeTransforms.

Types

type Appfile added in v0.3.1

type Appfile struct {
	Name             string
	Namespace        string
	ParsedComponents []*Component
	ParsedPolicies   []*Component

	AppRevision     *v1beta1.ApplicationRevision
	AppRevisionName string
	AppRevisionHash string

	AppLabels      map[string]string
	AppAnnotations map[string]string

	RelatedTraitDefinitions        map[string]*v1beta1.TraitDefinition
	RelatedComponentDefinitions    map[string]*v1beta1.ComponentDefinition
	RelatedWorkflowStepDefinitions map[string]*v1beta1.WorkflowStepDefinition
	RelatedSourceDefinitions       map[string]*v1beta1.SourceDefinition

	Policies   []v1beta1.AppPolicy
	Sources    []v1beta1.ApplicationSource
	Components []common.ApplicationComponent
	// Dependencies is what each component depends on, taken once from the
	// components as parsed: status reports it, and the workflow orders by the
	// entries of it that order (sources.Orders).
	Dependencies  []common.ComponentDependency
	Artifacts     []*types.ComponentManifest
	WorkflowSteps []wfTypesv1alpha1.WorkflowStep
	WorkflowMode  *wfTypesv1alpha1.WorkflowExecuteMode

	ExternalPolicies map[string]*v1alpha1.Policy
	ExternalWorkflow *wfTypesv1alpha1.Workflow
	ReferredObjects  []*unstructured.Unstructured

	// Context is the reconciliation context for the current Application, populated during
	// controller reconcile and carried into rendering
	Context context.Context
	// KubeClient is used by runtime resolvers that need API access during rendering.
	KubeClient client.Client
	// SourceCacheStore provides source cache persistence backing for rendering.
	SourceCacheStore velaprocess.SourceCacheStore

	// PolicyContext is context.custom as the policies that apply will supply
	// it, set by admission to validate components against. Nil validates as
	// though nothing were known of it.
	PolicyContext *ctxschema.View

	Debug bool
	// contains filtered or unexported fields
}

Appfile describes application

func (*Appfile) ComponentsWithReadDependencies

func (af *Appfile) ComponentsWithReadDependencies(components []common.ApplicationComponent) []common.ApplicationComponent

ComponentsWithReadDependencies returns a copy of one deploy step's components in which each dependsOn the components of this step it reads beside itself, so that the step applies it in a placement once its producer is healthy there. A producer this step does not deploy gives no edge.

func (*Appfile) GenerateComponentManifest added in v1.1.0

func (af *Appfile) GenerateComponentManifest(comp *Component, mutate func(*velaprocess.ContextData)) (*types.ComponentManifest, error)

GenerateComponentManifest generate only one ComponentManifest

func (*Appfile) GenerateComponentManifests added in v1.1.0

func (af *Appfile) GenerateComponentManifests() ([]*types.ComponentManifest, error)

GenerateComponentManifests converts an appFile to a slice of ComponentManifest

func (*Appfile) GeneratePolicyManifests added in v1.3.0

func (af *Appfile) GeneratePolicyManifests(ctx context.Context, cli client.Client) ([]*unstructured.Unstructured, error)

GeneratePolicyManifests generates policy manifests from an appFile internal policies like apply-once, topology, will not render manifests

func (*Appfile) LoadDynamicComponent added in v1.4.0

func (af *Appfile) LoadDynamicComponent(ctx context.Context, cli client.Client, comp *common.ApplicationComponent) (*common.ApplicationComponent, error)

LoadDynamicComponent for ref-objects typed components, this function will load referred objects from stored revisions

func (*Appfile) PolicyClient added in v1.3.0

func (af *Appfile) PolicyClient(cli client.Client) client.Client

PolicyClient cache retrieved policy if ApplicationRevision not exists in appfile else use the policy in ApplicationRevision

func (*Appfile) RenderPolicy

func (af *Appfile) RenderPolicy(workload *Component) (*RenderedPolicy, error)

RenderPolicy renders a policy's template as it is dispatched.

func (*Appfile) SetOAMContract added in v1.1.1

func (af *Appfile) SetOAMContract(comp *types.ComponentManifest) error

SetOAMContract will set OAM labels and annotations for resources as contract

func (*Appfile) StepReadDependencies

func (af *Appfile) StepReadDependencies(steps []workflowv1alpha1.WorkflowStep) map[string][]string

StepReadDependencies is, by step name, the steps each step waits on because a component it applies reads theirs: the edges StepsWithReadDependencies adds, and the earlier steps a workflow run in order puts first without one. A written dependsOn is the spec's, not a read's, and is not included.

func (*Appfile) StepsWithReadDependencies

func (af *Appfile) StepsWithReadDependencies(steps []workflowv1alpha1.WorkflowStep) []workflowv1alpha1.WorkflowStep

StepsWithReadDependencies returns a copy of the workflow's steps in which an apply-component step dependsOn the step named after each component its component reads beside itself, as that component's own dependsOn would.

The edge is left out when no step has that name, when it would close a cycle, and in a workflow run in order, where an earlier step finishes first anyway and a later one could never be read in time. A dependsOn there would only change when the reader is skipped: with one, a failure of another earlier step no longer skips it.

func (*Appfile) WorkflowClient added in v1.3.0

func (af *Appfile) WorkflowClient(cli client.Client) client.Client

type Component added in v1.9.6

type Component struct {
	Name               string
	Type               string
	CapabilityCategory types.CapabilityCategory
	Params             map[string]interface{}
	Traits             []*Trait
	FullTemplate       *Template
	Ctx                process.Context
	Patch              *cue.Value

	SkipApplyWorkload bool
	// contains filtered or unexported fields
}

Component is an internal struct for component in application User-defined policies are parsed as a Component without any Traits because their purpose is dispatching some resources Internal policies are NOT parsed as a Component

func (*Component) EvalContext added in v1.9.6

func (comp *Component) EvalContext(ctx process.Context) error

EvalContext eval workload template and set the result to context

func (*Component) EvalStatus added in v1.9.6

func (comp *Component) EvalStatus(templateContext map[string]interface{}) (*health.StatusResult, error)

EvalStatus eval workload status

func (*Component) GetTemplateContext added in v1.9.6

func (comp *Component) GetTemplateContext(ctx process.Context, client client.Client, accessor util.NamespaceAccessor) (map[string]interface{}, error)

GetTemplateContext get workload template context, it will be used to eval status and health

type Parser added in v0.3.1

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

Parser is an application parser

func NewApplicationParser added in v0.3.1

func NewApplicationParser(cli client.Client) *Parser

NewApplicationParser create appfile parser

func NewDryRunApplicationParser added in v1.0.3

func NewDryRunApplicationParser(cli client.Client, defs []*unstructured.Unstructured) *Parser

NewDryRunApplicationParser create an appfile parser for DryRun

func (*Parser) GenerateAppFile added in v0.3.1

func (p *Parser) GenerateAppFile(ctx context.Context, app *v1beta1.Application) (*Appfile, error)

GenerateAppFile generate appfile for the application to run, if the application is controlled by PublishVersion, the application revision will be used to create the appfile

func (*Parser) GenerateAppFileFromApp added in v1.3.0

func (p *Parser) GenerateAppFileFromApp(ctx context.Context, app *v1beta1.Application) (*Appfile, error)

GenerateAppFileFromApp converts an application to an Appfile

func (*Parser) GenerateAppFileFromRevision added in v1.1.1

func (p *Parser) GenerateAppFileFromRevision(appRev *v1beta1.ApplicationRevision) (*Appfile, error)

GenerateAppFileFromRevision converts an application revision to an Appfile

func (*Parser) ParseComponentFromRevision added in v1.9.6

func (p *Parser) ParseComponentFromRevision(comp common.ApplicationComponent, appRev *v1beta1.ApplicationRevision) (*Component, error)

ParseComponentFromRevision resolve an ApplicationComponent and generate a Component containing ALL information required by an Appfile from app revision.

func (*Parser) ParseComponentFromRevisionAndClient added in v1.9.6

func (p *Parser) ParseComponentFromRevisionAndClient(ctx context.Context, c common.ApplicationComponent, appRev *v1beta1.ApplicationRevision) (*Component, error)

ParseComponentFromRevisionAndClient resolve an ApplicationComponent and generate a Component containing ALL information required by an Appfile from app revision, and will fall back to load external definitions if not found

func (*Parser) ValidateCUESchematicAppfile added in v1.0.3

func (p *Parser) ValidateCUESchematicAppfile(ctx context.Context, a *Appfile) error

ValidateCUESchematicAppfile validates CUE schematic workloads in an Appfile

func (*Parser) ValidateComponentNames added in v1.1.0

func (p *Parser) ValidateComponentNames(app *v1beta1.Application) (int, error)

ValidateComponentNames validate all component names whether repeat in app

func (*Parser) ValidateComponentParams added in v1.10.3

func (p *Parser) ValidateComponentParams(ctxData velaprocess.ContextData, wl *Component, app *Appfile) error

ValidateComponentParams performs CUE‑level validation for a Component’s parameters and emits helpful, context‑rich errors.

Flow

  1. Assemble a synthetic CUE document (template + params + app context).
  2. Compile it; if compilation fails, return the compiler error.
  3. When the EnableCueValidation gate is on, ensure *all* non‑optional, non‑defaulted parameters are provided—either in the Component.Params block or as workflow‑step inputs.
  4. Run cue.Value.Validate to enforce user‑supplied values against template constraints.

type RenderedPolicy

type RenderedPolicy struct {
	// Output and Outputs, by name, are defaulted to the policy's name and the
	// Application's namespace, and labelled as the Application's.
	Output  *unstructured.Unstructured
	Outputs map[string]*unstructured.Unstructured
	// Context is what the template rendered against.
	Context process.Context
	// contains filtered or unexported fields
}

RenderedPolicy is a workload-bearing policy rendered as it is dispatched.

type Template added in v1.0.3

type Template struct {
	TemplateStr        string
	Health             string
	CustomStatus       string
	Details            string
	CapabilityCategory types.CapabilityCategory
	Reference          common.WorkloadTypeDescriptor
	Terraform          *common.Terraform

	ComponentDefinition *v1beta1.ComponentDefinition
	WorkloadDefinition  *v1beta1.WorkloadDefinition
	TraitDefinition     *v1beta1.TraitDefinition

	PolicyDefinition       *v1beta1.PolicyDefinition
	WorkflowStepDefinition *v1beta1.WorkflowStepDefinition
	SourceDefinition       *v1beta1.SourceDefinition

	// Ancestors are the definitions this one extends, nearest parent first, in
	// the form the render engine wants them.
	Ancestors []inherit.Level
	// AncestorComponentDefinitions and AncestorTraitDefinitions are those same
	// ancestors as objects, keyed by the name the extending definition wrote.
	//
	// They are carried so the ApplicationRevision can record them: a render that
	// went through a chain is only reproducible if every level it went through is
	// written down beside it. Keying by the written name keeps
	// `extends: webservice@v3` and a sibling component on plain `webservice` from
	// fighting over one entry.
	AncestorComponentDefinitions map[string]*v1beta1.ComponentDefinition
	AncestorTraitDefinitions     map[string]*v1beta1.TraitDefinition
	// AncestorStatus is each ancestor's status CUE, nearest parent first, so a
	// health policy composes with the one it extends.
	AncestorStatus []health.Snippets
}

Template is a helper struct for processing capability including ComponentDefinition, TraitDefinition. It mainly collects schematic and status data of a capability definition.

func LoadTemplate added in v1.0.3

func LoadTemplate(ctx context.Context, cli client.Client, capName string, capType types.CapType, annotations map[string]string) (*Template, error)

LoadTemplate gets the capability definition from cluster and resolve it. It returns a helper struct, Template, which will be used for further processing.

func LoadTemplateFromRevision added in v1.1.1

func LoadTemplateFromRevision(capName string, capType types.CapType, apprev *v1beta1.ApplicationRevision, mapper meta.RESTMapper) (*Template, error)

LoadTemplateFromRevision will load Definition template from app revision

func (*Template) AsStatusRequest added in v1.10.4

func (t *Template) AsStatusRequest(parameter map[string]interface{}) *health.StatusRequest

type TemplateLoaderFn added in v1.0.3

type TemplateLoaderFn func(context.Context, client.Client, string, types.CapType, map[string]string) (*Template, error)

TemplateLoaderFn load template of a capability definition

func DryRunTemplateLoader added in v1.0.3

func DryRunTemplateLoader(defs []*unstructured.Unstructured) TemplateLoaderFn

DryRunTemplateLoader return a function that do the same work as LoadTemplate, but load template from provided ones before loading from cluster through LoadTemplate

func (TemplateLoaderFn) LoadTemplate added in v1.0.3

func (fn TemplateLoaderFn) LoadTemplate(ctx context.Context, c client.Client, capName string, capType types.CapType, annotations map[string]string) (*Template, error)

LoadTemplate load template of a capability definition

type Trait added in v0.3.1

type Trait struct {
	// The Name is name of TraitDefinition, actually it's a type of the trait instance
	Name string
	// TypeLabel is the trait.oam.dev/type value on the objects the trait emits.
	// It equals Name except for a module trait, where it is the installed name.
	TypeLabel          string
	CapabilityCategory types.CapabilityCategory
	Params             map[string]interface{}

	Template           string
	CustomStatusFormat string

	// RequiredSecrets stores secret names which the trait needs from cloud resource component and its context
	RequiredSecrets []process.RequiredSecrets

	FullTemplate *Template
	// contains filtered or unexported fields
}

Trait is ComponentTrait

func (*Trait) EvalContext added in v0.3.1

func (trait *Trait) EvalContext(ctx process.Context) error

EvalContext eval trait template and set result to context

func (*Trait) EvalStatus added in v0.3.3

func (trait *Trait) EvalStatus(templateContext map[string]interface{}) (*health.StatusResult, error)

EvalStatus eval trait status (including health)

func (*Trait) GetTemplateContext added in v1.7.0

func (trait *Trait) GetTemplateContext(ctx process.Context, client client.Client, accessor util.NamespaceAccessor) (map[string]interface{}, error)

GetTemplateContext get trait template context, it will be used to eval status and health

func (*Trait) GetTypeLabel

func (trait *Trait) GetTypeLabel() string

GetTypeLabel returns TypeLabel, falling back to Name for a Trait built without one.

Directories

Path Synopsis
helm
flux2apis
Package apis contains typed structs from fluxcd/helm-controller and fluxcd/source-controller.
Package apis contains typed structs from fluxcd/helm-controller and fluxcd/source-controller.

Jump to

Keyboard shortcuts

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