Skip to content

Commit 242a472

Browse files
committed
fix: allow exit handler variables in resource template manifests
Signed-off-by: Markus Schneider <[email protected]>
1 parent 7dfdb63 commit 242a472

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

workflow/validate/validate.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ func ValidateWorkflow(wftmplGetter templateresolution.WorkflowTemplateNamespaced
244244
return errors.New(errors.CodeBadRequest, "spec.entrypoint is required")
245245
}
246246

247+
// if resource templates are present, workflow failure variables may appear in the manifest
248+
for _, tmpl := range wf.Spec.Templates {
249+
if tmpl.Resource != nil && tmpl.Resource.Manifest != "" {
250+
ctx.globalParams[common.GlobalVarWorkflowFailures] = placeholderGenerator.NextPlaceholder()
251+
break
252+
}
253+
}
254+
247255
if !opts.IgnoreEntrypoint {
248256
var args wfv1.ArgumentsProvider
249257
args = &wfArgs

workflow/validate/validate_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,47 @@ spec:
10411041
args: ["echo {{workflow.failures}}"]
10421042
`
10431043

1044+
var workflowStatusInResourceTemplateManifest = `
1045+
apiVersion: argoproj.io/v1alpha1
1046+
kind: Workflow
1047+
metadata:
1048+
generateName: exit-handlers-parent-workflow-
1049+
spec:
1050+
entrypoint: trigger-child-workflow
1051+
serviceAccountName: argo
1052+
templates:
1053+
- name: trigger-child-workflow
1054+
resource:
1055+
action: create
1056+
manifest: |
1057+
apiVersion: argoproj.io/v1alpha1
1058+
kind: Workflow
1059+
metadata:
1060+
generateName: {{workflow.name}}-child-workflow-
1061+
spec:
1062+
entrypoint: main
1063+
onExit: exit-handler
1064+
templates:
1065+
- name: main
1066+
dag:
1067+
tasks:
1068+
- name: say-hello-task
1069+
template: say-hello
1070+
- name: say-hello
1071+
script:
1072+
image: alpine:latest
1073+
command: [sh]
1074+
source: |
1075+
echo "hello from child workflow"
1076+
- name: exit-handler
1077+
script:
1078+
image: alpine:latest
1079+
command: [sh]
1080+
source: |
1081+
echo "hello from exit handler"
1082+
echo '{{workflow.failures}}'
1083+
`
1084+
10441085
func TestExitHandler(t *testing.T) {
10451086
// ensure {{workflow.status}} is not available when not in exit handler
10461087
err := validate(workflowStatusNotOnExit)
@@ -1049,6 +1090,10 @@ func TestExitHandler(t *testing.T) {
10491090
// ensure {{workflow.status}} is available in exit handler
10501091
err = validate(exitHandlerWorkflowStatusOnExit)
10511092
require.NoError(t, err)
1093+
1094+
// ensure {{workflow.status}} is available when in resource template manifest
1095+
err = validate(workflowStatusInResourceTemplateManifest)
1096+
require.NoError(t, err)
10521097
}
10531098

10541099
var workflowWithPriority = `

0 commit comments

Comments
 (0)