Skip to content

Commit

Permalink
add ConditionsMatch function
Browse files Browse the repository at this point in the history
  • Loading branch information
sbryzak committed May 3, 2024
1 parent 78585f7 commit 1ffd3be
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pkg/condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,32 @@ func HasConditionReason(conditions []toolchainv1alpha1.Condition, conditionType
con, found := FindConditionByType(conditions, conditionType)
return found && con.Reason == reason
}

// ConditionsMatch checks whether the specified conditions match and return true if they do
func ConditionsMatch(first, second []toolchainv1alpha1.Condition) bool {
if len(first) != len(second) {
return false

Check warning on line 153 in pkg/condition/condition.go

View check run for this annotation

Codecov / codecov/patch

pkg/condition/condition.go#L151-L153

Added lines #L151 - L153 were not covered by tests
}
for _, c := range first {
if !ContainsCondition(second, c) {
return false

Check warning on line 157 in pkg/condition/condition.go

View check run for this annotation

Codecov / codecov/patch

pkg/condition/condition.go#L155-L157

Added lines #L155 - L157 were not covered by tests
}
}
for _, c := range second {
if !ContainsCondition(first, c) {
return false

Check warning on line 162 in pkg/condition/condition.go

View check run for this annotation

Codecov / codecov/patch

pkg/condition/condition.go#L160-L162

Added lines #L160 - L162 were not covered by tests
}
}
return true

Check warning on line 165 in pkg/condition/condition.go

View check run for this annotation

Codecov / codecov/patch

pkg/condition/condition.go#L165

Added line #L165 was not covered by tests
}

// ContainsCondition returns true if the specified list of conditions contains the specified condition and the statuses of the conditions match.
// LastTransitionTime is ignored.
func ContainsCondition(conditions []toolchainv1alpha1.Condition, contains toolchainv1alpha1.Condition) bool {
for _, c := range conditions {
if c.Type == contains.Type {
return contains.Status == c.Status && contains.Reason == c.Reason && contains.Message == c.Message

Check warning on line 173 in pkg/condition/condition.go

View check run for this annotation

Codecov / codecov/patch

pkg/condition/condition.go#L170-L173

Added lines #L170 - L173 were not covered by tests
}
}
return false

Check warning on line 176 in pkg/condition/condition.go

View check run for this annotation

Codecov / codecov/patch

pkg/condition/condition.go#L176

Added line #L176 was not covered by tests
}

0 comments on commit 1ffd3be

Please sign in to comment.