Skip to content

Commit 40949f2

Browse files
committed
Use NewPipelineReconciler in tests
The tests make their own `PipelineReconciler` struct, but there's a constructor `NewPipelineReconciler` which could do some initialisation, and that will missed. So: use the constructor in suite-test.go. However! This now fails to initialise the eventRecorder, leaving it to default in `SetupWithManager`, and capturing events is part of the tests. I don't want to disturb existing behaviour*, so I've kept this change to the level-triggered controller. *How does it change? The event recorder is constructed using a notification-controller URL and used _only_ for promotion notifications. The event recorder for things that happen in the reconciler is left to default, which means it won't send those to the notification-controller. In practice it's unlikely to matter, since any alerts set up should filter for the promotion events. Signed-off-by: Michael Bridgen <[email protected]>
1 parent a44dbea commit 40949f2

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

controllers/leveltriggered/controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ type PipelineReconciler struct {
3333
stratReg strategy.StrategyRegistry
3434
}
3535

36-
func NewPipelineReconciler(c client.Client, s *runtime.Scheme, controllerName string, stratReg strategy.StrategyRegistry) *PipelineReconciler {
36+
func NewPipelineReconciler(c client.Client, s *runtime.Scheme, controllerName string, eventRecorder record.EventRecorder, stratReg strategy.StrategyRegistry) *PipelineReconciler {
3737
targetScheme := runtime.NewScheme()
3838

3939
return &PipelineReconciler{
4040
Client: c,
4141
Scheme: s,
4242
targetScheme: targetScheme,
43+
recorder: eventRecorder,
4344
ControllerName: controllerName,
4445
stratReg: stratReg,
4546
}

controllers/leveltriggered/suite_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ func TestMain(m *testing.M) {
133133

134134
eventRecorder = &testEventRecorder{events: map[string][]testEvent{}}
135135

136-
pipelineReconciler = &PipelineReconciler{
137-
Client: k8sManager.GetClient(),
138-
Scheme: scheme.Scheme,
139-
targetScheme: scheme.Scheme,
140-
recorder: eventRecorder,
141-
stratReg: strategy.StrategyRegistry{},
142-
}
136+
pipelineReconciler = NewPipelineReconciler(
137+
k8sManager.GetClient(),
138+
scheme.Scheme,
139+
"pipelines",
140+
eventRecorder,
141+
strategy.StrategyRegistry{},
142+
)
143143
err = pipelineReconciler.SetupWithManager(k8sManager)
144144
if err != nil {
145145
log.Fatalf("setup pipeline controller failed: %s", err)

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func main() {
137137
mgr.GetClient(),
138138
mgr.GetScheme(),
139139
controllerName,
140+
eventRecorder,
140141
stratReg,
141142
).SetupWithManager(mgr)
142143
} else {

0 commit comments

Comments
 (0)