Skip to content

Commit

Permalink
fix: Correct kill command. Fixes #8687 (#8908)
Browse files Browse the repository at this point in the history
* fix: Correct kill command. Fixes #8687

Signed-off-by: Alex Collins <alex_collins@intuit.com>

* fix: ok

Signed-off-by: Alex Collins <alex_collins@intuit.com>

* fix: ok

Signed-off-by: Alex Collins <alex_collins@intuit.com>
Signed-off-by: Saravanan Balasubramanian <sarabala1979@gmail.com>
  • Loading branch information
alexec authored and sarabala1979 committed Aug 8, 2022
1 parent e85c815 commit ef3fb42
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 39 deletions.
37 changes: 37 additions & 0 deletions cmd/argoexec/commands/kill.go
@@ -0,0 +1,37 @@
package commands

import (
"fmt"
"os"
"strconv"
"syscall"

"github.com/spf13/cobra"
)

func NewKillCommand() *cobra.Command {
return &cobra.Command{
Use: "kill SIGNAL PID",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
signum, err := strconv.Atoi(args[0])
if err != nil {
return err
}
pid, err := strconv.Atoi(args[1])
if err != nil {
return err
}
sig := syscall.Signal(signum)
p, err := os.FindProcess(pid)
if err != nil {
return err
}
fmt.Printf("killing %d with %v\n", pid, sig)
if err := p.Signal(sig); err != nil {
return err
}
return nil
},
}
}
1 change: 1 addition & 0 deletions cmd/argoexec/commands/root.go
Expand Up @@ -63,6 +63,7 @@ func NewRootCommand() *cobra.Command {
command.AddCommand(NewAgentCommand())
command.AddCommand(NewEmissaryCommand())
command.AddCommand(NewInitCommand())
command.AddCommand(NewKillCommand())
command.AddCommand(NewResourceCommand())
command.AddCommand(NewWaitCommand())
command.AddCommand(NewDataCommand())
Expand Down
21 changes: 12 additions & 9 deletions cmd/argoexec/commands/wait.go
Expand Up @@ -2,6 +2,8 @@ package commands

import (
"context"
"os/signal"
"syscall"
"time"

"github.com/argoproj/pkg/stats"
Expand Down Expand Up @@ -30,19 +32,20 @@ func waitContainer(ctx context.Context) error {
defer stats.LogStats()
stats.StartStatsTicker(5 * time.Minute)

defer func() {
if err := wfExecutor.KillSidecars(ctx); err != nil {
// use a block to constrain the scope of ctx
{
// this allows us to gracefully shutdown, capturing artifacts
ctx, cancel := signal.NotifyContext(ctx, syscall.SIGTERM)
defer cancel()

// Wait for main container to complete
err := wfExecutor.Wait(ctx)
if err != nil {
wfExecutor.AddError(err)
}
}()

// Wait for main container to complete
err := wfExecutor.Wait(ctx)
if err != nil {
wfExecutor.AddError(err)
}
// Capture output script result
err = wfExecutor.CaptureScriptResult(ctx)
err := wfExecutor.CaptureScriptResult(ctx)
if err != nil {
wfExecutor.AddError(err)
}
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/signals_test.go
Expand Up @@ -136,12 +136,12 @@ func (s *SignalsSuite) TestInjectedSidecar() {
WaitForWorkflow(fixtures.ToBeSucceeded, kill2xDuration)
}

func (s *SignalsSuite) TestInjectedSidecarKillAnnotation() {
func (s *SignalsSuite) TestSubProcess() {
s.Given().
Workflow("@testdata/sidecar-injected-kill-annotation-workflow.yaml").
Workflow("@testdata/subprocess-workflow.yaml").
When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeSucceeded, kill2xDuration)
WaitForWorkflow()
}

func TestSignalsSuite(t *testing.T) {
Expand Down
25 changes: 0 additions & 25 deletions test/e2e/testdata/sidecar-injected-kill-annotation-workflow.yaml

This file was deleted.

13 changes: 11 additions & 2 deletions workflow/signal/signal.go
Expand Up @@ -3,6 +3,7 @@ package signal
import (
"encoding/json"
"fmt"
"path/filepath"
"strings"
"syscall"

Expand All @@ -15,8 +16,16 @@ import (

func SignalContainer(restConfig *rest.Config, pod *corev1.Pod, container string, s syscall.Signal) error {
command := []string{"/bin/sh", "-c", "kill -%d 1"}
if container == common.WaitContainerName {
command = []string{"/bin/sh", "-c", "kill -%d $(pidof argoexec)"}

// If the container has the /var/run/argo volume mounted, this it will have access to `argoexec`.
for _, c := range pod.Spec.Containers {
if c.Name == container {
for _, m := range c.VolumeMounts {
if m.MountPath == common.VarRunArgoPath {
command = []string{filepath.Join(common.VarRunArgoPath, "argoexec"), "kill", "%d", "1"}
}
}
}
}

if v, ok := pod.Annotations[common.AnnotationKeyKillCmd(container)]; ok {
Expand Down

0 comments on commit ef3fb42

Please sign in to comment.