Skip to content

(feat): Add LVM support #10

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

Merged
merged 9 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
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
40 changes: 28 additions & 12 deletions cmd/ebs-bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func main() {
lds := service.NewLinuxDeviceService(erf)
uos := service.NewUnixOwnerService()
ans := service.NewAwsNitroNVMeService()
ls := service.NewLinuxLvmService(erf)
fssf := service.NewLinuxFileSystemServiceFactory(erf)

// Warnings
Expand All @@ -30,37 +31,50 @@ func main() {
c, err := config.New(os.Args)
checkError(err)

// Service + Config Consumers
// Services
db := backend.NewLinuxDeviceBackend(lds, fssf)
fb := backend.NewLinuxFileBackend(ufs)
ub := backend.NewLinuxOwnerBackend(uos)
dmb := backend.NewLinuxDeviceMetricsBackend(lds, fssf)
dae := action.NewDefaultActionExecutor()
lb := backend.NewLinuxLvmBackend(ls)

// Modify Config
modifiers := []config.Modifier{
config.NewAwsNVMeDriverModifier(ans, lds),
}
for _, m := range modifiers {
checkError(m.Modify(c))
}
// Executors
dae := action.NewDefaultActionExecutor()
le := layer.NewExponentialBackoffLayerExecutor(c, dae, layer.DefaultExponentialBackoffParameters())

// Validate Config
validators := []config.Validator{
config.NewFileSystemValidator(),
config.NewModeValidator(),
config.NewResizeThresholdValidator(),
config.NewDeviceValidator(lds),
config.NewMountPointValidator(),
config.NewMountOptionsValidator(),
config.NewOwnerValidator(uos),
config.NewLvmConsumptionValidator(),
}
for _, v := range validators {
checkError(v.Validate(c))
}

// Layers
le := layer.NewExponentialBackoffLayerExecutor(c, dae, layer.DefaultExponentialBackoffParameters())
// NVMe Device Modifier
checkError(config.NewAwsNVMeDriverModifier(ans, lds).Modify(c))

// LVM Layers
lvmLayers := []layer.Layer{
layer.NewCreatePhysicalVolumeLayer(db, lb),
layer.NewCreateVolumeGroupLayer(lb),
layer.NewCreateLogicalVolumeLayer(lb),
layer.NewActivateLogicalVolumeLayer(lb),
}
checkError(le.Execute(lvmLayers))

// LVM Modifiers
checkError(config.NewLvmModifier().Modify(c))

// Device Validator
checkError(config.NewDeviceValidator(lds).Validate(c))

// File System Layers
layers := []layer.Layer{
layer.NewFormatDeviceLayer(db),
layer.NewLabelDeviceLayer(db),
Expand All @@ -71,6 +85,8 @@ func main() {
layer.NewChangePermissionsLayer(fb),
}
checkError(le.Execute(layers))

log.Println("🟢 Passed all validation checks")
}

func checkError(err error) {
Expand Down
16 changes: 12 additions & 4 deletions configs/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
defaults:
lvmConsumption: 100
devices:
/dev/vdb:
fs: xfs
label: external-vol
mountPoint: /mnt/app
lvm: ifmx-etc
mountPoint: /mnt/foo
user: ubuntu
group: ubuntu
permissions: 755
/dev/vdc:
fs: xfs
lvm: ifmx-var
mountPoint: /mnt/bar
user: ubuntu
permissions: 0644
resizeFs: true
group: ubuntu
permissions: 755
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ module github.com/reecetech/ebs-bootstrap

go 1.21

require gopkg.in/yaml.v2 v2.4.0

require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0
github.com/google/go-cmp v0.6.0
github.com/ryanuber/go-glob v1.0.0
gopkg.in/yaml.v2 v2.4.0
)
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk=
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
172 changes: 172 additions & 0 deletions internal/action/lvm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package action

import (
"fmt"

"github.com/reecetech/ebs-bootstrap/internal/model"
"github.com/reecetech/ebs-bootstrap/internal/service"
)

type CreatePhysicalVolumeAction struct {
name string
mode model.Mode
lvmService service.LvmService
}

func NewCreatePhysicalVolumeAction(name string, ls service.LvmService) *CreatePhysicalVolumeAction {
return &CreatePhysicalVolumeAction{
name: name,
mode: model.Empty,
lvmService: ls,
}
}

func (a *CreatePhysicalVolumeAction) Execute() error {
return a.lvmService.CreatePhysicalVolume(a.name)
}

func (a *CreatePhysicalVolumeAction) GetMode() model.Mode {
return a.mode
}

func (a *CreatePhysicalVolumeAction) SetMode(mode model.Mode) Action {
a.mode = mode
return a
}

func (a *CreatePhysicalVolumeAction) Prompt() string {
return fmt.Sprintf("Would you like to create physical volume %s", a.name)
}

func (a *CreatePhysicalVolumeAction) Refuse() string {
return fmt.Sprintf("Refused to create physical volume %s", a.name)
}

func (a *CreatePhysicalVolumeAction) Success() string {
return fmt.Sprintf("Successfully created physical volume %s", a.name)
}

type CreateVolumeGroupAction struct {
name string
physicalVolume string
mode model.Mode
lvmService service.LvmService
}

func NewCreateVolumeGroupAction(name string, physicalVolume string, ls service.LvmService) *CreateVolumeGroupAction {
return &CreateVolumeGroupAction{
name: name,
physicalVolume: physicalVolume,
mode: model.Empty,
lvmService: ls,
}
}

func (a *CreateVolumeGroupAction) Execute() error {
return a.lvmService.CreateVolumeGroup(a.name, a.physicalVolume)
}

func (a *CreateVolumeGroupAction) GetMode() model.Mode {
return a.mode
}

func (a *CreateVolumeGroupAction) SetMode(mode model.Mode) Action {
a.mode = mode
return a
}

func (a *CreateVolumeGroupAction) Prompt() string {
return fmt.Sprintf("Would you like to create volume group %s on physical volume %s", a.name, a.physicalVolume)
}

func (a *CreateVolumeGroupAction) Refuse() string {
return fmt.Sprintf("Refused to create volume group %s on physical volume %s", a.name, a.physicalVolume)
}

func (a *CreateVolumeGroupAction) Success() string {
return fmt.Sprintf("Successfully created volume group %s on physical volume %s", a.name, a.physicalVolume)
}

type CreateLogicalVolumeAction struct {
name string
freeSpacePercent int
volumeGroup string
mode model.Mode
lvmService service.LvmService
}

func NewCreateLogicalVolumeAction(name string, freeSpacePercent int, volumeGroup string, ls service.LvmService) *CreateLogicalVolumeAction {
return &CreateLogicalVolumeAction{
name: name,
freeSpacePercent: freeSpacePercent,
volumeGroup: volumeGroup,
mode: model.Empty,
lvmService: ls,
}
}

func (a *CreateLogicalVolumeAction) Execute() error {
return a.lvmService.CreateLogicalVolume(a.name, a.volumeGroup, a.freeSpacePercent)
}

func (a *CreateLogicalVolumeAction) GetMode() model.Mode {
return a.mode
}

func (a *CreateLogicalVolumeAction) SetMode(mode model.Mode) Action {
a.mode = mode
return a
}

func (a *CreateLogicalVolumeAction) Prompt() string {
return fmt.Sprintf("Would you like to create logical volume %s that consumes %d%% free space of volume group %s", a.name, a.freeSpacePercent, a.volumeGroup)
}

func (a *CreateLogicalVolumeAction) Refuse() string {
return fmt.Sprintf("Refused to create logical volume %s that consumes %d%% free space of volume group %s", a.name, a.freeSpacePercent, a.volumeGroup)
}

func (a *CreateLogicalVolumeAction) Success() string {
return fmt.Sprintf("Successfully created logical volume %s that consumes %d%% free space of volume group %s", a.name, a.freeSpacePercent, a.volumeGroup)
}

type ActivateLogicalVolumeAction struct {
name string
volumeGroup string
mode model.Mode
lvmService service.LvmService
}

func NewActivateLogicalVolumeAction(name string, volumeGroup string, ls service.LvmService) *ActivateLogicalVolumeAction {
return &ActivateLogicalVolumeAction{
name: name,
volumeGroup: volumeGroup,
mode: model.Empty,
lvmService: ls,
}
}

func (a *ActivateLogicalVolumeAction) Execute() error {
return a.lvmService.ActivateLogicalVolume(a.name, a.volumeGroup)
}

func (a *ActivateLogicalVolumeAction) GetMode() model.Mode {
return a.mode
}

func (a *ActivateLogicalVolumeAction) SetMode(mode model.Mode) Action {
a.mode = mode
return a
}

func (a *ActivateLogicalVolumeAction) Prompt() string {
return fmt.Sprintf("Would you like to activate logical volume %s in volume group %s", a.name, a.volumeGroup)
}

func (a *ActivateLogicalVolumeAction) Refuse() string {
return fmt.Sprintf("Refused to activate logical volume %s in volume group %s", a.name, a.volumeGroup)
}

func (a *ActivateLogicalVolumeAction) Success() string {
return fmt.Sprintf("Successfully activated logical volume %s in volume group %s", a.name, a.volumeGroup)
}
Loading
Loading