@@ -82,6 +82,15 @@ type DeleteOption struct {
82
82
83
83
// selectivelyOrphan represents a list of resources following orphan deletion stratecy
84
84
SelectivelyOrphan * SelectivelyOrphan `json:"selectivelyOrphans,omitempty"`
85
+
86
+ // TTLSecondsAfterFinished limits the lifetime of a ManifestWork that has been marked Complete
87
+ // by one or more conditionRules set for its manifests. If this field is set, and
88
+ // the manifestwork has completed, then it is elligible to be automatically deleted.
89
+ // If this field is unset, the manifestwork won't be automatically deleted even afer completion.
90
+ // If this field is set to zero, the manfiestwork becomes elligible to be deleted immediately
91
+ // after completion.
92
+ // +optional
93
+ TTLSecondsAfterFinished * int64 `json:"ttlSecondsAfterFinished,omitempty"`
85
94
}
86
95
87
96
// ManifestConfigOption represents the configurations of a manifest defined in workload field.
@@ -101,8 +110,63 @@ type ManifestConfigOption struct {
101
110
// if it is not set.
102
111
// +optional
103
112
UpdateStrategy * UpdateStrategy `json:"updateStrategy,omitempty"`
113
+
114
+ // ConditionRules defines how to set manifestwork conditions for a specific manifest.
115
+ // +listType:=map
116
+ // +listMapKey:=condition
117
+ // +optional
118
+ ConditionRules []ConditionRule `json:"conditionRules,omitempty"`
104
119
}
105
120
121
+ // +kubebuilder:validation:XValidation:rule="self.type != 'CEL' || self.condition != \"\"",message="Condition is required for CEL rules"
122
+ type ConditionRule struct {
123
+ // Condition is the type of condition that is set based on this rule.
124
+ // Any condition is supported, but certain special conditions can be used to
125
+ // to control higher level behaviors of the manifestwork.
126
+ // If the condition is Complete, the manifest will no longer be updated once completed.
127
+ // +kubebuilder:validation:Required
128
+ // +required
129
+ Condition string `json:"condition"`
130
+
131
+ // Type defines how a manifest should be evaluated for a condition.
132
+ // It can be CEL, or WellKnownConditions.
133
+ // If the type is CEL, user should specify the celExpressions field
134
+ // If the type is WellKnownConditions, certain common types in k8s.io/api will be considered
135
+ // completed as defined by hardcoded rules.
136
+ // +kubebuilder:validation:Required
137
+ // +required
138
+ Type ConditionRuleType `json:"type"`
139
+
140
+ // CelExpressions defines the CEL expressions to be evaluated for the condition.
141
+ // Final result is the logical AND of all expressions.
142
+ // +optional
143
+ CelExpressions []string `json:"celExpressions"`
144
+
145
+ // Message is set on the condition created for this rule
146
+ // +optional
147
+ Message string `json:"message"`
148
+
149
+ // MessageExpression uses a CEL expression to generate a message for the condition
150
+ // Will override message if both are set and messageExpression returns a non-empty string.
151
+ // Variables:
152
+ // - object: The current instance of the manifest
153
+ // - result: Boolean result of the CEL expressions
154
+ // +optional
155
+ MessageExpression string `json:"messageExpression"`
156
+ }
157
+
158
+ // +kubebuilder:validation:Enum=WellKnownConditions;CEL
159
+ type ConditionRuleType string
160
+
161
+ const (
162
+ // WellKnownConditionsType represents a standard Complete condition for some common types, which
163
+ // is reflected with a hardcoded rule for types in k8s.io/api
164
+ WellKnownConditionsType ConditionRuleType = "WellKnownConditions"
165
+
166
+ // CelConditionExpressionsType enables user defined rules to set the status of the condition
167
+ CelConditionExpressionsType ConditionRuleType = "CEL"
168
+ )
169
+
106
170
// ManifestWorkExecutor is the executor that applies the resources to the managed cluster. i.e. the
107
171
// work agent.
108
172
type ManifestWorkExecutor struct {
@@ -527,6 +591,21 @@ const (
527
591
// ManifestDegraded represents that the current state of resource object does not
528
592
// match the desired state for a certain period.
529
593
ManifestDegraded string = "Degraded"
594
+ // ManifestComplete represents that the resource has completed and should no longer
595
+ // be updated.
596
+ ManifestComplete string = "Complete"
597
+ )
598
+
599
+ // Condition reasons
600
+ const (
601
+ // ConditionRuleTrue is set when a rule is evaluated without error
602
+ ConditionRuleEvaluated string = "ConditionRuleEvaluated"
603
+ // ConditionRuleInvalid is set when a rule is invalid and cannot be evaluated
604
+ ConditionRuleInvalid string = "ConditionRuleInvalid"
605
+ // ConditionRuleExpressionError is set when a rule fails due to an invalid expression
606
+ ConditionRuleExpressionError string = "ConditionRuleExpressionError"
607
+ // ConditionRuleInternalError is set when rule evaluation results in an error not caused by the expression
608
+ ConditionRuleInternalError string = "ConditionRuleInternalError"
530
609
)
531
610
532
611
const (
0 commit comments