Skip to content
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

🌱 v1beta2 conditions: make NewAggregate use generics #11281

Merged
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
4 changes: 2 additions & 2 deletions util/conditions/v1beta2/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (o *AggregateOptions) ApplyOptions(opts []AggregateOption) *AggregateOption
// the TargetConditionType option.
//
// Additionally, it is possible to inject custom merge strategies using the CustomMergeStrategy option.
func NewAggregateCondition(sourceObjs []Getter, sourceConditionType string, opts ...AggregateOption) (*metav1.Condition, error) {
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")
}
Expand Down Expand Up @@ -118,7 +118,7 @@ func NewAggregateCondition(sourceObjs []Getter, sourceConditionType string, opts

// SetAggregateCondition is a convenience method that calls NewAggregateCondition to create an aggregate condition from the source objects,
// and then calls Set to add the new condition to the target object.
func SetAggregateCondition(sourceObjs []Getter, targetObj Setter, conditionType string, opts ...AggregateOption) error {
func SetAggregateCondition[T Getter](sourceObjs []T, targetObj Setter, conditionType string, opts ...AggregateOption) error {
aggregateCondition, err := NewAggregateCondition(sourceObjs, conditionType, opts...)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion util/conditions/v1beta2/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,9 @@ 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(nil, AvailableCondition)
_, err := NewAggregateCondition(objs, AvailableCondition)
g.Expect(err).To(HaveOccurred())
})
}
Loading