(ctx context.Context, req *workflowpkg.WorkflowCreateRequest)
| 96 | } |
| 97 | |
| 98 | func (s *workflowServer) CreateWorkflow(ctx context.Context, req *workflowpkg.WorkflowCreateRequest) (*wfv1.Workflow, error) { |
| 99 | wfClient := auth.GetWfClient(ctx) |
| 100 | |
| 101 | if req.Workflow == nil { |
| 102 | return nil, sutils.ToStatusError(fmt.Errorf("workflow body not specified"), codes.InvalidArgument) |
| 103 | } |
| 104 | |
| 105 | if req.Workflow.Namespace == "" { |
| 106 | req.Workflow.Namespace = req.Namespace |
| 107 | } |
| 108 | |
| 109 | s.instanceIDService.Label(req.Workflow) |
| 110 | creator.LabelCreator(ctx, req.Workflow) |
| 111 | |
| 112 | wftmplGetter := s.wftmplStore.Getter(ctx, req.Workflow.Namespace) |
| 113 | cwftmplGetter := s.cwftmplStore.Getter(ctx) |
| 114 | |
| 115 | err := validate.ValidateWorkflow(ctx, wftmplGetter, cwftmplGetter, req.Workflow, s.wfDefaults, validate.ValidateOpts{}) |
| 116 | if err != nil { |
| 117 | return nil, sutils.ToStatusError(err, codes.InvalidArgument) |
| 118 | } |
| 119 | |
| 120 | // if we are doing a normal dryRun, just return the workflow un-altered |
| 121 | if req.CreateOptions != nil && len(req.CreateOptions.DryRun) > 0 { |
| 122 | return req.Workflow, nil |
| 123 | } |
| 124 | if req.ServerDryRun { |
| 125 | workflow, err := util.CreateServerDryRun(ctx, req.Workflow, wfClient) |
| 126 | if err != nil { |
| 127 | return nil, sutils.ToStatusError(err, codes.InvalidArgument) |
| 128 | } |
| 129 | return workflow, nil |
| 130 | } |
| 131 | |
| 132 | wf, err := wfClient.ArgoprojV1alpha1().Workflows(req.Namespace).Create(ctx, req.Workflow, metav1.CreateOptions{}) |
| 133 | logger := logging.RequireLoggerFromContext(ctx) |
| 134 | if err != nil { |
| 135 | if apierr.IsServerTimeout(err) && req.Workflow.GenerateName != "" && req.Workflow.Name != "" { |
| 136 | errWithHint := fmt.Errorf(`create request failed due to timeout, but it's possible that workflow "%s" already exists. Original error: %w`, req.Workflow.Name, err) |
| 137 | logger.WithError(err).Error(ctx, errWithHint.Error()) |
| 138 | return nil, sutils.ToStatusError(errWithHint, codes.DeadlineExceeded) |
| 139 | } |
| 140 | logger.WithError(err).Error(ctx, "Create request failed") |
| 141 | return nil, sutils.ToStatusError(err, codes.Internal) |
| 142 | } |
| 143 | |
| 144 | return wf, nil |
| 145 | } |
| 146 | |
| 147 | func (s *workflowServer) GetWorkflow(ctx context.Context, req *workflowpkg.WorkflowGetRequest) (*wfv1.Workflow, error) { |
| 148 | wfGetOption := metav1.GetOptions{} |
nothing calls this directly
no test coverage detected