Renaming variable testCWF.

Adding the workflow spec correctly to the CronWorkflow spec.
This commit is contained in:
Aleksandr Melnikov
2020-03-27 12:08:26 -07:00
parent 96fd279189
commit d7a289c895
2 changed files with 34 additions and 18 deletions

View File

@@ -42,33 +42,46 @@ func (c *Client) CreateCronWorkflow(namespace string, cronWorkflow *CronWorkflow
} }
(*opts.Labels)[workflowTemplateUIDLabelKey] = workflowTemplate.UID (*opts.Labels)[workflowTemplateUIDLabelKey] = workflowTemplate.UID
(*opts.Labels)[workflowTemplateVersionLabelKey] = fmt.Sprint(workflowTemplate.Version) (*opts.Labels)[workflowTemplateVersionLabelKey] = fmt.Sprint(workflowTemplate.Version)
var testCWF wfv1.CronWorkflow var argoCronWorkflow wfv1.CronWorkflow
testCWF.Spec.Schedule = cronWorkflow.Schedule argoCronWorkflow.Spec.Schedule = cronWorkflow.Schedule
testCWF.Spec.Timezone = cronWorkflow.Timezone argoCronWorkflow.Spec.Timezone = cronWorkflow.Timezone
testCWF.Spec.Suspend = cronWorkflow.Suspend argoCronWorkflow.Spec.Suspend = cronWorkflow.Suspend
testCWF.Spec.ConcurrencyPolicy = wfv1.ConcurrencyPolicy(cronWorkflow.ConcurrencyPolicy) argoCronWorkflow.Spec.ConcurrencyPolicy = wfv1.ConcurrencyPolicy(cronWorkflow.ConcurrencyPolicy)
testCWF.Spec.StartingDeadlineSeconds = cronWorkflow.StartingDeadlineSeconds argoCronWorkflow.Spec.StartingDeadlineSeconds = cronWorkflow.StartingDeadlineSeconds
testCWF.Spec.SuccessfulJobsHistoryLimit = cronWorkflow.SuccessfulJobsHistoryLimit argoCronWorkflow.Spec.SuccessfulJobsHistoryLimit = cronWorkflow.SuccessfulJobsHistoryLimit
testCWF.Spec.FailedJobsHistoryLimit = cronWorkflow.FailedJobsHistoryLimit argoCronWorkflow.Spec.FailedJobsHistoryLimit = cronWorkflow.FailedJobsHistoryLimit
//UX prevents multiple workflows
argoCreatedCronWorkflow, err := c.createCronWorkflow(namespace, &testCWF, opts) workflows, err := UnmarshalWorkflows([]byte(workflowTemplate.Manifest), true)
if err != nil { if err != nil {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"Namespace": namespace, "Namespace": namespace,
"CronWorkflow": cronWorkflow, "CronWorkflow": workflow,
"Error": err.Error(), "Error": err.Error(),
}).Error("Error parsing workflow.") }).Error("Error parsing workflow.")
return nil, err return nil, err
} }
cronWorkflow.Name = argoCreatedCronWorkflow.Name for _, wf := range workflows {
cronWorkflow.CreatedAt = argoCreatedCronWorkflow.CreationTimestamp.UTC() argoCronWorkflow.Spec.WorkflowSpec = wf.Spec
cronWorkflow.UID = string(argoCreatedCronWorkflow.ObjectMeta.UID) argoCreatedCronWorkflow, err := c.createCronWorkflow(namespace, &argoCronWorkflow, opts)
cronWorkflow.WorkflowExecution.WorkflowTemplate = workflowTemplate if err != nil {
// Manifests could get big, don't return them in this case. log.WithFields(log.Fields{
cronWorkflow.WorkflowExecution.WorkflowTemplate.Manifest = "" "Namespace": namespace,
"CronWorkflow": cronWorkflow,
"Error": err.Error(),
}).Error("Error parsing workflow.")
return nil, err
}
cronWorkflow.Name = argoCreatedCronWorkflow.Name
cronWorkflow.CreatedAt = argoCreatedCronWorkflow.CreationTimestamp.UTC()
cronWorkflow.UID = string(argoCreatedCronWorkflow.ObjectMeta.UID)
cronWorkflow.WorkflowExecution.WorkflowTemplate = workflowTemplate
// Manifests could get big, don't return them in this case.
cronWorkflow.WorkflowExecution.WorkflowTemplate.Manifest = ""
return cronWorkflow, nil return cronWorkflow, nil
}
return nil, nil
} }
func (c *Client) createCronWorkflow(namespace string, cwf *wfv1.CronWorkflow, opts *WorkflowExecutionOptions) (createdCronWorkflow *wfv1.CronWorkflow, err error) { func (c *Client) createCronWorkflow(namespace string, cwf *wfv1.CronWorkflow, opts *WorkflowExecutionOptions) (createdCronWorkflow *wfv1.CronWorkflow, err error) {

View File

@@ -63,5 +63,8 @@ func (c *CronWorkflowServer) CreateCronWorkflow(ctx context.Context, req *api.Cr
if err != nil { if err != nil {
return nil, err return nil, err
} }
if cwf == nil {
return nil, nil
}
return apiCronWorkflow(cwf), nil return apiCronWorkflow(cwf), nil
} }