@@ -51,6 +51,19 @@ func (o ConditionOwnerInfo) String() string {
51
51
return fmt .Sprintf ("%s %s" , o .Kind , o .Name )
52
52
}
53
53
54
+ // MergeOperation defines merge operations.
55
+ type MergeOperation string
56
+
57
+ const (
58
+ // SummaryMergeOperation defines a merge operation of type Summary.
59
+ // Summary should merge different conditions from the same object.
60
+ SummaryMergeOperation MergeOperation = "Summary"
61
+
62
+ // AggregateMergeOperation defines a merge operation of type Aggregate.
63
+ // Aggregate should merge the same condition across many objects.
64
+ AggregateMergeOperation MergeOperation = "Aggregate"
65
+ )
66
+
54
67
// MergeStrategy defines a strategy used to merge conditions during the aggregate or summary operation.
55
68
type MergeStrategy interface {
56
69
// Merge passed in conditions.
@@ -59,7 +72,7 @@ type MergeStrategy interface {
59
72
// Conditions passed in must be of the given conditionTypes (other condition types must be discarded).
60
73
//
61
74
// The list of conditionTypes has an implicit order; it is up to the implementation of merge to use this info or not.
62
- Merge (conditions []ConditionWithOwnerInfo , conditionTypes []string ) (status metav1.ConditionStatus , reason , message string , err error )
75
+ Merge (operation MergeOperation , conditions []ConditionWithOwnerInfo , conditionTypes []string ) (status metav1.ConditionStatus , reason , message string , err error )
63
76
}
64
77
65
78
// DefaultMergeStrategyOption is some configuration that modifies the DefaultMergeStrategy behaviour.
@@ -199,7 +212,7 @@ type defaultMergeStrategy struct {
199
212
// - issues: conditions with positive polarity (normal True) and status False or conditions with negative polarity (normal False) and status True.
200
213
// - unknown: conditions with status unknown.
201
214
// - info: conditions with positive polarity (normal True) and status True or conditions with negative polarity (normal False) and status False.
202
- func (d * defaultMergeStrategy ) Merge (conditions []ConditionWithOwnerInfo , conditionTypes []string ) (status metav1.ConditionStatus , reason , message string , err error ) {
215
+ func (d * defaultMergeStrategy ) Merge (operation MergeOperation , conditions []ConditionWithOwnerInfo , conditionTypes []string ) (status metav1.ConditionStatus , reason , message string , err error ) {
203
216
if len (conditions ) == 0 {
204
217
return "" , "" , "" , errors .New ("can't merge an empty list of conditions" )
205
218
}
@@ -208,15 +221,6 @@ func (d *defaultMergeStrategy) Merge(conditions []ConditionWithOwnerInfo, condit
208
221
return "" , "" , "" , errors .New ("can't merge without a getPriority func" )
209
222
}
210
223
211
- // Infer which operation is calling this func, so it is possible to use different strategies for computing the message for the target condition.
212
- // - When merge should consider a single condition type, we can assume this func is called within an aggregate operation
213
- // (Aggregate should merge the same condition across many objects)
214
- isAggregateOperation := len (conditionTypes ) == 1
215
-
216
- // - Otherwise we can assume this func is called within a summary operation
217
- // (Summary should merge different conditions from the same object)
218
- isSummaryOperation := ! isAggregateOperation
219
-
220
224
// sortConditions the relevance defined by the users (the order of condition types), LastTransition time (older first).
221
225
sortConditions (conditions , conditionTypes )
222
226
@@ -265,7 +269,7 @@ func (d *defaultMergeStrategy) Merge(conditions []ConditionWithOwnerInfo, condit
265
269
//
266
270
// When including messages from conditions, they are sorted by issue/unknown and by the implicit order of condition types
267
271
// provided by the user (it is considered as order of relevance).
268
- if isSummaryOperation {
272
+ if operation == SummaryMergeOperation {
269
273
message = summaryMessage (conditions , d , status )
270
274
}
271
275
@@ -291,7 +295,7 @@ func (d *defaultMergeStrategy) Merge(conditions []ConditionWithOwnerInfo, condit
291
295
//
292
296
// e.g. ...; 2 more Objects with issues; 1 more Objects with unknown status
293
297
//
294
- if isAggregateOperation {
298
+ if operation == AggregateMergeOperation {
295
299
n := 3
296
300
messages := []string {}
297
301
0 commit comments