Skip to content

Commit

Permalink
Make odo run cancelable
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Jun 2, 2023
1 parent b2c49f0 commit 13c475b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/component/execute_terminating.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package component

import (
"context"
"errors"
"fmt"
"io"

Expand Down Expand Up @@ -63,6 +64,10 @@ func ExecuteTerminatingCommand(ctx context.Context, execClient exec.Client, plat
return fmt.Errorf("unable to log error %v: %w", err, errLog)
}
}

if errors.Is(err, context.Canceled) {
fmt.Println("TODO: kill command")
}
return err
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/odo/cli/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ func (o *RunOptions) SetClientset(clientset *clientset.Clientset) {
o.clientset = clientset
}

func (o *RunOptions) HandleSignal(ctx context.Context, cancelFunc context.CancelFunc) error {
fmt.Println("canceling execution")
cancelFunc()
// At this point, `ctx.Done()` will be raised, and the cleanup will be done
// wait for the cleanup to finish and let the main thread finish instead of signal handler go routine from runnable
select {}
}

func (o *RunOptions) Complete(ctx context.Context, cmdline cmdline.Cmdline, args []string) error {
o.commandName = args[0] // Value at 0 is expected to exist, thanks to ExactArgs(1)
return nil
Expand Down

0 comments on commit 13c475b

Please sign in to comment.