Skip to content

Commit

Permalink
fixed helm termination
Browse files Browse the repository at this point in the history
Signed-off-by: Suleiman Dibirov <[email protected]>
  • Loading branch information
idsulik committed Nov 23, 2024
1 parent de29b5a commit 3a81af0
Showing 1 changed file with 6 additions and 32 deletions.
38 changes: 6 additions & 32 deletions pkg/skaffold/helm/bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,38 +128,12 @@ func generateHelmCommand(ctx context.Context, h Client, useSecrets bool, env []s
args = append([]string{"secrets"}, args...)
}

cmd := exec.Command("helm", args...)

// Set up context cancellation handler
go func() {
<-ctx.Done()

if cmd.Process != nil {
// Create a channel to detect if helm finishes cleanup
done := make(chan struct{})
go func() {
cmd.Wait()
close(done)
}()

// Send SIGINT for graceful shutdown
if err := cmd.Process.Signal(os.Interrupt); err != nil {
// Log error but continue to wait for timeout
fmt.Printf("Failed to send interrupt signal: %v\n", err)
}

// Wait for either cleanup completion or timeout
select {
case <-time.After(2 * time.Minute):
if err := cmd.Process.Kill(); err != nil {
fmt.Printf("Failed to kill process: %v\n", err)
}
case <-done:
fmt.Println("Helm cleanup completed")
return
}
}
}()
cmd := exec.CommandContext(ctx, "helm", args...)
cmd.Cancel = func() error {
fmt.Println("Terminating helm, giving it 2 minutes to clean up...")
return cmd.Process.Signal(os.Interrupt)
}
cmd.WaitDelay = 120 * time.Second

if len(env) > 0 {
cmd.Env = env
Expand Down

0 comments on commit 3a81af0

Please sign in to comment.