Documentation
¶
Index ¶
- Constants
- Variables
- func ComputeAppRevisionHash(appRevision *v1beta1.ApplicationRevision) (string, error)
- func DeepEqualRevision(old, new *v1beta1.ApplicationRevision) bool
- func GetAppRevisions(ctx context.Context, cli client.Client, appName string, appNs string) ([]v1beta1.ApplicationRevision, error)
- func GetSortedAppRevisions(ctx context.Context, cli client.Client, appName string, appNs string) ([]v1beta1.ApplicationRevision, error)
- func Setup(mgr ctrl.Manager, args core.Args) error
- type AppHandler
- func (h *AppHandler) ApplyApplicationScopeTransforms(ctx monitorContext.Context, app *v1beta1.Application) (monitorContext.Context, error)
- func (h *AppHandler) ApplyPolicies(ctx context.Context, af *appfile.Appfile) error
- func (h *AppHandler) Delete(ctx context.Context, _ client.Client, cluster string, owner string, ...) error
- func (h *AppHandler) Dispatch(ctx context.Context, _ client.Client, cluster string, owner string, ...) error
- func (h *AppHandler) FinalizeAndApplyAppRevision(ctx context.Context) error
- func (h *AppHandler) GenerateApplicationSteps(ctx monitorContext.Context, app *v1beta1.Application, ...) (*wfTypes.WorkflowInstance, []wfTypes.TaskRunner, error)
- func (h *AppHandler) PrepareCurrentAppRevision(ctx context.Context, af *appfile.Appfile) error
- func (h *AppHandler) UpdateAppLatestRevisionStatus(ctx context.Context, patchStatus statusPatcher) error
- func (h *AppHandler) UpdateApplicationMetadata(ctx monitorContext.Context, app *v1beta1.Application) error
- func (h *AppHandler) UpdateApplicationRevisionStatus(ctx context.Context, appRev *v1beta1.ApplicationRevision, ...)
- type ApplicationPolicyCache
- func (c *ApplicationPolicyCache) CleanupStale() int
- func (c *ApplicationPolicyCache) Get(app *v1beta1.Application) ([]RenderedPolicyResult, bool, error)
- func (c *ApplicationPolicyCache) GetWithReason(app *v1beta1.Application) ([]RenderedPolicyResult, bool, string, error)
- func (c *ApplicationPolicyCache) InvalidateAll()
- func (c *ApplicationPolicyCache) InvalidateApplication(namespace, name string)
- func (c *ApplicationPolicyCache) InvalidateForNamespace(namespace string)
- func (c *ApplicationPolicyCache) Set(app *v1beta1.Application, results []RenderedPolicyResult) error
- func (c *ApplicationPolicyCache) Size() int
- type ApplicationPolicyCacheEntry
- type DispatchOptions
- type HealthStatus
- type PolicyDryRunResult
- type PolicyMetadata
- type PolicyOutput
- type PolicyScopeIndex
- func (idx *PolicyScopeIndex) AddOrUpdate(policy *v1beta1.PolicyDefinition)
- func (idx *PolicyScopeIndex) Delete(policyName, namespace string)
- func (idx *PolicyScopeIndex) Get(policyName, appNamespace string) *PolicyMetadata
- func (idx *PolicyScopeIndex) GetFromNamespace(policyName, namespace string) *PolicyMetadata
- func (idx *PolicyScopeIndex) GetGlobalApplicationPolicies(namespace string) []*PolicyMetadata
- func (idx *PolicyScopeIndex) GetGlobalApplicationPoliciesDeduped(appNamespace string) []*PolicyMetadata
- func (idx *PolicyScopeIndex) Initialize(ctx context.Context, cli client.Client) error
- func (idx *PolicyScopeIndex) InvalidateNamespace(namespace string)
- func (idx *PolicyScopeIndex) Size() int
- type PolicyTransforms
- type PolicyValidationResult
- type Reconciler
- type RenderedPolicyResult
- type SortDispatchOptions
- type StageType
- type TraitFilter
- type Transform
- type TransformOperationType
Constants ¶
const ( // ComponentNamespaceContextKey is the key in context that defines the override namespace of component ComponentNamespaceContextKey contextKey = iota // ComponentContextKey is the key in context that records the component ComponentContextKey // ReplicaKeyContextKey is the key in context that records the replica key ReplicaKeyContextKey // OriginalAppKey is the key in the context that records the in coming original app OriginalAppKey // PolicyAdditionalContextKey is the key in the context that records additional context from Application-scoped policies PolicyAdditionalContextKey )
const ( // ApplicationPolicyCacheTTL defines how long cache entries are valid ApplicationPolicyCacheTTL = 1 * time.Minute // Policy source values for RenderedPolicyResult.Source PolicySourceGlobal = "global" PolicySourceExplicit = "explicit" // Cache miss reasons returned by GetWithReason CacheMissNotFound = "not_found" CacheMissSpecChanged = "spec_changed" CacheMissRevisionChanged = "revision_changed" CacheMissTTLExpired = "ttl_expired" )
const SkipGlobalPoliciesAnnotation = oam.AnnotationSkipGlobalPolicies
SkipGlobalPoliciesAnnotation is an alias for oam.AnnotationSkipGlobalPolicies.
Variables ¶
var ( // DisableAllComponentRevision disable component revision creation DisableAllComponentRevision = false // DisableAllApplicationRevision disable application revision creation DisableAllApplicationRevision = false )
var ( // DisableResourceApplyDoubleCheck optimize applyComponentFunc by disable post resource existing check after dispatch DisableResourceApplyDoubleCheck = false )
var ( // EnableResourceTrackerDeleteOnlyTrigger optimize ResourceTracker mutate event trigger by only receiving deleting events EnableResourceTrackerDeleteOnlyTrigger = true )
Functions ¶
func ComputeAppRevisionHash ¶
func ComputeAppRevisionHash(appRevision *v1beta1.ApplicationRevision) (string, error)
ComputeAppRevisionHash computes a single hash value for an appRevision object Spec of Application/WorkloadDefinitions/ComponentDefinitions/TraitDefinitions/ScopeDefinitions will be taken into compute
func DeepEqualRevision ¶
func DeepEqualRevision(old, new *v1beta1.ApplicationRevision) bool
DeepEqualRevision will compare the spec of Application and Definition to see if the Application is the same revision Spec of AC and Component will not be compared as they are generated by the application and definitions Note the Spec compare can only work when the RawExtension are decoded well in the RawExtension.Object instead of in RawExtension.Raw(bytes)
func GetAppRevisions ¶
func GetAppRevisions(ctx context.Context, cli client.Client, appName string, appNs string) ([]v1beta1.ApplicationRevision, error)
GetAppRevisions get application revisions by label
Types ¶
type AppHandler ¶
AppHandler handles application reconcile
func NewAppHandler ¶
func NewAppHandler(ctx context.Context, r *Reconciler, app *v1beta1.Application) (*AppHandler, error)
NewAppHandler create new app handler
func (*AppHandler) ApplyApplicationScopeTransforms ¶
func (h *AppHandler) ApplyApplicationScopeTransforms(ctx monitorContext.Context, app *v1beta1.Application) (monitorContext.Context, error)
ApplyApplicationScopeTransforms applies Application-scoped policy transforms to the in-memory Application before it is parsed into an AppFile. Global policies (vela-system) are applied first, then explicit spec.policies, in priority order. Results are cached with a 1-minute TTL and written to a ConfigMap for observability (backing store for `vela policy show`).
func (*AppHandler) ApplyPolicies ¶
ApplyPolicies will render policies into manifests from appfile and dispatch them Note the builtin policy like apply-once, shared-resource, etc. is not handled here.
func (*AppHandler) Delete ¶
func (h *AppHandler) Delete(ctx context.Context, _ client.Client, cluster string, owner string, manifest *unstructured.Unstructured) error
Delete delete manifests from k8s.
func (*AppHandler) Dispatch ¶
func (h *AppHandler) Dispatch(ctx context.Context, _ client.Client, cluster string, owner string, manifests ...*unstructured.Unstructured) error
Dispatch apply manifests into k8s.
func (*AppHandler) FinalizeAndApplyAppRevision ¶
func (h *AppHandler) FinalizeAndApplyAppRevision(ctx context.Context) error
FinalizeAndApplyAppRevision finalise AppRevision object and apply it
func (*AppHandler) GenerateApplicationSteps ¶
func (h *AppHandler) GenerateApplicationSteps(ctx monitorContext.Context, app *v1beta1.Application, appParser *appfile.Parser, af *appfile.Appfile) (*wfTypes.WorkflowInstance, []wfTypes.TaskRunner, error)
GenerateApplicationSteps generate application steps. nolint:gocyclo
func (*AppHandler) PrepareCurrentAppRevision ¶
PrepareCurrentAppRevision will generate a pure revision without metadata and rendered result the generated revision will be compare with the last revision to see if there's any difference.
func (*AppHandler) UpdateAppLatestRevisionStatus ¶
func (h *AppHandler) UpdateAppLatestRevisionStatus(ctx context.Context, patchStatus statusPatcher) error
UpdateAppLatestRevisionStatus only call to update app's latest revision status after applying manifests successfully otherwise it will override previous revision which is used during applying to do GC jobs
func (*AppHandler) UpdateApplicationMetadata ¶
func (h *AppHandler) UpdateApplicationMetadata(ctx monitorContext.Context, app *v1beta1.Application) error
UpdateApplicationMetadata persists policy-applied labels and annotations to the Application. Uses MergePatch to avoid clobbering concurrent spec changes. Safe because ApplicationRevision hashes only cover Application.Spec, not metadata.
func (*AppHandler) UpdateApplicationRevisionStatus ¶
func (h *AppHandler) UpdateApplicationRevisionStatus(ctx context.Context, appRev *v1beta1.ApplicationRevision, wfStatus *common.WorkflowStatus)
UpdateApplicationRevisionStatus update application revision status
type ApplicationPolicyCache ¶
type ApplicationPolicyCache struct {
// contains filtered or unexported fields
}
ApplicationPolicyCache caches rendered policy results keyed by namespace/name.
func NewApplicationPolicyCache ¶
func NewApplicationPolicyCache() *ApplicationPolicyCache
func (*ApplicationPolicyCache) CleanupStale ¶
func (c *ApplicationPolicyCache) CleanupStale() int
CleanupStale removes entries older than ApplicationPolicyCacheTTL and returns the count removed.
func (*ApplicationPolicyCache) Get ¶
func (c *ApplicationPolicyCache) Get(app *v1beta1.Application) ([]RenderedPolicyResult, bool, error)
Get retrieves cached results. Returns (results, hit, error).
func (*ApplicationPolicyCache) GetWithReason ¶
func (c *ApplicationPolicyCache) GetWithReason(app *v1beta1.Application) ([]RenderedPolicyResult, bool, string, error)
GetWithReason retrieves cached results with a miss reason for diagnostics. missReason: CacheMissNotFound | CacheMissSpecChanged | CacheMissRevisionChanged | CacheMissTTLExpired | "" (hit)
func (*ApplicationPolicyCache) InvalidateAll ¶
func (c *ApplicationPolicyCache) InvalidateAll()
InvalidateAll clears the entire cache. Call when global (vela-system) policies change.
func (*ApplicationPolicyCache) InvalidateApplication ¶
func (c *ApplicationPolicyCache) InvalidateApplication(namespace, name string)
func (*ApplicationPolicyCache) InvalidateForNamespace ¶
func (c *ApplicationPolicyCache) InvalidateForNamespace(namespace string)
InvalidateForNamespace removes all cache entries for Applications in the given namespace.
func (*ApplicationPolicyCache) Set ¶
func (c *ApplicationPolicyCache) Set(app *v1beta1.Application, results []RenderedPolicyResult) error
Set stores rendered policy results in the cache
func (*ApplicationPolicyCache) Size ¶
func (c *ApplicationPolicyCache) Size() int
type ApplicationPolicyCacheEntry ¶
type ApplicationPolicyCacheEntry struct {
// contains filtered or unexported fields
}
ApplicationPolicyCacheEntry holds rendered results for one Application. Invalidated when spec hash changes, ApplicationRevision changes, or TTL expires.
type DispatchOptions ¶
type DispatchOptions struct {
Workload *unstructured.Unstructured
Traits []*unstructured.Unstructured
OverrideNamespace string
Stage StageType
}
DispatchOptions is the options for dispatch
type HealthStatus ¶ added in v1.10.4
HealthStatus represents the health status of an application
type PolicyDryRunResult ¶
type PolicyDryRunResult struct {
// Application is the final in-memory state after all policies applied
Application *v1beta1.Application
// PolicyResults contains per-policy results in execution order
PolicyResults []common.AppliedApplicationPolicy
// PolicyDetails contains the full per-policy observability data (same structure as the
// ConfigMap written by the controller), keyed by policy name. Includes SpecBefore/SpecAfter.
PolicyDetails map[string]map[string]interface{}
// FinalContext is the merged context injected by all policies (union of output.ctx fields).
// This is what downstream CUE templates would see as context.custom.* during rendering.
FinalContext map[string]interface{}
// Errors contains any errors encountered during simulation
Errors []string
}
PolicyDryRunResult contains the results of a policy dry-run simulation
func SimulatePolicyApplication ¶
func SimulatePolicyApplication(ctx context.Context, cli client.Client, app *v1beta1.Application) (*PolicyDryRunResult, error)
SimulatePolicyApplication performs a dry-run simulation of policy application. It runs the exact same code path as the controller (ApplyApplicationScopeTransforms) on a deep copy of the Application, so results are guaranteed to match what the controller would do.
type PolicyMetadata ¶
type PolicyMetadata struct {
Name string
Namespace string
Scope v1beta1.PolicyScope
Global bool
Priority int32
ResourceVersion string
}
PolicyMetadata stores lightweight metadata about a PolicyDefinition This allows us to check scope and other properties without fetching the full definition
type PolicyOutput ¶
type PolicyOutput struct {
Components []common.ApplicationComponent `json:"components,omitempty"`
Workflow *v1beta1.Workflow `json:"workflow,omitempty"`
Policies []v1beta1.AppPolicy `json:"policies,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Ctx map[string]interface{} `json:"ctx,omitempty"`
}
PolicyOutput is the output structure returned by policy CUE templates.
type PolicyScopeIndex ¶
type PolicyScopeIndex struct {
// contains filtered or unexported fields
}
PolicyScopeIndex maintains an in-memory index of PolicyDefinition metadata This index is eagerly populated at startup and kept synchronized via watch events It also supports lazy initialization on first access for testing scenarios
func NewPolicyScopeIndex ¶
func NewPolicyScopeIndex() *PolicyScopeIndex
NewPolicyScopeIndex creates a new empty index
func (*PolicyScopeIndex) AddOrUpdate ¶
func (idx *PolicyScopeIndex) AddOrUpdate(policy *v1beta1.PolicyDefinition)
AddOrUpdate adds or updates a policy in the index This should be called from watch event handlers
func (*PolicyScopeIndex) Delete ¶
func (idx *PolicyScopeIndex) Delete(policyName, namespace string)
Delete removes a policy from the index This should be called from watch event handlers
func (*PolicyScopeIndex) Get ¶
func (idx *PolicyScopeIndex) Get(policyName, appNamespace string) *PolicyMetadata
Get retrieves metadata for a policy, searching in the specified namespace and vela-system Returns nil if not found
func (*PolicyScopeIndex) GetFromNamespace ¶
func (idx *PolicyScopeIndex) GetFromNamespace(policyName, namespace string) *PolicyMetadata
GetFromNamespace retrieves metadata for a policy in a specific namespace Returns nil if not found
func (*PolicyScopeIndex) GetGlobalApplicationPolicies ¶
func (idx *PolicyScopeIndex) GetGlobalApplicationPolicies(namespace string) []*PolicyMetadata
GetGlobalApplicationPolicies returns pre-filtered global Application-scoped policies This eliminates the need for List operations and in-memory filtering Returns policies sorted by Priority (asc) then Name (asc): lower priority value runs first
func (*PolicyScopeIndex) GetGlobalApplicationPoliciesDeduped ¶
func (idx *PolicyScopeIndex) GetGlobalApplicationPoliciesDeduped(appNamespace string) []*PolicyMetadata
GetGlobalApplicationPoliciesDeduped returns deduplicated global policies Namespace policies take precedence over vela-system policies
func (*PolicyScopeIndex) Initialize ¶
Initialize populates the index by listing all PolicyDefinitions from the cluster This should be called at controller startup
func (*PolicyScopeIndex) InvalidateNamespace ¶
func (idx *PolicyScopeIndex) InvalidateNamespace(namespace string)
InvalidateNamespace invalidates all policies in a namespace and rebuilds the index This can be used as a fallback if individual updates miss something
func (*PolicyScopeIndex) Size ¶
func (idx *PolicyScopeIndex) Size() int
Size returns the total number of indexed policies
type PolicyTransforms ¶
type PolicyTransforms struct {
Spec *Transform `json:"spec,omitempty"`
Labels *Transform `json:"labels,omitempty"`
Annotations *Transform `json:"annotations,omitempty"`
}
PolicyTransforms is the old-API transform structure (kept for backwards compatibility).
type PolicyValidationResult ¶
PolicyValidationResult contains validation errors and warnings
func ValidatePolicyDefinition ¶
func ValidatePolicyDefinition(policy *v1beta1.PolicyDefinition) *PolicyValidationResult
ValidatePolicyDefinition validates a PolicyDefinition Returns validation result with errors (blocking) and warnings (informational)
func (*PolicyValidationResult) IsValid ¶
func (r *PolicyValidationResult) IsValid() bool
IsValid returns true if there are no errors
type Reconciler ¶
type Reconciler struct {
client.Client
Scheme *runtime.Scheme
Recorder event.Recorder
// contains filtered or unexported fields
}
Reconciler reconciles an Application object
func (*Reconciler) SetupWithManager ¶
func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error
SetupWithManager install to manager
type RenderedPolicyResult ¶
type RenderedPolicyResult struct {
PolicyName string
PolicyType string
PolicyNamespace string
Priority int32
Enabled bool
Source string // PolicySourceGlobal or PolicySourceExplicit
Transforms interface{} // *PolicyOutput
AdditionalContext map[string]interface{} // output.ctx
SkipReason string
IsError bool // true when SkipReason is due to an error, false for config.enabled=false
// VersionKey is the namespaced key used in the handler's policyVersions map.
// For globals: "global:<defName>". For explicit: "<policy.Name>".
// Stored on the result so cache-restore can rebuild the map with correct keys.
VersionKey string
// Version tracking for status observability.
DefinitionRevisionName string
Revision int64
RevisionHash string
PolicyDefinitionUsed *v1beta1.PolicyDefinition
// Per-policy spec snapshots for ConfigMap audit trail; nil when spec was not modified.
SpecBefore *v1beta1.ApplicationSpec
SpecAfter *v1beta1.ApplicationSpec
}
RenderedPolicyResult stores the output of a rendered policy CUE template.
type SortDispatchOptions ¶
type SortDispatchOptions []DispatchOptions
SortDispatchOptions describe the sorting for options
func (SortDispatchOptions) Len ¶
func (s SortDispatchOptions) Len() int
func (SortDispatchOptions) Less ¶
func (s SortDispatchOptions) Less(i, j int) bool
func (SortDispatchOptions) Swap ¶
func (s SortDispatchOptions) Swap(i, j int)
type StageType ¶
type StageType int
StageType is a valid value for TraitDefinitionSpec.Stage
func ParseStageType ¶
ParseStageType parse the StageType from a string
type TraitFilter ¶
TraitFilter is used to filter trait object.
func ByTraitType ¶
func ByTraitType(readyTraits, checkTraits []*unstructured.Unstructured) TraitFilter
ByTraitType returns a filter that does not match the given type and belongs to readyTraits.
type Transform ¶
type Transform struct {
Type TransformOperationType `json:"type"`
Value interface{} `json:"value"`
}
Transform represents a typed transformation operation.
type TransformOperationType ¶
type TransformOperationType string
TransformOperationType defines the type of operation for a transform.
const ( TransformReplace TransformOperationType = "replace" TransformMerge TransformOperationType = "merge" )