Skip to content

Commit

Permalink
handle command interrupt
Browse files Browse the repository at this point in the history
Signed-off-by: Manabu McCloskey <[email protected]>
  • Loading branch information
nabuskey committed Nov 20, 2024
1 parent 8c6cd97 commit 11ec29c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
16 changes: 13 additions & 3 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"

"github.com/cnoe-io/idpbuilder/api/v1alpha1"
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 3 additions & 6 deletions pkg/controllers/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11ec29c

Please sign in to comment.