MCPcopy
hub / github.com/argoproj/argo-workflows / createTaskSet

Method createTaskSet

workflow/controller/taskset.go:172–229  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

170}
171
172func (woc *wfOperationCtx) createTaskSet(ctx context.Context) error {
173 if len(woc.taskSet) == 0 {
174 return nil
175 }
176
177 woc.log.Info(ctx, "Creating TaskSet")
178 labels := map[string]string{}
179 if woc.controller.Config.InstanceID != "" {
180 labels[common.LabelKeyControllerInstanceID] = woc.controller.Config.InstanceID
181 }
182 taskSet := wfv1.WorkflowTaskSet{
183 TypeMeta: metav1.TypeMeta{
184 Kind: workflow.WorkflowTaskSetKind,
185 APIVersion: workflow.APIVersion,
186 },
187 ObjectMeta: metav1.ObjectMeta{
188 Namespace: woc.wf.Namespace,
189 Name: woc.wf.Name,
190 Labels: labels,
191 OwnerReferences: []metav1.OwnerReference{
192 {
193 APIVersion: woc.wf.APIVersion,
194 Kind: woc.wf.Kind,
195 UID: woc.wf.UID,
196 Name: woc.wf.Name,
197 },
198 },
199 },
200 Spec: wfv1.WorkflowTaskSetSpec{
201 Tasks: woc.taskSet,
202 },
203 }
204 woc.log.Debug(ctx, "creating new taskset")
205
206 _, err := woc.controller.wfclientset.ArgoprojV1alpha1().WorkflowTaskSets(woc.wf.Namespace).Create(ctx, &taskSet, metav1.CreateOptions{})
207
208 if apierr.IsConflict(err) || apierr.IsAlreadyExists(err) {
209 woc.log.Debug(ctx, "patching the exiting taskset")
210 spec := map[string]interface{}{
211 "metadata": metav1.ObjectMeta{
212 Labels: map[string]string{
213 common.LabelKeyCompleted: strconv.FormatBool(woc.wf.Status.Fulfilled()),
214 },
215 },
216 "spec": wfv1.WorkflowTaskSetSpec{Tasks: woc.taskSet},
217 }
218 // patch the new templates into taskset
219 err = woc.mergePatchTaskSet(ctx, spec)
220 if err != nil {
221 woc.log.WithError(err).Error(ctx, "Failed to patch WorkflowTaskSet")
222 return fmt.Errorf("failed to patch TaskSet. %v", err)
223 }
224 } else if err != nil {
225 woc.log.WithError(err).Error(ctx, "Failed to create WorkflowTaskSet")
226 return err
227 }
228 return nil
229}

Callers 1

reconcileTaskSetMethod · 0.95

Calls 9

mergePatchTaskSetMethod · 0.95
InfoMethod · 0.65
DebugMethod · 0.65
CreateMethod · 0.65
WorkflowTaskSetsMethod · 0.65
ArgoprojV1alpha1Method · 0.65
ErrorMethod · 0.65
WithErrorMethod · 0.65
FulfilledMethod · 0.45

Tested by

no test coverage detected