Skip to content

Commit

Permalink
fix: Cannot create WorkflowTemplate with un-supplied inputs (argoproj…
Browse files Browse the repository at this point in the history
  • Loading branch information
sarabala1979 committed Apr 28, 2020
1 parent c3e30c5 commit e378ca4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
15 changes: 12 additions & 3 deletions workflow/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type ValidateOpts struct {
// IgnoreEntrypoint indicates to skip/ignore the EntryPoint validation on workflow spec.
// Entrypoint is optional for WorkflowTemplate and ClusterWorkflowTemplate
IgnoreEntrypoint bool

// WorkflowTemplateValidation indicates that the current context is validating a WorkflowTemplate or ClusterWorkflowTemplate
WorkflowTemplateValidation bool
}

// templateValidationCtx is the context for validating a workflow spec
Expand Down Expand Up @@ -172,7 +175,13 @@ func ValidateWorkflow(wftmplGetter templateresolution.WorkflowTemplateNamespaced
}

if !opts.IgnoreEntrypoint {
_, err = ctx.validateTemplateHolder(&wfv1.WorkflowStep{Template: wf.Spec.Entrypoint}, tmplCtx, &wf.Spec.Arguments, map[string]interface{}{})
var args wfv1.ArgumentsProvider
args = &wf.Spec.Arguments

if opts.WorkflowTemplateValidation {
args = &FakeArguments{}
}
_, err = ctx.validateTemplateHolder(&wfv1.WorkflowStep{Template: wf.Spec.Entrypoint}, tmplCtx, args, map[string]interface{}{})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -208,13 +217,13 @@ func ValidateWorkflow(wftmplGetter templateresolution.WorkflowTemplateNamespaced
// ValidateWorkflowTemplate accepts a workflow template and performs validation against it.
func ValidateWorkflowTemplate(wftmplGetter templateresolution.WorkflowTemplateNamespacedGetter, cwftmplGetter templateresolution.ClusterWorkflowTemplateGetter, wftmpl *wfv1.WorkflowTemplate) (*wfv1.WorkflowConditions, error) {
wf := common.ConvertWorkflowTemplateToWorkflow(wftmpl)
return ValidateWorkflow(wftmplGetter, cwftmplGetter, wf, ValidateOpts{IgnoreEntrypoint: wf.Spec.Entrypoint == ""})
return ValidateWorkflow(wftmplGetter, cwftmplGetter, wf, ValidateOpts{IgnoreEntrypoint: wf.Spec.Entrypoint == "", WorkflowTemplateValidation: true})
}

// ValidateClusterWorkflowTemplate accepts a cluster workflow template and performs validation against it.
func ValidateClusterWorkflowTemplate(wftmplGetter templateresolution.WorkflowTemplateNamespacedGetter, cwftmplGetter templateresolution.ClusterWorkflowTemplateGetter, cwftmpl *wfv1.ClusterWorkflowTemplate) (*wfv1.WorkflowConditions, error) {
wf := common.ConvertClusterWorkflowTemplateToWorkflow(cwftmpl)
return ValidateWorkflow(wftmplGetter, cwftmplGetter, wf, ValidateOpts{IgnoreEntrypoint: wf.Spec.Entrypoint == ""})
return ValidateWorkflow(wftmplGetter, cwftmplGetter, wf, ValidateOpts{IgnoreEntrypoint: wf.Spec.Entrypoint == "", WorkflowTemplateValidation: true})
}

// ValidateCronWorkflow validates a CronWorkflow
Expand Down
23 changes: 23 additions & 0 deletions workflow/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2385,3 +2385,26 @@ func TestWorfklowGlobalVariables(t *testing.T) {
_, err := validate(globalVariables)
assert.NoError(t, err)
}

var wfTemplateWithEntrypoint = `
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
name: template-with-entrypoint
spec:
entrypoint: whalesay-template
templates:
- name: whalesay-template
inputs:
parameters:
- name: message
container:
image: docker/whalesay
command: [cowsay]
args: ["{{inputs.parameters.message}}"]
`

func TestWorkflowTemplateWithEntrypoint(t *testing.T) {
err := validateWorkflowTemplate(wfTemplateWithEntrypoint)
assert.NoError(t, err)
}

0 comments on commit e378ca4

Please sign in to comment.