Skip to content

🌱 Return Unknown condition for NewAggregateCondition when no… #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion util/conditions/v1beta2/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ func (o *AggregateOptions) ApplyOptions(opts []AggregateOption) *AggregateOption
// Additionally, it is possible to inject custom merge strategies using the CustomMergeStrategy option.
func NewAggregateCondition[T Getter](sourceObjs []T, sourceConditionType string, opts ...AggregateOption) (*metav1.Condition, error) {
if len(sourceObjs) == 0 {
return nil, errors.New("sourceObjs can't be empty")
return &metav1.Condition{
Type: sourceConditionType,
Status: metav1.ConditionUnknown,
Reason: NotYetReportedReason,
}, nil
}

aggregateOpt := &AggregateOptions{
Expand Down
22 changes: 14 additions & 8 deletions util/conditions/v1beta2/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@
wantErr: false,
},
{
name: "Error if negative polarity conditions are misconfigured",
conditions: [][]metav1.Condition{},
name: "Error if negative polarity conditions are misconfigured",
conditions: [][]metav1.Condition{
{{Type: clusterv1.ScalingUpV1Beta2Condition, Status: metav1.ConditionTrue, Reason: "Reason-1", Message: "Message-1"}},
},
conditionType: clusterv1.ScalingUpV1Beta2Condition,
options: []AggregateOption{NegativePolarityConditionTypes{"foo"}}, // NegativePolarityConditionTypes if set must equal source condition
want: nil,
Expand Down Expand Up @@ -420,6 +422,16 @@
},
wantErr: false,
},
{
name: "Empty source objects return an unknown condition with status not yet reported",
conditionType: clusterv1.AvailableV1Beta2Condition,
want: &metav1.Condition{
Type: clusterv1.AvailableV1Beta2Condition,
Status: metav1.ConditionUnknown,
Reason: NotYetReportedReason,
},
wantErr: false,
},
}

for _, tt := range tests {
Expand All @@ -446,10 +458,4 @@
})
}

t.Run("Fails if source objects are empty", func(t *testing.T) {
var objs []*builder.Phase3Obj
g := NewWithT(t)
_, err := NewAggregateCondition(objs, clusterv1.AvailableV1Beta2Condition)
g.Expect(err).To(HaveOccurred())
})
}

Check failure on line 461 in util/conditions/v1beta2/aggregate_test.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary trailing newline (whitespace)
Loading