Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #282 from dexhorthy/entrypoint/cleanup
Browse files Browse the repository at this point in the history
fix entrypoint for navigate-lifecycle, add clean shutdown to other ship tasks
  • Loading branch information
dexhorthy authored Aug 8, 2018
2 parents 8ea29d9 + 40ecad2 commit 6bb62bb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/lifecycle/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ type ShipDaemon struct {
*V2Routes
}

func (d *ShipDaemon) AwaitShutdown() error {
return <-d.ExitChan
}

// "this is fine"
func (d *ShipDaemon) EnsureStarted(ctx context.Context, release *api.Release) chan error {

Expand Down
1 change: 1 addition & 0 deletions pkg/lifecycle/daemon/daemontypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Daemon interface {
TerraformConfirmedChan() chan bool
KustomizeSavedChan() chan interface{}
GetCurrentConfig() map[string]interface{}
AwaitShutdown() error
}

const StepNameMessage = "message"
Expand Down
4 changes: 4 additions & 0 deletions pkg/lifecycle/daemon/headless/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ type HeadlessDaemon struct {
ResolvedConfig map[string]interface{}
}

func (d *HeadlessDaemon) AwaitShutdown() error {
return nil
}

func NewHeadlessDaemon(
ui cli.Ui,
logger log.Logger,
Expand Down
4 changes: 4 additions & 0 deletions pkg/ship/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func (s *Ship) Update(ctx context.Context) error {

func (s *Ship) Watch(ctx context.Context) error {
debug := level.Debug(log.With(s.Logger, "method", "watch"))
ctx, cancelFunc := context.WithCancel(ctx)
defer s.Shutdown(cancelFunc)

for {
existingState, err := s.State.TryLoad()
Expand Down Expand Up @@ -118,6 +120,8 @@ func (s *Ship) Watch(ctx context.Context) error {

func (s *Ship) Init(ctx context.Context) error {
debug := level.Debug(log.With(s.Logger, "method", "init"))
ctx, cancelFunc := context.WithCancel(ctx)
defer s.Shutdown(cancelFunc)

if s.Viper.GetString("raw") != "" {
release := s.fakeKustomizeRawRelease()
Expand Down
12 changes: 10 additions & 2 deletions pkg/ship/ship.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,16 @@ func (s *Ship) execute(ctx context.Context, release *api.Release, selector *spec
runResultCh := make(chan error)
go func() {
defer close(runResultCh)
err := s.Runner.Run(ctx, release)
s.Daemon.AllStepsDone(ctx)
var err error
// *wince* dex do this better
if viper.GetBool("navigate-lifecycle") {
s.Daemon.EnsureStarted(ctx, release)
err = s.Daemon.AwaitShutdown()
} else {
err = s.Runner.Run(ctx, release)
s.Daemon.AllStepsDone(ctx)
}

if err != nil {
level.Error(s.Logger).Log("event", "shutdown", "reason", "error", "err", err)
} else {
Expand Down
12 changes: 12 additions & 0 deletions pkg/test-mocks/daemon/daemon.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6bb62bb

Please sign in to comment.