From ee66b8d4521048869cd4d0880cd53ecbfc272caa Mon Sep 17 00:00:00 2001 From: Stephen Cahill Date: Mon, 3 Mar 2025 21:35:20 -0500 Subject: [PATCH] :seedling: Return Unknown condition for NewAggregateCondition when no soureObjs provided --- util/conditions/v1beta2/aggregate.go | 6 +++++- util/conditions/v1beta2/aggregate_test.go | 22 ++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/util/conditions/v1beta2/aggregate.go b/util/conditions/v1beta2/aggregate.go index 3a3615a28966..e9a142783453 100644 --- a/util/conditions/v1beta2/aggregate.go +++ b/util/conditions/v1beta2/aggregate.go @@ -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{ diff --git a/util/conditions/v1beta2/aggregate_test.go b/util/conditions/v1beta2/aggregate_test.go index 4958f2b9a6f7..339689f4b8b3 100644 --- a/util/conditions/v1beta2/aggregate_test.go +++ b/util/conditions/v1beta2/aggregate_test.go @@ -69,8 +69,10 @@ func TestAggregate(t *testing.T) { 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, @@ -420,6 +422,16 @@ func TestAggregate(t *testing.T) { }, 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 { @@ -446,10 +458,4 @@ func TestAggregate(t *testing.T) { }) } - 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()) - }) }