diff --git a/workflow/common/convert.go b/workflow/common/convert.go index f57e273f29ed..13552768a53b 100644 --- a/workflow/common/convert.go +++ b/workflow/common/convert.go @@ -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 + "-", diff --git a/workflow/validate/validate.go b/workflow/validate/validate.go index e731d1c393a0..ddc9b2d5b4c6 100644 --- a/workflow/validate/validate.go +++ b/workflow/validate/validate.go @@ -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}) @@ -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}) diff --git a/workflow/validate/validate_test.go b/workflow/validate/validate_test.go index 8e89fe6c3c59..4898c1065148 100644 --- a/workflow/validate/validate_test.go +++ b/workflow/validate/validate_test.go @@ -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) +}