diff --git a/pkg/build/build.go b/pkg/build/build.go index 0da1cb4f..f325123c 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "os" + "os/signal" + "syscall" "time" "github.com/cnoe-io/idpbuilder/api/v1alpha1" @@ -266,9 +268,17 @@ func (b *Build) Run(ctx context.Context, recreateCluster bool) error { return fmt.Errorf("creating localbuild resource: %w", err) } - err = <-managerExit - close(managerExit) - return err + interrupted := make(chan os.Signal, 1) + defer close(interrupted) + signal.Notify(interrupted, os.Interrupt, syscall.SIGTERM) + + select { + case mgrErr := <-managerExit: + return mgrErr + case <-interrupted: + b.CancelFunc() + return fmt.Errorf("command interrupted") + } } func isBuildCustomizationSpecEqual(s1, s2 v1alpha1.BuildCustomizationSpec) bool { diff --git a/pkg/controllers/run.go b/pkg/controllers/run.go index b7187ddf..7d68d134 100644 --- a/pkg/controllers/run.go +++ b/pkg/controllers/run.go @@ -63,15 +63,12 @@ func RunControllers( if err != nil { logger.Error(err, "unable to create custom package controller") } - // Start our manager in another goroutine logger.V(1).Info("starting manager") + go func() { - if err := mgr.Start(ctx); err != nil { - logger.Error(err, "problem running manager") - exitCh <- err - } - exitCh <- nil + exitCh <- mgr.Start(ctx) + close(exitCh) }() return nil