Documentation
¶
Index ¶
- Constants
- func ClusterLabelsExist(ctx context.Context, c client.Client) (bool, error)
- func FormatClusterLabels(labels map[string]string) string
- func GetClusterLabels(ctx context.Context, c client.Client) (map[string]string, error)
- func ValidatePlacement(spec PlacementSpec) error
- type AllCondition
- type AnyCondition
- type Condition
- type LabelCondition
- type LabelConditionBuilder
- func (b *LabelConditionBuilder) Eq(value string) *LabelCondition
- func (b *LabelConditionBuilder) Exists() *LabelCondition
- func (b *LabelConditionBuilder) In(values ...string) *LabelCondition
- func (b *LabelConditionBuilder) Ne(value string) *LabelCondition
- func (b *LabelConditionBuilder) NotExists() *LabelCondition
- func (b *LabelConditionBuilder) NotIn(values ...string) *LabelCondition
- type NotCondition
- type Operator
- type PlacementResult
- type PlacementSpec
- type ValidationError
Constants ¶
const ( // ClusterIdentityConfigMapName is the well-known name of the ConfigMap // that stores cluster identity labels for definition placement. ClusterIdentityConfigMapName = "vela-cluster-identity" // ClusterIdentityNamespace is the namespace where the cluster identity // ConfigMap is expected to be found. ClusterIdentityNamespace = "vela-system" )
Variables ¶
This section is empty.
Functions ¶
func ClusterLabelsExist ¶
ClusterLabelsExist checks if the cluster identity ConfigMap exists. This can be used to warn users that cluster labels are not configured.
func FormatClusterLabels ¶
FormatClusterLabels returns a formatted string representation of cluster labels suitable for display in CLI output.
func GetClusterLabels ¶
GetClusterLabels retrieves the cluster identity labels from the well-known ConfigMap in the vela-system namespace.
The ConfigMap is expected to be named "vela-cluster-identity" and contain labels as key-value pairs in its Data field.
Returns an empty map (not an error) if the ConfigMap does not exist, allowing definitions without placement constraints to work on any cluster.
func ValidatePlacement ¶
func ValidatePlacement(spec PlacementSpec) error
ValidatePlacement checks for conflicting placement constraints. Returns an error if the constraints would prevent the definition from running anywhere.
Conflict detection covers:
- Identical conditions in RunOn and NotRunOn
- Label conditions that logically conflict (e.g., Eq vs Exists on same key)
- Composite conditions (All, Any, Not) with conflicting inner conditions
- Deeply nested conditions
Types ¶
type AllCondition ¶
type AllCondition struct {
// Conditions are the conditions to AND together.
Conditions []Condition `json:"conditions" yaml:"conditions"`
}
AllCondition represents a logical AND of multiple conditions. All conditions must match for the AllCondition to match.
func All ¶
func All(conditions ...Condition) *AllCondition
All creates an AllCondition that requires all conditions to match.
func (*AllCondition) Evaluate ¶
func (c *AllCondition) Evaluate(labels map[string]string) bool
Evaluate for AllCondition returns true if all conditions match.
func (*AllCondition) String ¶
func (c *AllCondition) String() string
String returns a human-readable representation of the AllCondition.
type AnyCondition ¶
type AnyCondition struct {
// Conditions are the conditions to OR together.
Conditions []Condition `json:"conditions" yaml:"conditions"`
}
AnyCondition represents a logical OR of multiple conditions. At least one condition must match for the AnyCondition to match.
func Any ¶
func Any(conditions ...Condition) *AnyCondition
Any creates an AnyCondition that requires at least one condition to match.
func (*AnyCondition) Evaluate ¶
func (c *AnyCondition) Evaluate(labels map[string]string) bool
Evaluate for AnyCondition returns true if any condition matches.
func (*AnyCondition) String ¶
func (c *AnyCondition) String() string
String returns a human-readable representation of the AnyCondition.
type Condition ¶
type Condition interface {
// Evaluate returns true if the condition matches the given labels.
Evaluate(labels map[string]string) bool
// String returns a human-readable representation of the condition.
String() string
}
Condition represents a placement condition that can be evaluated against a set of cluster labels.
type LabelCondition ¶
type LabelCondition struct {
// Key is the label key to match against.
Key string `json:"key" yaml:"key"`
// Operator is the comparison operator.
Operator Operator `json:"operator" yaml:"operator"`
// Values are the values to compare against (used by Eq, Ne, In, NotIn).
Values []string `json:"values,omitempty" yaml:"values,omitempty"`
}
LabelCondition represents a condition on a single cluster label.
func (*LabelCondition) Evaluate ¶
func (c *LabelCondition) Evaluate(labels map[string]string) bool
Evaluate for LabelCondition checks if the label matches the condition.
func (*LabelCondition) String ¶
func (c *LabelCondition) String() string
String returns a human-readable representation of the LabelCondition.
type LabelConditionBuilder ¶
type LabelConditionBuilder struct {
// contains filtered or unexported fields
}
LabelConditionBuilder provides a fluent API for creating LabelConditions.
func Label ¶
func Label(key string) *LabelConditionBuilder
Label creates a new LabelCondition builder for the given key.
func (*LabelConditionBuilder) Eq ¶
func (b *LabelConditionBuilder) Eq(value string) *LabelCondition
Eq creates a condition that matches when the label equals the value.
func (*LabelConditionBuilder) Exists ¶
func (b *LabelConditionBuilder) Exists() *LabelCondition
Exists creates a condition that matches when the label key exists.
func (*LabelConditionBuilder) In ¶
func (b *LabelConditionBuilder) In(values ...string) *LabelCondition
In creates a condition that matches when the label value is in the set.
func (*LabelConditionBuilder) Ne ¶
func (b *LabelConditionBuilder) Ne(value string) *LabelCondition
Ne creates a condition that matches when the label does not equal the value.
func (*LabelConditionBuilder) NotExists ¶
func (b *LabelConditionBuilder) NotExists() *LabelCondition
NotExists creates a condition that matches when the label key does not exist.
func (*LabelConditionBuilder) NotIn ¶
func (b *LabelConditionBuilder) NotIn(values ...string) *LabelCondition
NotIn creates a condition that matches when the label value is not in the set.
type NotCondition ¶
type NotCondition struct {
// Condition is the condition to negate.
Condition Condition `json:"condition" yaml:"condition"`
}
NotCondition represents a logical NOT of a condition. Matches when the inner condition does not match.
func Not ¶
func Not(condition Condition) *NotCondition
Not creates a NotCondition that negates the given condition.
func (*NotCondition) Evaluate ¶
func (c *NotCondition) Evaluate(labels map[string]string) bool
Evaluate for NotCondition returns true if the inner condition does not match.
func (*NotCondition) String ¶
func (c *NotCondition) String() string
String returns a human-readable representation of the NotCondition.
type Operator ¶
type Operator string
Operator represents a comparison operator for label matching.
const ( // OperatorEquals matches when the label value equals the specified value. OperatorEquals Operator = "Eq" // OperatorNotEquals matches when the label value does not equal the specified value. OperatorNotEquals Operator = "Ne" // OperatorIn matches when the label value is in the specified set of values. OperatorIn Operator = "In" // OperatorNotIn matches when the label value is not in the specified set of values. OperatorNotIn Operator = "NotIn" // OperatorExists matches when the label key exists (regardless of value). OperatorExists Operator = "Exists" // OperatorNotExists matches when the label key does not exist. OperatorNotExists Operator = "NotExists" )
func ValidOperators ¶
func ValidOperators() []Operator
ValidOperators returns all valid operator values.
type PlacementResult ¶
type PlacementResult struct {
// Eligible indicates whether the definition can run on the cluster.
Eligible bool
// Reason provides a human-readable explanation for the result.
Reason string
// MatchedRunOn indicates which RunOn conditions matched (if any).
MatchedRunOn []string
// MatchedNotRunOn indicates which NotRunOn conditions matched (if any).
MatchedNotRunOn []string
}
PlacementResult represents the result of evaluating placement constraints.
func Evaluate ¶
func Evaluate(spec PlacementSpec, labels map[string]string) PlacementResult
Evaluate checks if the given cluster labels satisfy the placement constraints. Returns a PlacementResult with eligibility status and explanation.
Evaluation logic:
- If no constraints are defined, the definition is eligible (runs everywhere)
- If RunOn is specified, all RunOn conditions must match
- If NotRunOn is specified, none of the NotRunOn conditions must match
- Final eligibility = (matches RunOn OR RunOn is empty) AND (does not match NotRunOn)
type PlacementSpec ¶
type PlacementSpec struct {
// RunOn specifies conditions that must be satisfied for the definition
// to be applied. If multiple conditions are provided, they are ANDed together.
// If empty, the definition can run on any cluster.
RunOn []Condition `json:"runOn,omitempty" yaml:"runOn,omitempty"`
// NotRunOn specifies conditions that exclude clusters from running the
// definition. If any condition matches, the definition will not be applied.
// If empty, no clusters are excluded.
NotRunOn []Condition `json:"notRunOn,omitempty" yaml:"notRunOn,omitempty"`
}
PlacementSpec defines where a definition can and cannot run.
func GetEffectivePlacement ¶
func GetEffectivePlacement(modulePlacement, definitionPlacement PlacementSpec) PlacementSpec
GetEffectivePlacement returns the effective placement by combining module-level and definition-level placements. If the definition has placement constraints, they override the module defaults. If the definition has no placement constraints, the module defaults are used.
func (*PlacementSpec) IsEmpty ¶
func (p *PlacementSpec) IsEmpty() bool
IsEmpty returns true if no placement constraints are defined.
type ValidationError ¶
ValidationError represents a placement validation error.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string