Skip to content

Commit c306045

Browse files
Collapse version changes in monitor output
Versions are showing up multiple times.
1 parent 65c7c30 commit c306045

2 files changed

Lines changed: 70 additions & 8 deletions

File tree

pkg/monitor/operator.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ func startClusterOperatorMonitoring(ctx context.Context, m Recorder, client conf
6262
Message: msg,
6363
})
6464
}
65-
if changes := findOperatorVersionChange(oldCO.Status.Versions, co.Status.Versions); len(changes) > 0 {
66-
conditions = append(conditions, Condition{
67-
Level: Info,
68-
Locator: locateClusterOperator(co),
69-
Message: fmt.Sprintf("versions: %v", strings.Join(changes, ", ")),
70-
})
71-
}
65+
}
66+
if changes := findOperatorVersionChange(oldCO.Status.Versions, co.Status.Versions); len(changes) > 0 {
67+
conditions = append(conditions, Condition{
68+
Level: Info,
69+
Locator: locateClusterOperator(co),
70+
Message: fmt.Sprintf("versions: %v", strings.Join(changes, ", ")),
71+
})
7272
}
7373
return conditions
7474
},
@@ -296,7 +296,7 @@ func findOperatorVersionChange(old, new []configv1.OperandVersion) []string {
296296
continue
297297
}
298298
if old[p].Version == new[i].Version {
299-
continue
299+
break
300300
}
301301
changed = append(changed, fmt.Sprintf("%s %s -> %s", new[i].Name, old[p].Version, new[i].Version))
302302
break

pkg/monitor/operator_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package monitor
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
7+
configv1 "github.com/openshift/api/config/v1"
8+
)
9+
10+
func Test_findOperatorVersionChange(t *testing.T) {
11+
type args struct {
12+
}
13+
tests := []struct {
14+
name string
15+
old []configv1.OperandVersion
16+
new []configv1.OperandVersion
17+
want []string
18+
}{
19+
{
20+
old: []configv1.OperandVersion{{Name: "a", Version: "1.0.0"}, {Name: "b", Version: "1.0.1"}},
21+
new: []configv1.OperandVersion{{Name: "a", Version: "1.0.0"}, {Name: "b", Version: "1.0.1"}},
22+
},
23+
{
24+
old: []configv1.OperandVersion{{Name: "a", Version: "1.0.0"}, {Name: "b", Version: "1.0.1"}},
25+
new: []configv1.OperandVersion{{Name: "a", Version: "1.0.1"}, {Name: "b", Version: "1.0.1"}},
26+
want: []string{"a 1.0.0 -> 1.0.1"},
27+
},
28+
{
29+
old: []configv1.OperandVersion{{Name: "a", Version: "1.0.0"}, {Name: "b", Version: "1.0.1"}},
30+
new: []configv1.OperandVersion{{Name: "b", Version: "1.0.1"}, {Name: "a", Version: "1.0.0"}},
31+
},
32+
{
33+
old: []configv1.OperandVersion{{Name: "a", Version: "1.0.0"}, {Name: "b", Version: "1.0.1"}},
34+
new: []configv1.OperandVersion{{Name: "b", Version: "1.0.1"}, {Name: "a", Version: "1.0.1"}},
35+
want: []string{"a 1.0.0 -> 1.0.1"},
36+
},
37+
{
38+
old: []configv1.OperandVersion{{Name: "a", Version: "1.0.0"}},
39+
new: []configv1.OperandVersion{{Name: "a", Version: "1.0.1"}},
40+
want: []string{"a 1.0.0 -> 1.0.1"},
41+
},
42+
{
43+
old: []configv1.OperandVersion{{Name: "a", Version: "1.0.0"}},
44+
new: []configv1.OperandVersion{{Name: "a", Version: "1.0.0"}},
45+
},
46+
{
47+
old: []configv1.OperandVersion{{Name: "a", Version: "1.0.0"}},
48+
new: []configv1.OperandVersion{},
49+
},
50+
{
51+
old: []configv1.OperandVersion{},
52+
new: []configv1.OperandVersion{{Name: "a", Version: "1.0.0"}},
53+
},
54+
}
55+
for _, tt := range tests {
56+
t.Run(tt.name, func(t *testing.T) {
57+
if got := findOperatorVersionChange(tt.old, tt.new); !reflect.DeepEqual(got, tt.want) {
58+
t.Errorf("findOperatorVersionChange() = %v, want %v", got, tt.want)
59+
}
60+
})
61+
}
62+
}

0 commit comments

Comments
 (0)