Skip to content

Commit b7a4a28

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 b7a4a28

19 files changed

Lines changed: 1977 additions & 34 deletions

api/v1/clusterextensionrevision_types.go

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ 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+
ProgressionProbes []ProgressionProbe `json:"progressionProbes,omitempty"`
121+
109122
// collisionProtection specifies the default collision protection strategy for all objects
110123
// in this revision. Individual phases or objects can override this value.
111124
//
@@ -120,6 +133,187 @@ type ClusterExtensionRevisionSpec struct {
120133
CollisionProtection CollisionProtection `json:"collisionProtection,omitempty"`
121134
}
122135

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

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.

applyconfigurations/api/v1/clusterextensionrevisionspec.go

Lines changed: 20 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)