Skip to content

Commit b230589

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 b230589

19 files changed

Lines changed: 1908 additions & 34 deletions

api/v1/clusterextensionrevision_types.go

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ 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:MaxItems=20
117+
// +listType=atomic
118+
// +optional
119+
ProgressionProbes []ProgressionProbe `json:"progressionProbes,omitempty"`
120+
109121
// collisionProtection specifies the default collision protection strategy for all objects
110122
// in this revision. Individual phases or objects can override this value.
111123
//
@@ -120,6 +132,173 @@ type ClusterExtensionRevisionSpec struct {
120132
CollisionProtection CollisionProtection `json:"collisionProtection,omitempty"`
121133
}
122134

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

api/v1/zz_generated.deepcopy.go

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