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 PolicyDryRunFlags
- 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) IgnoredNamespaceGlobals(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" // CacheMissPublishVersionChanged means the publishVersion pin moved. The new pin cuts a // revision that must render the live global policies, not the previous pin's results. CacheMissPublishVersionChanged = "publish_version_changed" // CacheMissMetadataChanged means a label or annotation policy templates read changed: one in // context.appLabels or context.appAnnotations, which include the rollout annotations. CacheMissMetadataChanged = "metadata_changed" )
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 ¶ added in v1.11.0
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 are applied first, then explicit spec.policies, in priority order. Results are cached (see ApplicationPolicyCache) and recorded in the app's policy ConfigMap, which `vela policy view` reads.
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 ¶ added in v1.11.0
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 ¶ added in v1.11.0
type ApplicationPolicyCache struct {
// contains filtered or unexported fields
}
ApplicationPolicyCache caches rendered policy results keyed by namespace/name.
func NewApplicationPolicyCache ¶ added in v1.11.0
func NewApplicationPolicyCache() *ApplicationPolicyCache
func (*ApplicationPolicyCache) CleanupStale ¶ added in v1.11.0
func (c *ApplicationPolicyCache) CleanupStale() int
CleanupStale removes entries older than ApplicationPolicyCacheTTL and returns the count removed.
func (*ApplicationPolicyCache) Get ¶ added in v1.11.0
func (c *ApplicationPolicyCache) Get(app *v1beta1.Application) ([]RenderedPolicyResult, bool, error)
Get retrieves cached results. Returns (results, hit, error).
func (*ApplicationPolicyCache) GetWithReason ¶ added in v1.11.0
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 | CacheMissPublishVersionChanged | CacheMissMetadataChanged | CacheMissTTLExpired | "" (hit)
func (*ApplicationPolicyCache) InvalidateAll ¶ added in v1.11.0
func (c *ApplicationPolicyCache) InvalidateAll()
InvalidateAll clears the entire cache. Call when global (vela-system) policies change.
func (*ApplicationPolicyCache) InvalidateApplication ¶ added in v1.11.0
func (c *ApplicationPolicyCache) InvalidateApplication(namespace, name string)
func (*ApplicationPolicyCache) InvalidateForNamespace ¶ added in v1.11.0
func (c *ApplicationPolicyCache) InvalidateForNamespace(namespace string)
InvalidateForNamespace removes all cache entries for Applications in the given namespace.
func (*ApplicationPolicyCache) Set ¶ added in v1.11.0
func (c *ApplicationPolicyCache) Set(app *v1beta1.Application, results []RenderedPolicyResult) error
Set stores rendered policy results in the cache
func (*ApplicationPolicyCache) Size ¶ added in v1.11.0
func (c *ApplicationPolicyCache) Size() int
type ApplicationPolicyCacheEntry ¶ added in v1.11.0
type ApplicationPolicyCacheEntry struct {
// contains filtered or unexported fields
}
ApplicationPolicyCacheEntry holds rendered results for one Application. It is invalidated when the spec, the ApplicationRevision, the publishVersion pin or the metadata policy templates read changes, or when the 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 PolicyDryRunFlags ¶ added in v1.11.1
type PolicyDryRunFlags struct {
AllowNamespaceGlobalPolicies bool `json:"allowNamespaceGlobalPolicies"`
AllowSkipGlobalPolicies bool `json:"allowSkipGlobalPolicies"`
}
PolicyDryRunFlags are the controller flags that change which policies apply. A simulation reads them from this process (AllowNamespaceGlobalPolicies and AllowSkipGlobalPolicies in pkg/controller/common), so they match the controller's only when the caller sets them to its values.
type PolicyDryRunResult ¶ added in v1.11.0
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
// Flags are the controller flags the simulation assumed.
Flags PolicyDryRunFlags
}
PolicyDryRunResult contains the results of a policy dry-run simulation
func SimulatePolicyApplication ¶ added in v1.11.0
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 controller's code path (ApplyApplicationScopeTransforms) on a deep copy of the Application, through a client that drops every write. The result matches the controller's when this process holds the controller's flags (see PolicyDryRunFlags) and the policies read the same cluster data.
type PolicyMetadata ¶ added in v1.11.0
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 ¶ added in v1.11.0
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 ¶ added in v1.11.0
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 ¶ added in v1.11.0
func NewPolicyScopeIndex() *PolicyScopeIndex
NewPolicyScopeIndex creates a new empty index
func (*PolicyScopeIndex) AddOrUpdate ¶ added in v1.11.0
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 ¶ added in v1.11.0
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 ¶ added in v1.11.0
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 ¶ added in v1.11.0
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 ¶ added in v1.11.0
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 ¶ added in v1.11.0
func (idx *PolicyScopeIndex) GetGlobalApplicationPoliciesDeduped(appNamespace string) []*PolicyMetadata
GetGlobalApplicationPoliciesDeduped returns deduplicated global policies Namespace policies take precedence over vela-system policies
func (*PolicyScopeIndex) IgnoredNamespaceGlobals ¶ added in v1.11.1
func (idx *PolicyScopeIndex) IgnoredNamespaceGlobals(appNamespace string) []*PolicyMetadata
IgnoredNamespaceGlobals returns the global policies in appNamespace that do not apply because global policies are restricted to vela-system (--allow-namespace-global-policies=false).
func (*PolicyScopeIndex) Initialize ¶ added in v1.11.0
Initialize populates the index by listing all PolicyDefinitions from the cluster This should be called at controller startup
func (*PolicyScopeIndex) InvalidateNamespace ¶ added in v1.11.0
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 ¶ added in v1.11.0
func (idx *PolicyScopeIndex) Size() int
Size returns the total number of indexed policies
type PolicyTransforms ¶ added in v1.11.0
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 ¶ added in v1.11.0
PolicyValidationResult contains validation errors and warnings
func ValidatePolicyDefinition ¶ added in v1.11.0
func ValidatePolicyDefinition(ctx context.Context, policy *v1beta1.PolicyDefinition, cueTemplate string, val cue.Value) *PolicyValidationResult
ValidatePolicyDefinition validates a PolicyDefinition. cueTemplate and val are the effective (post-upgrade) template and its compiled cue.Value, computed once by the caller with webhookutils.CompilePolicyTemplate: this function and validateNoRequiredParameters both check against them rather than each compiling the template again. Neither is read when the policy has no CUE schematic, since that case is rejected before either is touched. Returns validation result with errors (blocking) and warnings (informational)
func (*PolicyValidationResult) IsValid ¶ added in v1.11.0
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 ¶ added in v1.11.0
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
// UpdatePending is set when a newer live version of this policy is held back, by the app's
// rollout settings, a publishVersion pin, a render failure or a spec rewrite; it applies at
// the app's next revision.
UpdatePending bool
// UpdateFailsToRender is set on a pending update whose newer version fails to render.
UpdateFailsToRender bool
// UpdateRewritesSpec is set on a pending update whose newer version rewrites the spec.
UpdateRewritesSpec bool
// DataPending is set when this policy's output changed with apply-data-changes off: it
// contributes the output last applied, and the change applies at the app's next revision.
DataPending bool
// Settings are the rollout settings the rendered template sets under config, and
// SettingWarnings describes any it set that were ignored.
Settings policySettings
SettingWarnings []string
// 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 ¶ added in v1.11.0
type Transform struct {
Type TransformOperationType `json:"type"`
Value interface{} `json:"value"`
}
Transform represents a typed transformation operation.
type TransformOperationType ¶ added in v1.11.0
type TransformOperationType string
TransformOperationType defines the type of operation for a transform.
const ( TransformReplace TransformOperationType = "replace" TransformMerge TransformOperationType = "merge" )
Source Files
¶
- application_controller.go
- application_metrics.go
- application_policies.go
- application_policy_cache.go
- apply.go
- dispatcher.go
- generator.go
- policy_dryrun.go
- policy_errors.go
- policy_held_updates.go
- policy_hold.go
- policy_rollout.go
- policy_scope_index.go
- policy_validation.go
- revision.go
- valuesfrom_fingerprint.go
- workflow.go