Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only allow erasing disks under very certain circumstances. #57

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func Run(spec *Specification, hal hal.InBand) (*event.EventEmitter, error) {
if err != nil {
return eventEmitter, errors.Wrap(err, "fetch")
}

if m != nil && m.Allocation != nil && m.Allocation.Reinstall != nil && *m.Allocation.Reinstall {
hammer.FilesystemLayout = m.Allocation.Filesystemlayout
primaryDiskWiped := false
Expand All @@ -143,9 +144,22 @@ func Run(spec *Specification, hal hal.InBand) (*event.EventEmitter, error) {
return eventEmitter, err
}

err = storage.WipeDisks()
if err != nil {
return eventEmitter, errors.Wrap(err, "wipe")
wipeDisks := false
if m == nil || m.Allocation == nil {
// the machine belongs to no one, we can safely erase disks
wipeDisks = true
}
if m != nil && m.Allocation != nil && !*m.Allocation.Succeeded {
// the allocation has not succeeded, so a user was never able to work with this machine
// we're most certainly running in a crash loop and are safe to start all over again
wipeDisks = true
}

if wipeDisks {
err = storage.WipeDisks()
if err != nil {
return eventEmitter, errors.Wrap(err, "wipe")
}
}

err = hammer.ConfigureBIOS()
Expand Down