From 56694abe27267c1cb855064b44bc7c32d61ca66c Mon Sep 17 00:00:00 2001 From: Saravanan Balasubramanian <33908564+sarabala1979@users.noreply.github.com> Date: Fri, 19 Jun 2020 17:06:45 -0700 Subject: [PATCH] Fixed onexit on workflowtempalteRef (#3263) --- pkg/apis/workflow/v1alpha1/workflow_types.go | 7 +++++++ test/e2e/functional_test.go | 17 +++++++++++++++++ .../workflow-template-whalesay-template.yaml | 6 ++++++ .../workflow-template-ref-exithandler.yaml | 14 ++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 test/e2e/testdata/workflow-template-ref-exithandler.yaml diff --git a/pkg/apis/workflow/v1alpha1/workflow_types.go b/pkg/apis/workflow/v1alpha1/workflow_types.go index fc63dc3547e9..903041373334 100644 --- a/pkg/apis/workflow/v1alpha1/workflow_types.go +++ b/pkg/apis/workflow/v1alpha1/workflow_types.go @@ -1835,6 +1835,13 @@ func (wf *Workflow) GetTemplateByName(name string) *Template { return &t } } + if wf.Status.StoredWorkflowSpec != nil { + for _, t := range wf.Status.StoredWorkflowSpec.Templates { + if t.Name == name { + return &t + } + } + } return nil } diff --git a/test/e2e/functional_test.go b/test/e2e/functional_test.go index a68a3c91ed00..7c5bcdcd4a02 100644 --- a/test/e2e/functional_test.go +++ b/test/e2e/functional_test.go @@ -582,6 +582,23 @@ func (s *FunctionalSuite) TestOptionalInputArtifacts() { }) } +func (s *FunctionalSuite) TestWorkflowTemplateRefWithExitHandler() { + s.Given(). + WorkflowTemplate("@smoke/workflow-template-whalesay-template.yaml"). + When(). + CreateWorkflowTemplates() + s.Given(). + Workflow("@testdata/workflow-template-ref-exithandler.yaml"). + When(). + SubmitWorkflow(). + WaitForWorkflow(30 * time.Second). + Then(). + ExpectWorkflow(func(t *testing.T, _ *metav1.ObjectMeta, status *wfv1.WorkflowStatus) { + assert.Equal(t, wfv1.NodeSucceeded, status.Phase) + }) + +} + func TestFunctionalSuite(t *testing.T) { suite.Run(t, new(FunctionalSuite)) } diff --git a/test/e2e/smoke/workflow-template-whalesay-template.yaml b/test/e2e/smoke/workflow-template-whalesay-template.yaml index 704e79bad8ca..fb810ae81541 100644 --- a/test/e2e/smoke/workflow-template-whalesay-template.yaml +++ b/test/e2e/smoke/workflow-template-whalesay-template.yaml @@ -6,6 +6,7 @@ metadata: argo-e2e: true spec: entrypoint: whalesay-template + onExit: on-exit arguments: parameters: - name: message @@ -19,3 +20,8 @@ spec: image: argoproj/argosay:v2 args: ["echo", "{{inputs.parameters.message}}"] imagePullPolicy: IfNotPresent + - name: on-exit + container: + image: argoproj/argosay:v2 + args: ["echo", "Exit Handler"] + imagePullPolicy: IfNotPresent \ No newline at end of file diff --git a/test/e2e/testdata/workflow-template-ref-exithandler.yaml b/test/e2e/testdata/workflow-template-ref-exithandler.yaml new file mode 100644 index 000000000000..4f717bc83fce --- /dev/null +++ b/test/e2e/testdata/workflow-template-ref-exithandler.yaml @@ -0,0 +1,14 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Workflow +metadata: + generateName: workflow-template-hello-world- + labels: + argo-e2e: "true" +spec: + entrypoint: whalesay-template + arguments: + parameters: + - name: message + value: "hello world" + workflowTemplateRef: + name: workflow-template-whalesay-template