Skip to content

Commit 79e203f

Browse files
committed
ProgressionProbes
Provides an API which allows custom probe definitions to determine readiness of the CER phases. Objects can be selected for in one of two ways: by GroupKind, or by Label (matchLabels and matchExpressions). They can then be tested via any of: Condition, FieldsEqual, and FieldValue. Condition checks that the object has a condition matching the type and status provided. FieldsEqual uses two provided field paths and checks for equality. FieldValue uses a provided field path and checks that the value is equal to the provided expected value. Signed-off-by: Daniel Franz <dfranz@redhat.com>
1 parent 6f23a79 commit 79e203f

19 files changed

Lines changed: 2028 additions & 34 deletions

api/v1/clusterextensionrevision_types.go

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ type ClusterExtensionRevisionSpec struct {
106106
// <opcon:experimental>
107107
ProgressDeadlineMinutes int32 `json:"progressDeadlineMinutes,omitempty"`
108108

109+
// progressionProbes is an optional field which provides the ability to define custom readiness probes
110+
// for objects defined within spec.phases. As documented in that field, most kubernetes-native objects
111+
// within the phases already have some kind of readiness check built-in, but this field allows for checks
112+
// which are tailored to the objects being rolled out - particularly custom resources.
113+
//
114+
// The maximum number of probes is 20.
115+
//
116+
// +kubebuilder:validation:MinItems=1
117+
// +kubebuilder:validation:MaxItems=20
118+
// +listType=atomic
119+
// +optional
120+
// <opcon:experimental>
121+
ProgressionProbes []ProgressionProbe `json:"progressionProbes,omitempty"`
122+
109123
// collisionProtection specifies the default collision protection strategy for all objects
110124
// in this revision. Individual phases or objects can override this value.
111125
//
@@ -120,6 +134,202 @@ type ClusterExtensionRevisionSpec struct {
120134
CollisionProtection CollisionProtection `json:"collisionProtection,omitempty"`
121135
}
122136

137+
// ProgressionProbe provides a custom probe definition, consisting of an object selection method and assertions.
138+
type ProgressionProbe struct {
139+
// selector is a required field which defines the method by which we select objects to apply the below
140+
// assertions to. Any object which matches the defined selector will have all the associated assertions
141+
// applied against it.
142+
//
143+
// If no objects within a phase are selected by the provided selector, then all assertions defined here
144+
// are considered to have succeeded.
145+
//
146+
// +required
147+
// <opcon:experimental>
148+
Selector ObjectSelector `json:"selector,omitzero"`
149+
150+
// assertions is a required list of checks which will run against the objects selected by the selector. If
151+
// one or more assertions fail then the phase within which the object lives will be not be considered
152+
// 'Ready', blocking rollout of all subsequent phases.
153+
//
154+
// +kubebuilder:validation:MinItems=1
155+
// +kubebuilder:validation:MaxItems=20
156+
// +listType=atomic
157+
// +required
158+
// <opcon:experimental>
159+
Assertions []Assertion `json:"assertions,omitempty"`
160+
}
161+
162+
// ObjectSelector is a discriminated union which defines the method by which we select objects to make assertions against.
163+
// +union
164+
// +kubebuilder:validation:XValidation:rule="self.type == 'GroupKind' ?has(self.groupKind) : !has(self.groupKind)",message="groupKind is required when type is GroupKind, and forbidden otherwise"
165+
// +kubebuilder:validation:XValidation:rule="self.type == 'Label' ?has(self.label) : !has(self.label)",message="label is required when type is Label, and forbidden otherwise"
166+
type ObjectSelector struct {
167+
// type is a required field which specifies the type of selector to use.
168+
//
169+
// The allowed selector types are "GroupKind" and "Label".
170+
//
171+
// When set to "GroupKind", all objects which match the specified group and kind will be selected.
172+
// When set to "Label", all objects which match the specified labels and/or expressions will be selected.
173+
//
174+
// +unionDiscriminator
175+
// +kubebuilder:validation:Enum=GroupKind;Label
176+
// +required
177+
// <opcon:experimental>
178+
SelectorType SelectorType `json:"type,omitempty"`
179+
180+
// groupKind specifies the group and kind of objects to select.
181+
//
182+
// Required when type is "GroupKind".
183+
//
184+
// Uses the kubernetes format specified here:
185+
// https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#GroupKind
186+
//
187+
// +optional
188+
// +unionMember
189+
// <opcon:experimental>
190+
GroupKind metav1.GroupKind `json:"groupKind,omitempty,omitzero"`
191+
192+
// label is the label selector definition.
193+
//
194+
// Required when type is "Label".
195+
//
196+
// Uses the kubernetes format specified here:
197+
// https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#LabelSelector
198+
// Requires exactly one of matchLabels or matchExpressions.
199+
//
200+
// +kubebuilder:validation:MinProperties=1
201+
// +kubebuilder:validation:MaxProperties=1
202+
// +optional
203+
// +unionMember
204+
// <opcon:experimental>
205+
Label metav1.LabelSelector `json:"label,omitempty,omitzero"`
206+
}
207+
208+
// SelectorType defines the type of selector used for progressionProbes.
209+
// +enum
210+
type SelectorType string
211+
212+
const (
213+
SelectorTypeGroupKind SelectorType = "GroupKind"
214+
SelectorTypeLabel SelectorType = "Label"
215+
)
216+
217+
// ProbeType defines the type of probe used as an assertion.
218+
// +enum
219+
type ProbeType string
220+
221+
const (
222+
ProbeTypeFieldCondition ProbeType = "Condition"
223+
ProbeTypeFieldEqual ProbeType = "FieldsEqual"
224+
ProbeTypeFieldValue ProbeType = "FieldValue"
225+
)
226+
227+
// Assertion is a discriminated union which defines the probe type and definition used as an assertion.
228+
// +union
229+
// +kubebuilder:validation:XValidation:rule="self.type == 'Condition' ?has(self.condition) : !has(self.condition)",message="condition is required when type is Condition, and forbidden otherwise"
230+
// +kubebuilder:validation:XValidation:rule="self.type == 'FieldsEqual' ?has(self.fieldsEqual) : !has(self.fieldsEqual)",message="fieldsEqual is required when type is FieldsEqual, and forbidden otherwise"
231+
// +kubebuilder:validation:XValidation:rule="self.type == 'FieldValue' ?has(self.fieldValue) : !has(self.fieldValue)",message="fieldValue is required when type is FieldValue, and forbidden otherwise"
232+
type Assertion struct {
233+
// type is a required field which specifies the type of probe to use.
234+
//
235+
// The allowed probe types are "Condition", "FieldsEqual", and "FieldValue".
236+
//
237+
// When set to "Condition", the probe checks objects that have reached a condition of specified type and status.
238+
// When set to "FieldsEqual", the probe checks that the values found at two provided field paths are matching.
239+
// When set to "FieldValue", the probe checks that the value found at the provided field path matches what was specified.
240+
//
241+
// +unionDiscriminator
242+
// +kubebuilder:validation:Enum=Condition;FieldsEqual;FieldValue
243+
// +required
244+
// <opcon:experimental>
245+
ProbeType ProbeType `json:"type,omitempty"`
246+
247+
// condition contains the expected condition type and status.
248+
//
249+
// +unionMember
250+
// +optional
251+
// <opcon:experimental>
252+
Condition ConditionProbe `json:"condition,omitempty,omitzero"`
253+
254+
// fieldsEqual contains the two field paths whose values are expected to match.
255+
//
256+
// +unionMember
257+
// +optional
258+
// <opcon:experimental>
259+
FieldsEqual FieldsEqualProbe `json:"fieldsEqual,omitempty,omitzero"`
260+
261+
// fieldValue contains the expected field path and value found within.
262+
//
263+
// +unionMember
264+
// +optional
265+
// <opcon:experimental>
266+
FieldValue FieldValueProbe `json:"fieldValue,omitempty,omitzero"`
267+
}
268+
269+
// ConditionProbe defines the condition type and status required for the probe to succeed.
270+
type ConditionProbe struct {
271+
// type sets the expected condition type, i.e. "Ready".
272+
//
273+
// +kubebuilder:validation:MinLength=1
274+
// +kubebuilder:validation:MaxLength=200
275+
// +required
276+
// <opcon:experimental>
277+
Type string `json:"type,omitempty,omitzero"`
278+
279+
// status sets the expected condition status.
280+
//
281+
// Allowed values are "True" and "False".
282+
//
283+
// +kubebuilder:validation:Enum=True;False
284+
// +required
285+
// <opcon:experimental>
286+
Status string `json:"status,omitempty,omitzero"`
287+
}
288+
289+
// FieldsEqualProbe defines the paths of the two fields required to match for the probe to succeed.
290+
type FieldsEqualProbe struct {
291+
// fieldA sets the field path for the first field, i.e. "spec.replicas". The probe will fail
292+
// if the path does not exist.
293+
//
294+
// +kubebuilder:validation:MinLength=1
295+
// +kubebuilder:validation:MaxLength=200
296+
// +kubebuilder:validation:XValidation:rule="self.matches('^[a-zA-Z0-9]+(?:\\\\.[a-zA-Z0-9]+)*$')",message="must contain a valid field path. valid fields contain upper or lower-case alphanumeric characters separated by the \".\" character."
297+
// +required
298+
// <opcon:experimental>
299+
FieldA string `json:"fieldA,omitempty,omitzero"`
300+
301+
// fieldB sets the field path for the second field, i.e. "status.readyReplicas". The probe will fail
302+
// if the path does not exist.
303+
//
304+
// +kubebuilder:validation:MinLength=1
305+
// +kubebuilder:validation:MaxLength=200
306+
// +kubebuilder:validation:XValidation:rule="self.matches('^[a-zA-Z0-9]+(?:\\\\.[a-zA-Z0-9]+)*$')",message="must contain a valid field path. valid fields contain upper or lower-case alphanumeric characters separated by the \".\" character."
307+
// +required
308+
// <opcon:experimental>
309+
FieldB string `json:"fieldB,omitempty,omitzero"`
310+
}
311+
312+
// FieldValueProbe defines the path and value expected within for the probe to succeed.
313+
type FieldValueProbe struct {
314+
// fieldPath sets the field path for the field to check, i.e. "status.phase". The probe will fail
315+
// if the path does not exist.
316+
//
317+
// +kubebuilder:validation:MinLength=1
318+
// +kubebuilder:validation:MaxLength=200
319+
// +kubebuilder:validation:XValidation:rule="self.matches('^[a-zA-Z0-9]+(?:\\\\.[a-zA-Z0-9]+)*$')",message="must contain a valid field path. valid fields contain upper or lower-case alphanumeric characters separated by the \".\" character."
320+
// +required
321+
// <opcon:experimental>
322+
FieldPath string `json:"fieldPath,omitempty,omitzero"`
323+
324+
// value sets the expected value found at fieldPath, i.e. "Bound".
325+
//
326+
// +kubebuilder:validation:MinLength=1
327+
// +kubebuilder:validation:MaxLength=200
328+
// +required
329+
// <opcon:experimental>
330+
Value string `json:"value,omitempty,omitzero"`
331+
}
332+
123333
// ClusterExtensionRevisionLifecycleState specifies the lifecycle state of the ClusterExtensionRevision.
124334
type ClusterExtensionRevisionLifecycleState string
125335

api/v1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)