Skip to content

Commit c1f414c

Browse files
committed
v1beta2 conditions: make NewAggregate use generics
1 parent 7b5489c commit c1f414c

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

util/conditions/v1beta2/aggregate.go

Lines changed: 2 additions & 2 deletions
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
}
@@ -118,7 +118,7 @@ func NewAggregateCondition(sourceObjs []Getter, sourceConditionType string, opts
118118

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

util/conditions/v1beta2/aggregate_test.go

Lines changed: 2 additions & 1 deletion
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)