Repository: argoproj/argo
Pull request #3482 (2020-07-14 23:02:19)

fix: Pass resolved arguments to onExit handler
Note that this is a PR targeted at `release-2.9` (not `master`)


Patch:
diff --git a/.github/workflows/ci-build.yaml b/.github/workflows/ci-build.yaml
index 1a2027b7e..12bf1e9d7 100644
--- a/.github/workflows/ci-build.yaml
+++ b/.github/workflows/ci-build.yaml
@@ -71,7 +71,7 @@ jobs:
           mkdir -p dist
           mkdir -p /tmp/log/argo-e2e
           git fetch --tags
-          KUBECONFIG=~/.kube/config make start PROFILE=$PROFILE E2E_EXECUTOR=docker DEV_IMAGE=true
+          KUBECONFIG=~/.kube/config make start PROFILE=$PROFILE E2E_EXECUTOR=docker DEV_IMAGE=true 2>&1 > /tmp/log/argo-e2e/argo.log &
       - name: Wait for Argo Server to be ready
         if: ${{ matrix.test != 'test' }}
         env:
diff --git a/Makefile b/Makefile
index d61875cb4..098b3ea88 100644
--- a/Makefile
+++ b/Makefile
@@ -44,7 +44,7 @@ MANIFESTS_VERSION     := $(VERSION)
 DEV_IMAGE             := false
 else
 ifeq ($(findstring release,$(GIT_BRANCH)),release)
-VERSION               := $(shell git tag --no-merge|grep ^v|sort -d|tail -n1)
+VERSION               := $(shell git tag|grep ^v|sort -d|tail -n1)
 MANIFESTS_VERSION     := $(VERSION)
 DEV_IMAGE             := false
 else
diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json
index 0e55b58cd..a5277bd91 100644
--- a/api/openapi-spec/swagger.json
+++ b/api/openapi-spec/swagger.json
@@ -12,7 +12,7 @@
   "info": {
     "description": "Argo",
     "title": "Argo",
-    "version": "release-2.9"
+    "version": "v2.9.2"
   },
   "host": "localhost:2746",
   "paths": {
diff --git a/workflow/controller/operator.go b/workflow/controller/operator.go
index 3a99eb4c2..6fff103d3 100644
--- a/workflow/controller/operator.go
+++ b/workflow/controller/operator.go
@@ -341,7 +341,7 @@ func (woc *wfOperationCtx) operate() {
 
 		woc.log.Infof("Running OnExit handler: %s", woc.wfSpec.OnExit)
 		onExitNodeName := woc.wf.ObjectMeta.Name + ".onExit"
-		onExitNode, err = woc.executeTemplate(onExitNodeName, &wfv1.WorkflowStep{Template: woc.wfSpec.OnExit}, tmplCtx, woc.wfSpec.Arguments, &executeTemplateOpts{onExitTemplate: true})
+		onExitNode, err = woc.executeTemplate(onExitNodeName, &wfv1.WorkflowStep{Template: woc.wfSpec.OnExit}, tmplCtx, execArgs, &executeTemplateOpts{onExitTemplate: true})
 		if err != nil {
 			// the error are handled in the callee so just log it.
 			woc.log.WithError(err).Error("error in exit template execution")


Test patch:
diff --git a/test/e2e/fixtures/e2e_suite.go b/test/e2e/fixtures/e2e_suite.go
index 93d43b95b..542e2e7ac 100644
--- a/test/e2e/fixtures/e2e_suite.go
+++ b/test/e2e/fixtures/e2e_suite.go
@@ -36,35 +36,6 @@ const Label = "argo-e2e"
 // Cron tests run in parallel, so use a different label so they are not deleted when a new test runs
 const LabelCron = Label + "-cron"
 
-var imageTag string
-var k3d bool
-
-func init() {
-	gitBranch, err := runCli("git", "rev-parse", "--abbrev-ref=loose", "HEAD")
-	if err != nil {
-		panic(err)
-	}
-	imageTag = strings.TrimSpace(gitBranch)
-	if imageTag == "master" {
-		imageTag = "latest"
-	}
-	if strings.HasPrefix(gitBranch, "release-") {
-		tags, err := runCli("git", "tag", "--merged")
-		if err != nil {
-			panic(err)
-		}
-		parts := strings.Split(tags, "\n")
-		imageTag = parts[len(parts)-2]
-	}
-	imageTag = strings.ReplaceAll(imageTag, "/", "-")
-	context, err := runCli("kubectl", "config", "current-context")
-	if err != nil {
-		panic(err)
-	}
-	k3d = strings.TrimSpace(context) == "k3s-default"
-	log.WithFields(log.Fields{"imageTag": imageTag, "k3d": k3d}).Info()
-}
-
 type E2ESuite struct {
 	suite.Suite
 	Persistence       *Persistence
diff --git a/test/e2e/fixtures/given.go b/test/e2e/fixtures/given.go
index e98fe76da..e246fda6b 100644
--- a/test/e2e/fixtures/given.go
+++ b/test/e2e/fixtures/given.go
@@ -73,17 +73,17 @@ func (g *Given) Workflow(text string) *Given {
 func (g *Given) checkImages(templates []wfv1.Template) {
 	// Using an arbitrary image will result in slow and flakey tests as we can't really predict when they'll be
 	// downloaded or evicted. To keep tests fast and reliable you must use whitelisted images.
-	imageWhitelist := map[string]bool{
-		"argoexec:" + imageTag: true,
-		"argoproj/argosay:v1":  true,
-		"argoproj/argosay:v2":  true,
-		"python:alpine3.6":     true,
+	imageWhitelist := func(image string) bool {
+		return strings.Contains(image, "argoexec:") ||
+			image == "argoproj/argosay:v1" ||
+			image == "argoproj/argosay:v2" ||
+			image == "python:alpine3.6"
 	}
 	for _, t := range templates {
 		container := t.Container
 		if container != nil {
 			image := container.Image
-			if !imageWhitelist[image] {
+			if !imageWhitelist(image) {
 				g.t.Fatalf("non-whitelisted image used in test: %s", image)
 			}
 		}
diff --git a/workflow/controller/operator_test.go b/workflow/controller/operator_test.go
index 31eaa05c4..fc72bedd9 100644
--- a/workflow/controller/operator_test.go
+++ b/workflow/controller/operator_test.go
@@ -4017,3 +4017,164 @@ status:
 		}
 	}
 }
+
+var globalVarsOnExit = `
+apiVersion: argoproj.io/v1alpha1
+kind: Workflow
+metadata:
+  name: hello-world-6gphm-8n22g
+  namespace: default
+spec:
+  arguments:
+    parameters:
+    - name: message
+      value: nononono
+  workflowTemplateRef:
+    name: hello-world-6gphm
+status:
+  nodes:
+    hello-world-6gphm-8n22g:
+      displayName: hello-world-6gphm-8n22g
+      finishedAt: "2020-07-14T20:45:28Z"
+      hostNodeName: minikube
+      id: hello-world-6gphm-8n22g
+      inputs:
+        parameters:
+        - name: message
+          value: nononono
+      name: hello-world-6gphm-8n22g
+      outputs:
+        artifacts:
+        - archiveLogs: true
+          name: main-logs
+          s3:
+            accessKeySecret:
+              key: accesskey
+              name: my-minio-cred
+            bucket: my-bucket
+            endpoint: minio:9000
+            insecure: true
+            key: hello-world-6gphm-8n22g/hello-world-6gphm-8n22g/main.log
+            secretKeySecret:
+              key: secretkey
+              name: my-minio-cred
+        exitCode: "0"
+      phase: Succeeded
+      resourcesDuration:
+        cpu: 2
+        memory: 1
+      startedAt: "2020-07-14T20:45:25Z"
+      templateRef:
+        name: hello-world-6gphm
+        template: whalesay
+      templateScope: local/hello-world-6gphm-8n22g
+      type: Pod
+  phase: Running
+  resourcesDuration:
+    cpu: 5
+    memory: 2
+  startedAt: "2020-07-14T20:45:25Z"
+  storedTemplates:
+    namespaced/hello-world-6gphm/whalesay:
+      arguments: {}
+      container:
+        args:
+        - hello {{inputs.parameters.message}}
+        command:
+        - cowsay
+        image: docker/whalesay:latest
+        name: ""
+        resources: {}
+      inputs:
+        parameters:
+        - name: message
+      metadata: {}
+      name: whalesay
+      outputs: {}
+  storedWorkflowTemplateSpec:
+    arguments:
+      parameters:
+      - name: message
+        value: default
+    entrypoint: whalesay
+    onExit: exitContainer
+    templates:
+    - arguments: {}
+      container:
+        args:
+        - hello {{inputs.parameters.message}}
+        command:
+        - cowsay
+        image: docker/whalesay:latest
+        name: ""
+        resources: {}
+      inputs:
+        parameters:
+        - name: message
+      metadata: {}
+      name: whalesay
+      outputs: {}
+    - arguments: {}
+      container:
+        args:
+        - goodbye {{inputs.parameters.message}}
+        command:
+        - cowsay
+        image: docker/whalesay
+        name: ""
+        resources: {}
+      inputs:
+        parameters:
+        - name: message
+      metadata: {}
+      name: exitContainer
+      outputs: {}
+
+`
+
+var wftmplGlobalVarsOnExit = `
+apiVersion: argoproj.io/v1alpha1
+kind: WorkflowTemplate
+metadata:
+  name: hello-world-6gphm
+  namespace: default
+spec:
+  entrypoint: whalesay
+  onExit: exitContainer
+  arguments:
+    parameters:
+    - name: message
+      value: "default"
+  templates:
+  - name: whalesay
+    inputs:
+      parameters:
+      - name: message
+    container:
+      image: docker/whalesay:latest
+      command: [cowsay]
+      args: ["hello {{inputs.parameters.message}}"]
+  - name: exitContainer
+    inputs:
+      parameters:
+      - name: message
+    container:
+      image: docker/whalesay
+      command: [cowsay]
+      args: ["goodbye {{inputs.parameters.message}}"]
+`
+
+func TestGlobalVarsOnExit(t *testing.T) {
+	wf := unmarshalWF(globalVarsOnExit)
+	wftmpl := unmarshalWFTmpl(wftmplGlobalVarsOnExit)
+	cancel, controller := newController(wf, wftmpl)
+	defer cancel()
+	woc := newWorkflowOperationCtx(wf, controller)
+
+	woc.operate()
+
+	node := woc.wf.Status.Nodes["hello-world-6gphm-8n22g-3224262006"]
+	if assert.NotNil(t, node) && assert.NotNil(t, node.Inputs) && assert.NotEmpty(t, node.Inputs.Parameters) {
+		assert.Equal(t, "nononono", *node.Inputs.Parameters[0].Value)
+	}
+}