Skip to content

Commit

Permalink
Fix multi-worker workflows: (#875)
Browse files Browse the repository at this point in the history
## Description


This fixes multi worker workflows. Previously, across workers, multitask workflows updating of the workflow status of each action after the first task didn't take previous tasks into account. Now it does.

## Why is this needed



Fixes: #

## How Has This Been Tested?



manually tested with Tink stack v0.4.3 helm chart.

Here's the template I tested with:

```yaml
apiVersion: "tinkerbell.org/v1alpha1"
kind: Template
metadata:
  name: multiworker
  namespace: tink-system
spec:
  data: |
    version: "0.1"
    name: multiworker
    global_timeout: 9800
    tasks:
      - name: "task 1"
        worker: "{{.device_1}}"
        volumes:
          - /dev:/dev
          - /dev/console:/dev/console
          - /lib/firmware:/lib/firmware:ro
        actions:
          - name: "action 1"
            image: alpine
            timeout: 120
            command: ["sleep", "2"]
          - name: "action 2"
            image: alpine
            timeout: 120
            command: ["sleep", "2"]
          - name: "action 3"
            image: alpine
            timeout: 120
            command: ["sleep", "2"]
      - name: "task 2"
        worker: "{{.device_1}}"
        volumes:
          - /dev:/dev
          - /dev/console:/dev/console
          - /lib/firmware:/lib/firmware:ro
        actions:
          - name: "action 1"
            image: alpine
            timeout: 120
            command: ["sleep", "2"]
          - name: "action 2"
            image: alpine
            timeout: 120
            command: ["sleep", "2"]
          - name: "action 3"
            image: alpine
            timeout: 120
            command: ["sleep", "2"]
      - name: "task 3"
        worker: "{{.device_2}}"
        volumes:
          - /dev:/dev
          - /dev/console:/dev/console
          - /lib/firmware:/lib/firmware:ro
        actions:
          - name: "sleep 1"
            image: alpine
            timeout: 120
            command: ["sleep", "2"]
          - name: "sleep 2"
            image: alpine
            timeout: 120
            command: ["sleep", "2"]
      - name: "task 4"
        worker: "{{.device_2}}"
        volumes:
          - /dev:/dev
          - /dev/console:/dev/console
          - /lib/firmware:/lib/firmware:ro
        actions:
          - name: "action 1"
            image: alpine
            timeout: 120
            command: ["sleep", "2"]
          - name: "action 2"
            image: alpine
            timeout: 120
            command: ["sleep", "2"]
```


## How are existing users impacted? What migration steps/scripts do we need?





## Checklist:

I have:

- [ ] updated the documentation and/or roadmap (if required)
- [ ] added unit or e2e tests
- [ ] provided instructions on how to upgrade
  • Loading branch information
mergify[bot] authored Feb 1, 2024
2 parents f2c141f + af82c36 commit 26be9ca
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/server/kubernetes_api_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,19 @@ func (s *KubernetesBackedServer) modifyWorkflowState(wf *v1alpha1.Workflow, wfCo
actionIndex = -1
)

seenActions := 0
for ti, task := range wf.Status.Tasks {
if wfContext.CurrentTask == task.Name {
taskIndex = ti
for ai, action := range task.Actions {
if action.Name == wfContext.CurrentAction && wfContext.CurrentActionIndex == int64(ai) {
if action.Name == wfContext.CurrentAction && (wfContext.CurrentActionIndex == int64(ai) || wfContext.CurrentActionIndex == int64(seenActions)) {
actionIndex = ai
goto cont
}
seenActions++
}
}
seenActions += len(task.Actions)
}
cont:

Expand Down

0 comments on commit 26be9ca

Please sign in to comment.