Skip to content

Commit

Permalink
fix: Consider WorkflowTemplate metadata during validation (#3988)
Browse files Browse the repository at this point in the history
  • Loading branch information
simster7 committed Sep 10, 2020
1 parent 089e186 commit b9a0bb0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 0 additions & 1 deletion workflow/common/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func ConvertCronWorkflowToWorkflow(cronWf *wfv1.CronWorkflow) *wfv1.Workflow {
}

func NewWorkflowFromWorkflowTemplate(templateName string, workflowMetadata *metav1.ObjectMeta, clusterScope bool) *wfv1.Workflow {

wf := &wfv1.Workflow{
ObjectMeta: metav1.ObjectMeta{
GenerateName: templateName + "-",
Expand Down
8 changes: 8 additions & 0 deletions workflow/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ func ValidateWorkflowTemplateRefFields(wfSpec wfv1.WorkflowSpec) error {
// ValidateWorkflowTemplate accepts a workflow template and performs validation against it.
func ValidateWorkflowTemplate(wftmplGetter templateresolution.WorkflowTemplateNamespacedGetter, cwftmplGetter templateresolution.ClusterWorkflowTemplateGetter, wftmpl *wfv1.WorkflowTemplate) (*wfv1.Conditions, error) {
wf := &wfv1.Workflow{
ObjectMeta: v1.ObjectMeta{
Labels: wftmpl.ObjectMeta.Labels,
Annotations: wftmpl.ObjectMeta.Annotations,
},
Spec: wftmpl.Spec.WorkflowSpec,
}
return ValidateWorkflow(wftmplGetter, cwftmplGetter, wf, ValidateOpts{IgnoreEntrypoint: wf.Spec.Entrypoint == "", WorkflowTemplateValidation: true})
Expand All @@ -272,6 +276,10 @@ func ValidateWorkflowTemplate(wftmplGetter templateresolution.WorkflowTemplateNa
// ValidateClusterWorkflowTemplate accepts a cluster workflow template and performs validation against it.
func ValidateClusterWorkflowTemplate(wftmplGetter templateresolution.WorkflowTemplateNamespacedGetter, cwftmplGetter templateresolution.ClusterWorkflowTemplateGetter, cwftmpl *wfv1.ClusterWorkflowTemplate) (*wfv1.Conditions, error) {
wf := &wfv1.Workflow{
ObjectMeta: v1.ObjectMeta{
Labels: cwftmpl.ObjectMeta.Labels,
Annotations: cwftmpl.ObjectMeta.Annotations,
},
Spec: cwftmpl.Spec.WorkflowSpec,
}
return ValidateWorkflow(wftmplGetter, cwftmplGetter, wf, ValidateOpts{IgnoreEntrypoint: wf.Spec.Entrypoint == "", WorkflowTemplateValidation: true})
Expand Down
31 changes: 31 additions & 0 deletions workflow/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2616,3 +2616,34 @@ func TestDagAndStepLevelOutputArtifactsForDiffExecutor(t *testing.T) {
assert.NoError(t, err)
})
}

var testWorkflowTemplateLabels = `
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
generateName: test-foobar-
labels:
testLabel: foobar
spec:
entrypoint: whalesay
templates:
- name: whalesay
resubmitPendingPods: true
container:
image: docker/whalesay
metrics:
prometheus:
- name: intuit_data_persistplat_dppselfservice_workflow_test_duration
help: Duration of workflow
labels:
- key: label
value: "{{workflow.labels.testLabel}}"
gauge:
realtime: true
value: "{{duration}}"
`

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

0 comments on commit b9a0bb0

Please sign in to comment.