@@ -51,6 +51,19 @@ func (o ConditionOwnerInfo) String() string {
5151 return fmt .Sprintf ("%s %s" , o .Kind , o .Name )
5252}
5353
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+
5467// MergeStrategy defines a strategy used to merge conditions during the aggregate or summary operation.
5568type MergeStrategy interface {
5669 // Merge passed in conditions.
@@ -59,7 +72,7 @@ type MergeStrategy interface {
5972 // Conditions passed in must be of the given conditionTypes (other condition types must be discarded).
6073 //
6174 // 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 )
6376}
6477
6578// DefaultMergeStrategyOption is some configuration that modifies the DefaultMergeStrategy behaviour.
@@ -199,7 +212,7 @@ type defaultMergeStrategy struct {
199212// - issues: conditions with positive polarity (normal True) and status False or conditions with negative polarity (normal False) and status True.
200213// - unknown: conditions with status unknown.
201214// - 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 ) {
203216 if len (conditions ) == 0 {
204217 return "" , "" , "" , errors .New ("can't merge an empty list of conditions" )
205218 }
@@ -208,15 +221,6 @@ func (d *defaultMergeStrategy) Merge(conditions []ConditionWithOwnerInfo, condit
208221 return "" , "" , "" , errors .New ("can't merge without a getPriority func" )
209222 }
210223
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-
220224 // sortConditions the relevance defined by the users (the order of condition types), LastTransition time (older first).
221225 sortConditions (conditions , conditionTypes )
222226
@@ -265,7 +269,7 @@ func (d *defaultMergeStrategy) Merge(conditions []ConditionWithOwnerInfo, condit
265269 //
266270 // When including messages from conditions, they are sorted by issue/unknown and by the implicit order of condition types
267271 // provided by the user (it is considered as order of relevance).
268- if isSummaryOperation {
272+ if operation == SummaryMergeOperation {
269273 message = summaryMessage (conditions , d , status )
270274 }
271275
@@ -291,7 +295,7 @@ func (d *defaultMergeStrategy) Merge(conditions []ConditionWithOwnerInfo, condit
291295 //
292296 // e.g. ...; 2 more Objects with issues; 1 more Objects with unknown status
293297 //
294- if isAggregateOperation {
298+ if operation == AggregateMergeOperation {
295299 n := 3
296300 messages := []string {}
297301
0 commit comments