Skip to content

Commit 426b355

Browse files
committed
v1beta2 conditions: make NewAggregate use generics
1 parent af80c02 commit 426b355

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

util/conditions/v1beta2/aggregate.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (o *AggregateOptions) ApplyOptions(opts []AggregateOption) *AggregateOption
5151
// the TargetConditionType option.
5252
//
5353
// Additionally, it is possible to inject custom merge strategies using the CustomMergeStrategy option.
54-
func NewAggregateCondition(sourceObjs []Getter, sourceConditionType string, opts ...AggregateOption) (*metav1.Condition, error) {
54+
func NewAggregateCondition[T Getter](sourceObjs []T, sourceConditionType string, opts ...AggregateOption) (*metav1.Condition, error) {
5555
if len(sourceObjs) == 0 {
5656
return nil, errors.New("sourceObjs can't be empty")
5757
}
@@ -113,7 +113,7 @@ func NewAggregateCondition(sourceObjs []Getter, sourceConditionType string, opts
113113

114114
// SetAggregateCondition is a convenience method that calls NewAggregateCondition to create an aggregate condition from the source objects,
115115
// and then calls Set to add the new condition to the target object.
116-
func SetAggregateCondition(sourceObjs []Getter, targetObj Setter, conditionType string, opts ...AggregateOption) error {
116+
func SetAggregateCondition[T Getter](sourceObjs []T, targetObj Setter, conditionType string, opts ...AggregateOption) error {
117117
aggregateCondition, err := NewAggregateCondition(sourceObjs, conditionType, opts...)
118118
if err != nil {
119119
return err

util/conditions/v1beta2/aggregate_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,9 @@ func TestAggregate(t *testing.T) {
271271
}
272272

273273
t.Run("Fails if source objects are empty", func(t *testing.T) {
274+
var objs []*builder.Phase3Obj
274275
g := NewWithT(t)
275-
_, err := NewAggregateCondition(nil, AvailableCondition)
276+
_, err := NewAggregateCondition(objs, AvailableCondition)
276277
g.Expect(err).To(HaveOccurred())
277278
})
278279
}

0 commit comments

Comments
 (0)