Skip to content

Commit

Permalink
fix: allow accepting rejected infra machines
Browse files Browse the repository at this point in the history
Accepting a previously rejected machine is ok, unlike rejecting a previously accepted machine.

Also prevent going back to the pending status from the accepted or rejected statuses.

Signed-off-by: Utku Ozdemir <[email protected]>
  • Loading branch information
utkuozdemir committed Dec 19, 2024
1 parent 3332684 commit 6190568
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions internal/backend/runtime/omni/state_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,8 +1082,14 @@ func infraMachineConfigValidationOptions(st state.State) []validated.StateOption
return nil
}

if oldRes.TypedSpec().Value.AcceptanceStatus != newRes.TypedSpec().Value.AcceptanceStatus {
return errors.New("acceptance status cannot be changed after it is accepted or rejected")
if oldRes.TypedSpec().Value.AcceptanceStatus != specs.InfraMachineConfigSpec_PENDING &&
newRes.TypedSpec().Value.AcceptanceStatus == specs.InfraMachineConfigSpec_PENDING {
return errors.New("an accepted or rejected machine cannot be set to back to pending acceptance")
}

if oldRes.TypedSpec().Value.AcceptanceStatus == specs.InfraMachineConfigSpec_ACCEPTED &&
newRes.TypedSpec().Value.AcceptanceStatus == specs.InfraMachineConfigSpec_REJECTED {
return errors.New("an accepted machine cannot be rejected")
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/backend/runtime/omni/state_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ func TestInfraMachineConfigValidation(t *testing.T) {
return nil
})
require.True(t, validated.IsValidationError(err), "expected validation error")
assert.ErrorContains(t, err, "acceptance status cannot be changed")
assert.ErrorContains(t, err, "an accepted machine cannot be rejected")

// try to destroy it

Expand Down

0 comments on commit 6190568

Please sign in to comment.