@@ -114,9 +114,9 @@ func GetLastTransitionTime(from Getter, t clusterv1.ConditionType) *metav1.Time
114
114
return nil
115
115
}
116
116
117
- // Summary returns a Ready condition with the summary of all the conditions existing
117
+ // summary returns a Ready condition with the summary of all the conditions existing
118
118
// on an object. If the object does not have other conditions, no summary condition is generated.
119
- func Summary (from Getter , options ... MergeOption ) * clusterv1.Condition {
119
+ func summary (from Getter , options ... MergeOption ) * clusterv1.Condition {
120
120
conditions := from .GetConditions ()
121
121
122
122
conditionsInScope := make ([]localizedCondition , 0 , len (conditions ))
@@ -137,11 +137,47 @@ func Summary(from Getter, options ...MergeOption) *clusterv1.Condition {
137
137
return merge (conditionsInScope , clusterv1 .ReadyCondition , mergeOpt )
138
138
}
139
139
140
- // Mirror mirrors the Ready condition from a dependent object into the target condition;
140
+ // mirrorOptions allows to set options for the mirror operation.
141
+ type mirrorOptions struct {
142
+ fallbackTo * bool
143
+ fallbackReason string
144
+ fallbackSeverity clusterv1.ConditionSeverity
145
+ fallbackMessage string
146
+ }
147
+
148
+ // MirrorOptions defines an option for mirroring conditions.
149
+ type MirrorOptions func (* mirrorOptions )
150
+
151
+ // WithFallbackValue specify a fallback value to use in case the mirrored condition does not exists;
152
+ // in case the fallbackValue is false, given values for reason, severity and message will be used.
153
+ func WithFallbackValue (fallbackValue bool , reason string , severity clusterv1.ConditionSeverity , message string ) MirrorOptions {
154
+ return func (c * mirrorOptions ) {
155
+ c .fallbackTo = & fallbackValue
156
+ c .fallbackReason = reason
157
+ c .fallbackSeverity = severity
158
+ c .fallbackMessage = message
159
+ }
160
+ }
161
+
162
+ // mirror mirrors the Ready condition from a dependent object into the target condition;
141
163
// if the Ready condition does not exists in the source object, no target conditions is generated.
142
- func Mirror (from Getter , targetCondition clusterv1.ConditionType ) * clusterv1.Condition {
164
+ func mirror (from Getter , targetCondition clusterv1.ConditionType , options ... MirrorOptions ) * clusterv1.Condition {
165
+ mirrorOpt := & mirrorOptions {}
166
+ for _ , o := range options {
167
+ o (mirrorOpt )
168
+ }
169
+
143
170
condition := Get (from , clusterv1 .ReadyCondition )
144
171
172
+ if mirrorOpt .fallbackTo != nil && condition == nil {
173
+ switch * mirrorOpt .fallbackTo {
174
+ case true :
175
+ condition = TrueCondition (targetCondition )
176
+ case false :
177
+ condition = FalseCondition (targetCondition , mirrorOpt .fallbackReason , mirrorOpt .fallbackSeverity , mirrorOpt .fallbackMessage )
178
+ }
179
+ }
180
+
145
181
if condition != nil {
146
182
condition .Type = targetCondition
147
183
}
@@ -152,7 +188,7 @@ func Mirror(from Getter, targetCondition clusterv1.ConditionType) *clusterv1.Con
152
188
// Aggregates all the the Ready condition from a list of dependent objects into the target object;
153
189
// if the Ready condition does not exists in one of the source object, the object is excluded from
154
190
// the aggregation; if none of the source object have ready condition, no target conditions is generated.
155
- func Aggregate (from []Getter , targetCondition clusterv1.ConditionType , options ... MergeOption ) * clusterv1.Condition {
191
+ func aggregate (from []Getter , targetCondition clusterv1.ConditionType , options ... MergeOption ) * clusterv1.Condition {
156
192
conditionsInScope := make ([]localizedCondition , 0 , len (from ))
157
193
for i := range from {
158
194
condition := Get (from [i ], clusterv1 .ReadyCondition )
0 commit comments