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

Fix conditions counter in case of mismatching order of conditions between WithConditions and WithStepCounterIfOnly #3740

Merged
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
11 changes: 8 additions & 3 deletions util/conditions/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,20 @@ func summary(from Getter, options ...MergeOption) *clusterv1.Condition {
}

// If it is required to add a step counter only if a subset of condition exists, check if the conditions
// in scope are included in this subset.
// in scope are included in this subset or not.
if mergeOpt.addStepCounterIfOnlyConditionTypes != nil {
for _, c := range conditionsInScope {
found := false
for _, t := range mergeOpt.addStepCounterIfOnlyConditionTypes {
if c.Type != t {
mergeOpt.addStepCounter = false
if c.Type == t {
found = true
break
}
}
if !found {
mergeOpt.addStepCounter = false
break
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions util/conditions/getter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@ func TestSummary(t *testing.T) {
options: []MergeOption{WithConditions("bar", "baz"), WithStepCounter(), WithStepCounterIfOnly("bar")}, // there is only bar, the step counter should be set and counts only a subset of conditions
want: FalseCondition(clusterv1.ReadyCondition, "reason falseInfo1", clusterv1.ConditionSeverityInfo, "0 of 1 completed"),
},
{
name: "Returns ready condition with the summary of selected conditions (using WithConditions and WithStepCounterIfOnly options - with inconsistent order between the two)",
from: getterWithConditions(bar),
options: []MergeOption{WithConditions("baz", "bar"), WithStepCounter(), WithStepCounterIfOnly("bar", "baz")}, // conditions in WithStepCounterIfOnly could be in different order than in WithConditions
want: FalseCondition(clusterv1.ReadyCondition, "reason falseInfo1", clusterv1.ConditionSeverityInfo, "0 of 2 completed"),
},
{
name: "Returns ready condition with the summary of selected conditions (using WithConditions and WithStepCounterIfOnly options)",
from: getterWithConditions(bar, baz),
Expand Down