Skip to content

Commit

Permalink
Extract disk wiping from disk partitioning (#91)
Browse files Browse the repository at this point in the history
## Description
Extracting the Wipe functionality and add it as a dedicated command, where user can only wipe disks without any partitioning, using the metadata of the Hardware. 



## Why is this needed
This is very helpful, when the provisioned machine, is gonna be used by some storage specific services or SDS operator, as some of those operators don't use disks that are in a specific status(for example if the disks have partitions, the storage operator would considered this disk is being used by anther software and wouldn't use and utilize it).


Fixes: #90

## How Has This Been Tested?



It was tested by using this commit and build an image out of it, where this image has been use as a workflow to de provision a machine. 

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




## 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 Sep 21, 2022
2 parents 5f58001 + 7d47827 commit 8e1f99f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 25 deletions.
24 changes: 24 additions & 0 deletions actions/rootio/v1/cmd/rootio.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var rootioCmd = &cobra.Command{
}

func init() {
rootioCmd.AddCommand(rootioWipe)
rootioCmd.AddCommand(rootioFormat)
rootioCmd.AddCommand(rootioPartition)
rootioCmd.AddCommand(rootioMount)
Expand Down Expand Up @@ -116,6 +117,29 @@ var rootioPartition = &cobra.Command{
},
}

var rootioWipe = &cobra.Command{
Use: "wipe",
Short: "Use rootio to wipe disks based upon metadata",
Run: func(cmd *cobra.Command, args []string) {
for disk := range metadata.Instance.Storage.Disks {
err := storage.VerifyBlockDevice(metadata.Instance.Storage.Disks[disk].Device)
if err != nil {
log.Error(err)
}
err = storage.ExamineDisk(metadata.Instance.Storage.Disks[disk])
if err != nil {
log.Error(err)
}

err = storage.Wipe(metadata.Instance.Storage.Disks[disk])
log.Infoln("Wiping")
if err != nil {
log.Error(err)
}
}
},
}

var rootioVersion = &cobra.Command{
Use: "version",
Short: "Version and Release information about the rootio storage manager",
Expand Down
25 changes: 0 additions & 25 deletions actions/rootio/v1/pkg/storage/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,28 +197,3 @@ func MBRPartition(d types.Disk) error {
}
return nil
}

// Wipe will clean the table from a disk.
func Wipe(d types.Disk) error {
disk, err := os.OpenFile(d.Device, os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return err
}
defer disk.Close()
bigBuff := make([]byte, 1024*1024*1024)
n, err := disk.Write(bigBuff)
if err != nil {
return err
}
log.Infof("Wrote [%d] bytes to [%s]", n, d.Device)
log.Infoln("Flushing writes to new partition")
err = disk.Sync()
if err != nil {
return err
}
err = disk.Close()
if err != nil {
return err
}
return nil
}
33 changes: 33 additions & 0 deletions actions/rootio/v1/pkg/storage/wipe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package storage

import (
"os"

log "github.com/sirupsen/logrus"
"github.com/tinkerbell/hub/actions/rootio/v1/pkg/types.go"
)

// Wipe will clean the table from a disk.
func Wipe(d types.Disk) error {
disk, err := os.OpenFile(d.Device, os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return err
}
defer disk.Close()
bigBuff := make([]byte, 1024*1024*1024)
n, err := disk.Write(bigBuff)
if err != nil {
return err
}
log.Infof("Wrote [%d] bytes to [%s]", n, d.Device)
log.Infoln("Flushing writes to new partition")
err = disk.Sync()
if err != nil {
return err
}
err = disk.Close()
if err != nil {
return err
}
return nil
}

0 comments on commit 8e1f99f

Please sign in to comment.