Skip to content

Commit

Permalink
feat(emissary executor): Add step to allow users to pause template be…
Browse files Browse the repository at this point in the history
…fore and after execution. Fixes #6841 (#6868)

Signed-off-by: NikeNano <niklas.sven.hansson@gmail.com>
  • Loading branch information
NikeNano committed Nov 18, 2021
1 parent ee3b15e commit 3d47a5d
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 3 deletions.
25 changes: 25 additions & 0 deletions cmd/argoexec/commands/emissary.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ func NewEmissaryCommand() *cobra.Command {
command.Stderr = io.MultiWriter(os.Stderr, stderr)
}

if _, ok := os.LookupEnv("ARGO_DEBUG_PAUSE_BEFORE"); ok {
for {
// User can create the file: /ctr/NAME_OF_THE_CONTAINER/before
// in order to break out of the sleep and release the container from
// the debugging state.
if _, err := os.Stat(varRunArgo + "/ctr/" + containerName + "/before"); os.IsNotExist(err) {
time.Sleep(time.Second)
continue
}
break
}
}
if err := command.Start(); err != nil {
return err
}
Expand All @@ -150,6 +162,19 @@ func NewEmissaryCommand() *cobra.Command {

cmdErr := command.Wait()

if _, ok := os.LookupEnv("ARGO_DEBUG_PAUSE_AFTER"); ok {
for {
// User can create the file: /ctr/NAME_OF_THE_CONTAINER/after
// in order to break out of the sleep and release the container from
// the debugging state.
if _, err := os.Stat(varRunArgo + "/ctr/" + containerName + "/after"); os.IsNotExist(err) {
time.Sleep(time.Second)
continue
}
break
}
}

if cmdErr == nil {
exitCode = 0
} else if exitError, ok := cmdErr.(*exec.ExitError); ok {
Expand Down
4 changes: 1 addition & 3 deletions cmd/argoexec/commands/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ func waitContainer(ctx context.Context) error {
stats.StartStatsTicker(5 * time.Minute)

defer func() {
// Killing sidecar containers
err := wfExecutor.KillSidecars(ctx)
if err != nil {
if err := wfExecutor.KillSidecars(ctx); err != nil {
wfExecutor.AddError(err)
}
}()
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/functional/pause-after.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: pause-after-
spec:
entrypoint: whalesay
templates:
- name: whalesay
container:
image: argoproj/argosay:v2
env:
- name: ARGO_DEBUG_PAUSE_AFTER
value: 'true'
15 changes: 15 additions & 0 deletions test/e2e/functional/pause-before-after.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: pause-before-after
spec:
entrypoint: whalesay
templates:
- name: whalesay
container:
image: argoproj/argosay:v2
env:
- name: ARGO_DEBUG_PAUSE_BEFORE
value: 'true'
- name: ARGO_DEBUG_PAUSE_AFTER
value: 'true'
13 changes: 13 additions & 0 deletions test/e2e/functional/pause-before.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: pause-before-
spec:
entrypoint: whalesay
templates:
- name: whalesay
container:
image: argoproj/argosay:v2
env:
- name: ARGO_DEBUG_PAUSE_BEFORE
value: 'true'
31 changes: 31 additions & 0 deletions test/e2e/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,37 @@ spec:
WaitForWorkflow(fixtures.ToBeSucceeded)
}

func (s *FunctionalSuite) TestPauseBefore() {
s.Given().
Workflow(`@functional/pause-before.yaml`).
When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeRunning).
Exec("bash", []string{"-c", "sleep 5 && kubectl exec -i $(kubectl get pods | awk '/pause-before/ {print $1;exit}') -c main -- bash -c 'touch /proc/1/root/run/argo/ctr/main/before'"}, fixtures.NoError).
WaitForWorkflow(fixtures.ToBeSucceeded)
}

func (s *FunctionalSuite) TestPauseAfter() {
s.Given().
Workflow(`@functional/pause-after.yaml`).
When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeRunning).
Exec("bash", []string{"-c", "sleep 5 && kubectl exec -i $(kubectl get pods -n argo | awk '/pause-after/ {print $1;exit}') -c main -- bash -c 'touch /proc/1/root/run/argo/ctr/main/after'"}, fixtures.NoError).
WaitForWorkflow(fixtures.ToBeSucceeded)
}

func (s *FunctionalSuite) TestPauseAfterAndBefore() {
s.Given().
Workflow(`@functional/pause-before-after.yaml`).
When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeRunning).
Exec("bash", []string{"-c", "sleep 5 && kubectl exec -i $(kubectl get pods | awk '/pause-before-after/ {print $1;exit}') -c main -- bash -c 'touch /proc/1/root/run/argo/ctr/main/before'"}, fixtures.NoError).
Exec("bash", []string{"-c", "kubectl exec -i $(kubectl get pods | awk '/pause-before-after/ {print $1;exit}') -c main -- bash -c 'touch /proc/1/root/run/argo/ctr/main/after'"}, fixtures.NoError).
WaitForWorkflow(fixtures.ToBeSucceeded)
}

func TestFunctionalSuite(t *testing.T) {
suite.Run(t, new(FunctionalSuite))
}
Expand Down
11 changes: 11 additions & 0 deletions workflow/controller/workflowpod.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin
case wfv1.TemplateTypeContainerSet:

}

mainCtrs[i] = c
}

Expand All @@ -191,6 +192,16 @@ func (woc *wfOperationCtx) createWorkflowPod(ctx context.Context, nodeName strin
activeDeadlineSeconds = tmplActiveDeadlineSeconds
}
}

// If the template is marked for debugging no deadline will be set
for _, c := range mainCtrs {
for _, env := range c.Env {
if env.Name == "ARGO_DEBUG_PAUSE_BEFORE" || env.Name == "ARGO_DEBUG_PAUSE_AFTER" {
activeDeadlineSeconds = nil
}
}
}

pod := &apiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: util.PodName(woc.wf.Name, nodeName, tmpl.Name, nodeID),
Expand Down

0 comments on commit 3d47a5d

Please sign in to comment.