Skip to content

Commit

Permalink
fix: Unmark daemoned nodes after stopping them (#5005)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Behar <simbeh7@gmail.com>
  • Loading branch information
simster7 committed Feb 4, 2021
1 parent 38e98f7 commit d1abcb0
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/e2e/daemon_pod_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// +build functional

package e2e

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/argoproj/argo/v3/pkg/apis/workflow/v1alpha1"
"github.com/argoproj/argo/v3/test/e2e/fixtures"
)

type DaemonPodSuite struct {
fixtures.E2ESuite
}

func (s *DaemonPodSuite) TestWorkflowCompletesIfContainsDaemonPod() {
s.Given().
Workflow(`apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: whalesay-
labels:
argo-e2e: true
spec:
entrypoint: whalesay
templates:
- name: whalesay
dag:
tasks:
- name: redis
template: redis-tmpl
- name: whale
dependencies: [redis]
template: whale-tmpl
- name: redis-tmpl
daemon: true
container:
image: argoproj/argosay:v2
args: ["sleep", "100s"]
- name: whale-tmpl
container:
image: argoproj/argosay:v2
args: ["echo", "hello world"]
`).
When().
SubmitWorkflow().
WaitForWorkflow(fixtures.ToBeSucceeded, "to be succeeded").
Then().
ExpectWorkflow(func(t *testing.T, metadata *v1.ObjectMeta, status *v1alpha1.WorkflowStatus) {
assert.False(t, status.FinishedAt.IsZero())
})
}

func TestDaemonPodSuite(t *testing.T) {
suite.Run(t, new(DaemonPodSuite))
}
1 change: 1 addition & 0 deletions test/e2e/fixtures/when.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ var ToBeRunning Condition = func(wf *wfv1.Workflow) bool {
return node.Phase == wfv1.NodeRunning
})
}
var ToBeSucceeded Condition = func(wf *wfv1.Workflow) bool { return wf.Status.Phase == wfv1.WorkflowSucceeded }

// `ToBeDone` replaces `ToFinish` which also makes sure the workflow is both complete not pending archiving.
// This additional check is not needed for most use case, however in `AfterTest` we delete the workflow and this
Expand Down
4 changes: 4 additions & 0 deletions workflow/controller/exec_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ func (woc *wfOperationCtx) killDaemonedChildren(ctx context.Context, nodeID stri
firstErr = err
}
}

childNode.Daemoned = nil
woc.wf.Status.Nodes[childNode.ID] = childNode
woc.updated = true
}
return firstErr
}
Expand Down
33 changes: 33 additions & 0 deletions workflow/controller/exec_control_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package controller

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"k8s.io/utils/pointer"

"github.com/argoproj/argo/v3/pkg/apis/workflow/v1alpha1"
)

func TestKillDaemonChildrenUnmarkPod(t *testing.T) {
cancel, controller := newController()
defer cancel()

woc := newWorkflowOperationCtx(&v1alpha1.Workflow{
Status: v1alpha1.WorkflowStatus{
Nodes: v1alpha1.Nodes{
"a": v1alpha1.NodeStatus{
ID: "a",
BoundaryID: "a",
Daemoned: pointer.BoolPtr(true),
},
},
},
}, controller)

assert.NotNil(t, woc.wf.Status.Nodes["a"].Daemoned)
// Error will be that it cannot find the pod, but we only care about the node status for this test
_ = woc.killDaemonedChildren(context.Background(), "a")
assert.Nil(t, woc.wf.Status.Nodes["a"].Daemoned)
}

0 comments on commit d1abcb0

Please sign in to comment.