newWorkflowOperationCtx creates and initializes a new wfOperationCtx object.
(ctx context.Context, wf *wfv1.Workflow, wfc *WorkflowController)
| 149 | |
| 150 | // newWorkflowOperationCtx creates and initializes a new wfOperationCtx object. |
| 151 | func newWorkflowOperationCtx(ctx context.Context, wf *wfv1.Workflow, wfc *WorkflowController) *wfOperationCtx { |
| 152 | // NEVER modify objects from the store. It's a read-only, local cache. |
| 153 | // You can use DeepCopy() to make a deep copy of original object and modify this copy |
| 154 | // Or create a copy manually for better performance |
| 155 | wfCopy := wf.DeepCopyObject().(*wfv1.Workflow) |
| 156 | |
| 157 | slogger := logging.RequireLoggerFromContext(ctx) |
| 158 | |
| 159 | woc := wfOperationCtx{ |
| 160 | wf: wfCopy, |
| 161 | orig: wf, |
| 162 | execWf: wfCopy, |
| 163 | updated: false, |
| 164 | log: slogger.WithFields(logging.Fields{ |
| 165 | "workflow": wf.Name, |
| 166 | "namespace": wf.Namespace, |
| 167 | }), |
| 168 | controller: wfc, |
| 169 | globalParams: make(map[string]string), |
| 170 | volumes: wf.Spec.DeepCopy().Volumes, |
| 171 | deadline: time.Now().UTC().Add(maxOperationTime), |
| 172 | eventRecorder: wfc.eventRecorderManager.Get(ctx, wf.Namespace), |
| 173 | preExecutionNodeStatuses: make(map[string]wfv1.NodeStatus), |
| 174 | taskSet: make(map[string]wfv1.Template), |
| 175 | currentStackDepth: 0, |
| 176 | } |
| 177 | |
| 178 | if woc.wf.Status.Nodes == nil { |
| 179 | woc.wf.Status.Nodes = make(map[string]wfv1.NodeStatus) |
| 180 | } |
| 181 | |
| 182 | if woc.wf.Status.StoredTemplates == nil { |
| 183 | woc.wf.Status.StoredTemplates = make(map[string]wfv1.Template) |
| 184 | } |
| 185 | return &woc |
| 186 | } |
| 187 | |
| 188 | // operate is the main operator logic of a workflow. It evaluates the current state of the workflow, |
| 189 | // and its pods and decides how to proceed down the execution path. |