Skip to content

Commit 9949ca9

Browse files
committed
capi: always stop local control plane in capi Teardown
Instead of doing the control plane shutdown as part of the controllers shutdown process, it should be done at Teardown time instead. This makes sure that local control plane binaries are stopped even when we fail to create controllers, for example when creating a cloud session for controller setup.
1 parent b8df7d4 commit 9949ca9

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

pkg/clusterapi/system.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ func (c *system) Run(ctx context.Context) error {
324324
defer c.wg.Done()
325325
// Stop the controllers when the context is cancelled.
326326
<-ctx.Done()
327+
logrus.Info("Shutting down local Cluster API controllers...")
327328
for _, ct := range controllers {
328329
if ct.state != nil {
329330
if err := ct.state.Stop(); err != nil {
@@ -333,11 +334,6 @@ func (c *system) Run(ctx context.Context) error {
333334
logrus.Infof("Stopped controller: %s", ct.Name)
334335
}
335336
}
336-
337-
// Stop the local control plane.
338-
if err := c.lcp.Stop(); err != nil {
339-
logrus.Warnf("Failed to stop local Cluster API control plane: %v", err)
340-
}
341337
}()
342338

343339
// Run the controllers.
@@ -377,10 +373,13 @@ func (c *system) Teardown() {
377373
// Proceed to shutdown.
378374
c.teardownOnce.Do(func() {
379375
c.cancel()
380-
logrus.Info("Shutting down local Cluster API control plane...")
381376
ch := make(chan struct{})
382377
go func() {
383378
c.wg.Wait()
379+
logrus.Info("Shutting down local Cluster API control plane...")
380+
if err := c.lcp.Stop(); err != nil {
381+
logrus.Warnf("Failed to stop local Cluster API control plane: %v", err)
382+
}
384383
close(ch)
385384
}()
386385
select {

0 commit comments

Comments
 (0)