Skip to content

Commit

Permalink
Do Rufio/BMC actions before creating a workflow:
Browse files Browse the repository at this point in the history
This is to avoid a race condition that could occur
if a machine is running HookOS and Tink worker is
connected and running when a workflow is created.

The workflow would start to execute but then be cut
off when the reboot action is called. This has been
show to cause undefined behavior.

Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Mar 14, 2023
1 parent 6c5e8e5 commit 1d284b7
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions controllers/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,37 +143,40 @@ func (mrc *machineReconcileContext) Reconcile() error {
}

func (mrc *machineReconcileContext) reconcile(hw *tinkv1.Hardware) error {
if !isHardwareReady(hw) {
wf, err := mrc.ensureTemplateAndWorkflow(hw)
if isHardwareReady(hw) {
mrc.log.Info("Marking TinkerbellMachine as Ready")
mrc.tinkerbellMachine.Status.Ready = true

if ensureJobErr := mrc.ensureHardwareProvisionJob(hw); ensureJobErr != nil {
return fmt.Errorf("failed to ensure hardware ready for provisioning: %w", ensureJobErr)
}
return nil
}

switch {
case errors.Is(err, &errRequeueRequested{}):
return nil
case err != nil:
return fmt.Errorf("ensure template and workflow returned: %w", err)
}
if ensureJobErr := mrc.ensureHardwareProvisionJob(hw); ensureJobErr != nil {
return fmt.Errorf("failed to ensure hardware ready for provisioning: %w", ensureJobErr)
}

s := wf.GetCurrentActionState()
wf, err := mrc.ensureTemplateAndWorkflow(hw)

if s == tinkv1.WorkflowStateFailed || s == tinkv1.WorkflowStateTimeout {
return errWorkflowFailed
}
switch {
case errors.Is(err, &errRequeueRequested{}):
return nil
case err != nil:
return fmt.Errorf("ensure template and workflow returned: %w", err)
}

if !lastActionStarted(wf) {
return nil
}
s := wf.GetCurrentActionState()
if s == tinkv1.WorkflowStateFailed || s == tinkv1.WorkflowStateTimeout {
return errWorkflowFailed
}

if err := mrc.patchHardwareStates(hw, inUse, provisioned); err != nil {
return fmt.Errorf("failed to patch hardware: %w", err)
}
if !lastActionStarted(wf) {
return nil
}

mrc.log.Info("Marking TinkerbellMachine as Ready")
if err := mrc.patchHardwareStates(hw, inUse, provisioned); err != nil {
return fmt.Errorf("failed to patch hardware: %w", err)
}

mrc.log.Info("Marking TinkerbellMachine as Ready")
mrc.tinkerbellMachine.Status.Ready = true

return nil
Expand Down

0 comments on commit 1d284b7

Please sign in to comment.