Skip to content

Commit

Permalink
(feat): Change lvmConsumption from int to uint64
Browse files Browse the repository at this point in the history
  • Loading branch information
lasith-kg committed May 24, 2024
1 parent 7fe11bb commit 5336268
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
8 changes: 4 additions & 4 deletions internal/action/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ func (a *CreateVolumeGroupAction) Success() string {

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

func NewCreateLogicalVolumeAction(name string, volumeGroupPercent int, volumeGroup string, ls service.LvmService) *CreateLogicalVolumeAction {
func NewCreateLogicalVolumeAction(name string, volumeGroupPercent uint64, volumeGroup string, ls service.LvmService) *CreateLogicalVolumeAction {
return &CreateLogicalVolumeAction{
name: name,
volumeGroupPercent: volumeGroupPercent,
Expand Down Expand Up @@ -212,13 +212,13 @@ func (a *ResizePhysicalVolumeAction) Success() string {

type ResizeLogicalVolumeAction struct {
name string
volumeGroupPercent int
volumeGroupPercent uint64
volumeGroup string
mode model.Mode
lvmService service.LvmService
}

func NewResizeLogicalVolumeAction(name string, volumeGroupPercent int, volumeGroup string, ls service.LvmService) *ResizeLogicalVolumeAction {
func NewResizeLogicalVolumeAction(name string, volumeGroupPercent uint64, volumeGroup string, ls service.LvmService) *ResizeLogicalVolumeAction {
return &ResizeLogicalVolumeAction{
name: name,
volumeGroupPercent: volumeGroupPercent,
Expand Down
12 changes: 6 additions & 6 deletions internal/backend/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ const (
type LvmBackend interface {
CreatePhysicalVolume(name string) action.Action
CreateVolumeGroup(name string, physicalVolume string) action.Action
CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) action.Action
CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) action.Action
ActivateLogicalVolume(name string, volumeGroup string) action.Action
GetVolumeGroups(name string) []*model.VolumeGroup
GetLogicalVolume(name string, volumeGroup string) (*model.LogicalVolume, error)
SearchLogicalVolumes(volumeGroup string) ([]*model.LogicalVolume, error)
SearchVolumeGroup(physicalVolume string) (*model.VolumeGroup, error)
ShouldResizePhysicalVolume(name string) (bool, error)
ResizePhysicalVolume(name string) action.Action
ShouldResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) (bool, error)
ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) action.Action
ShouldResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) (bool, error)
ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) action.Action
From(config *config.Config) error
}

Expand Down Expand Up @@ -154,7 +154,7 @@ func (lb *LinuxLvmBackend) CreateVolumeGroup(name string, physicalVolume string)
return action.NewCreateVolumeGroupAction(name, physicalVolume, lb.lvmService)
}

func (lb *LinuxLvmBackend) CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) action.Action {
func (lb *LinuxLvmBackend) CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) action.Action {
return action.NewCreateLogicalVolumeAction(name, volumeGroupPercent, volumeGroup, lb.lvmService)
}

Expand All @@ -178,7 +178,7 @@ func (lb *LinuxLvmBackend) ResizePhysicalVolume(name string) action.Action {
return action.NewResizePhysicalVolumeAction(name, lb.lvmService)
}

func (lb *LinuxLvmBackend) ShouldResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) (bool, error) {
func (lb *LinuxLvmBackend) ShouldResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) (bool, error) {
left := float64(volumeGroupPercent) - LogicalVolumeResizeTolerance
right := float64(volumeGroupPercent) + LogicalVolumeResizeTolerance
lvn, err := lb.lvmGraph.GetLogicalVolume(name, volumeGroup)
Expand All @@ -196,7 +196,7 @@ func (lb *LinuxLvmBackend) ShouldResizeLogicalVolume(name string, volumeGroup st
return usedPerecent < left, nil
}

func (lb *LinuxLvmBackend) ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) action.Action {
func (lb *LinuxLvmBackend) ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) action.Action {
return action.NewResizeLogicalVolumeAction(name, volumeGroupPercent, volumeGroup, lb.lvmService)
}

Expand Down
8 changes: 4 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Flag struct {
Remount bool
MountOptions string
Resize bool
LvmConsumption int
LvmConsumption uint64
}

type Device struct {
Expand All @@ -41,7 +41,7 @@ type Options struct {
Remount bool `yaml:"remount"`
MountOptions model.MountOptions `yaml:"mountOptions"`
Resize bool `yaml:"resize"`
LvmConsumption int `yaml:"lvmConsumption"`
LvmConsumption uint64 `yaml:"lvmConsumption"`
}

// We don't export "overrides" as this is an attribute that is used
Expand Down Expand Up @@ -99,7 +99,7 @@ func parseFlags(program string, args []string) (*Flag, error) {
flags.BoolVar(&f.Remount, "remount", false, "override for remount")
flags.StringVar(&f.MountOptions, "mount-options", "", "override for mount options")
flags.BoolVar(&f.Resize, "resize", false, "override for resize filesystem")
flags.IntVar(&f.LvmConsumption, "lvm-consumption", 0, "override for lvm consumption")
flags.Uint64Var(&f.LvmConsumption, "lvm-consumption", 0, "override for lvm consumption")

// Actually parse the flag
err := flags.Parse(args)
Expand Down Expand Up @@ -169,7 +169,7 @@ func (c *Config) GetResize(name string) bool {
return c.overrides.Resize || c.Defaults.Resize || cd.Resize
}

func (c *Config) GetLvmConsumption(name string) int {
func (c *Config) GetLvmConsumption(name string) uint64 {
cd, found := c.Devices[name]
if !found {
return DefaultLvmConsumption
Expand Down
4 changes: 2 additions & 2 deletions internal/config/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,6 @@ func (lcv *LvmConsumptionValidator) Validate(c *Config) error {
return nil
}

func (lcv *LvmConsumptionValidator) isValid(lc int) bool {
return lc >= 0 && lc <= 100
func (lcv *LvmConsumptionValidator) isValid(lc uint64) bool {
return lc <= 100
}
8 changes: 4 additions & 4 deletions internal/service/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ type LvmService interface {
GetLogicalVolumes() ([]*model.LogicalVolume, error)
CreatePhysicalVolume(name string) error
CreateVolumeGroup(name string, physicalVolume string) error
CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) error
CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) error
ActivateLogicalVolume(name string, volumeGroup string) error
ResizePhysicalVolume(name string) error
ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) error
ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) error
}

type LinuxLvmService struct {
Expand Down Expand Up @@ -192,7 +192,7 @@ func (ls *LinuxLvmService) CreateVolumeGroup(name string, physicalVolume string)
return err
}

func (ls *LinuxLvmService) CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) error {
func (ls *LinuxLvmService) CreateLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) error {
r := ls.runnerFactory.Select(utils.LvCreate)
_, err := r.Command("-l", fmt.Sprintf("%d%%VG", volumeGroupPercent), "-n", name, volumeGroup)
return err
Expand All @@ -210,7 +210,7 @@ func (ls *LinuxLvmService) ResizePhysicalVolume(name string) error {
return err
}

func (ls *LinuxLvmService) ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent int) error {
func (ls *LinuxLvmService) ResizeLogicalVolume(name string, volumeGroup string, volumeGroupPercent uint64) error {
r := ls.runnerFactory.Select(utils.LvExtend)
_, err := r.Command("-l", fmt.Sprintf("%d%%VG", volumeGroupPercent), fmt.Sprintf("%s/%s", volumeGroup, name))
return err
Expand Down

0 comments on commit 5336268

Please sign in to comment.