Skip to content

Commit 5880b0c

Browse files
authored
✨ Workload conditions (#362)
* Add support for manifestwork condition rules to types Signed-off-by: Ben Perry <[email protected]> * Update codegen Signed-off-by: Ben Perry <[email protected]> * gofmt doesn't like '' in comments Signed-off-by: Ben Perry <[email protected]> * Const condition reasons Signed-off-by: Ben Perry <[email protected]> * No need for separate reasons on successful evaluation to true/false Signed-off-by: Ben Perry <[email protected]> * Add reason for invalid condition rule Signed-off-by: Ben Perry <[email protected]> * Match cel expressions format from celSelectors Signed-off-by: Ben Perry <[email protected]> * Update from comments Signed-off-by: Ben Perry <[email protected]> --------- Signed-off-by: Ben Perry <[email protected]>
1 parent 922ceac commit 5880b0c

6 files changed

+317
-2
lines changed

addon/v1alpha1/0000_03_addon.open-cluster-management.io_addontemplates.crd.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ spec:
113113
type: object
114114
type: array
115115
type: object
116+
ttlSecondsAfterFinished:
117+
description: |-
118+
TTLSecondsAfterFinished limits the lifetime of a ManifestWork that has been marked Complete
119+
by one or more conditionRules set for its manifests. If this field is set, and
120+
the manifestwork has completed, then it is elligible to be automatically deleted.
121+
If this field is unset, the manifestwork won't be automatically deleted even afer completion.
122+
If this field is set to zero, the manfiestwork becomes elligible to be deleted immediately
123+
after completion.
124+
format: int64
125+
type: integer
116126
type: object
117127
executor:
118128
description: |-
@@ -167,6 +177,59 @@ spec:
167177
description: ManifestConfigOption represents the configurations
168178
of a manifest defined in workload field.
169179
properties:
180+
conditionRules:
181+
description: ConditionRules defines how to set manifestwork
182+
conditions for a specific manifest.
183+
items:
184+
properties:
185+
celExpressions:
186+
description: |-
187+
CelExpressions defines the CEL expressions to be evaluated for the condition.
188+
Final result is the logical AND of all expressions.
189+
items:
190+
type: string
191+
type: array
192+
condition:
193+
description: |-
194+
Condition is the type of condition that is set based on this rule.
195+
Any condition is supported, but certain special conditions can be used to
196+
to control higher level behaviors of the manifestwork.
197+
If the condition is Complete, the manifest will no longer be updated once completed.
198+
type: string
199+
message:
200+
description: Message is set on the condition created
201+
for this rule
202+
type: string
203+
messageExpression:
204+
description: |-
205+
MessageExpression uses a CEL expression to generate a message for the condition
206+
Will override message if both are set and messageExpression returns a non-empty string.
207+
Variables:
208+
- object: The current instance of the manifest
209+
- result: Boolean result of the CEL expressions
210+
type: string
211+
type:
212+
description: |-
213+
Type defines how a manifest should be evaluated for a condition.
214+
It can be CEL, or WellKnownConditions.
215+
If the type is CEL, user should specify the celExpressions field
216+
If the type is WellKnownConditions, certain common types in k8s.io/api will be considered
217+
completed as defined by hardcoded rules.
218+
enum:
219+
- WellKnownConditions
220+
- CEL
221+
type: string
222+
required:
223+
- condition
224+
- type
225+
type: object
226+
x-kubernetes-validations:
227+
- message: Condition is required for CEL rules
228+
rule: self.type != 'CEL' || self.condition != ""
229+
type: array
230+
x-kubernetes-list-map-keys:
231+
- condition
232+
x-kubernetes-list-type: map
170233
feedbackRules:
171234
description: |-
172235
FeedbackRules defines what resource status field should be returned. If it is not set or empty,

work/v1/0000_00_work.open-cluster-management.io_manifestworks.crd.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ spec:
9898
type: object
9999
type: array
100100
type: object
101+
ttlSecondsAfterFinished:
102+
description: |-
103+
TTLSecondsAfterFinished limits the lifetime of a ManifestWork that has been marked Complete
104+
by one or more conditionRules set for its manifests. If this field is set, and
105+
the manifestwork has completed, then it is elligible to be automatically deleted.
106+
If this field is unset, the manifestwork won't be automatically deleted even afer completion.
107+
If this field is set to zero, the manfiestwork becomes elligible to be deleted immediately
108+
after completion.
109+
format: int64
110+
type: integer
101111
type: object
102112
executor:
103113
description: |-
@@ -152,6 +162,59 @@ spec:
152162
description: ManifestConfigOption represents the configurations
153163
of a manifest defined in workload field.
154164
properties:
165+
conditionRules:
166+
description: ConditionRules defines how to set manifestwork
167+
conditions for a specific manifest.
168+
items:
169+
properties:
170+
celExpressions:
171+
description: |-
172+
CelExpressions defines the CEL expressions to be evaluated for the condition.
173+
Final result is the logical AND of all expressions.
174+
items:
175+
type: string
176+
type: array
177+
condition:
178+
description: |-
179+
Condition is the type of condition that is set based on this rule.
180+
Any condition is supported, but certain special conditions can be used to
181+
to control higher level behaviors of the manifestwork.
182+
If the condition is Complete, the manifest will no longer be updated once completed.
183+
type: string
184+
message:
185+
description: Message is set on the condition created for
186+
this rule
187+
type: string
188+
messageExpression:
189+
description: |-
190+
MessageExpression uses a CEL expression to generate a message for the condition
191+
Will override message if both are set and messageExpression returns a non-empty string.
192+
Variables:
193+
- object: The current instance of the manifest
194+
- result: Boolean result of the CEL expressions
195+
type: string
196+
type:
197+
description: |-
198+
Type defines how a manifest should be evaluated for a condition.
199+
It can be CEL, or WellKnownConditions.
200+
If the type is CEL, user should specify the celExpressions field
201+
If the type is WellKnownConditions, certain common types in k8s.io/api will be considered
202+
completed as defined by hardcoded rules.
203+
enum:
204+
- WellKnownConditions
205+
- CEL
206+
type: string
207+
required:
208+
- condition
209+
- type
210+
type: object
211+
x-kubernetes-validations:
212+
- message: Condition is required for CEL rules
213+
rule: self.type != 'CEL' || self.condition != ""
214+
type: array
215+
x-kubernetes-list-map-keys:
216+
- condition
217+
x-kubernetes-list-type: map
155218
feedbackRules:
156219
description: |-
157220
FeedbackRules defines what resource status field should be returned. If it is not set or empty,

work/v1/types.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ type DeleteOption struct {
8282

8383
// selectivelyOrphan represents a list of resources following orphan deletion stratecy
8484
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"`
8594
}
8695

8796
// ManifestConfigOption represents the configurations of a manifest defined in workload field.
@@ -101,8 +110,63 @@ type ManifestConfigOption struct {
101110
// if it is not set.
102111
// +optional
103112
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"`
104119
}
105120

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+
106170
// ManifestWorkExecutor is the executor that applies the resources to the managed cluster. i.e. the
107171
// work agent.
108172
type ManifestWorkExecutor struct {
@@ -527,6 +591,21 @@ const (
527591
// ManifestDegraded represents that the current state of resource object does not
528592
// match the desired state for a certain period.
529593
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"
530609
)
531610

532611
const (

work/v1/zz_generated.deepcopy.go

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

work/v1/zz_generated.swagger_doc_generated.go

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)