Skip to content

Commit

Permalink
Change type of DiskSize to int to uint
Browse files Browse the repository at this point in the history
It help us to fix integer overflow issue with latest version of
golint-ci.
  • Loading branch information
praveenkumar committed Oct 8, 2024
1 parent 7f4bfec commit 329d1cd
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/crc/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func runStart(ctx context.Context) (*types.StartResult, error) {
startConfig := types.StartConfig{
BundlePath: config.Get(crcConfig.Bundle).AsString(),
Memory: config.Get(crcConfig.Memory).AsUInt(),
DiskSize: config.Get(crcConfig.DiskSize).AsInt(),
DiskSize: config.Get(crcConfig.DiskSize).AsUInt(),
CPUs: config.Get(crcConfig.CPUs).AsUInt(),
NameServer: config.Get(crcConfig.NameServer).AsString(),
PullSecret: cluster.NewInteractivePullSecretLoader(config),
Expand Down Expand Up @@ -187,7 +187,7 @@ func validateStartFlags() error {
if err := validation.ValidateCPUs(config.Get(crcConfig.CPUs).AsUInt(), crcConfig.GetPreset(config)); err != nil {
return err
}
if err := validation.ValidateDiskSize(config.Get(crcConfig.DiskSize).AsInt()); err != nil {
if err := validation.ValidateDiskSize(config.Get(crcConfig.DiskSize).AsUInt()); err != nil {
return err
}
if err := validation.ValidateBundle(config.Get(crcConfig.Bundle).AsString(), crcConfig.GetPreset(config)); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func getStartConfig(cfg crcConfig.Storage, args client.StartConfig) types.StartC
return types.StartConfig{
BundlePath: cfg.Get(crcConfig.Bundle).AsString(),
Memory: cfg.Get(crcConfig.Memory).AsUInt(),
DiskSize: cfg.Get(crcConfig.DiskSize).AsInt(),
DiskSize: cfg.Get(crcConfig.DiskSize).AsUInt(),
CPUs: cfg.Get(crcConfig.CPUs).AsUInt(),
NameServer: cfg.Get(crcConfig.NameServer).AsString(),
PullSecret: cluster.NewNonInteractivePullSecretLoader(cfg, args.PullSecretFile),
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/config/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func validateString(value interface{}) (bool, string) {

// validateDiskSize checks if provided disk size is valid in the config
func validateDiskSize(value interface{}) (bool, string) {
diskSize, err := cast.ToIntE(value)
diskSize, err := cast.ToUintE(value)
if err != nil {
return false, fmt.Sprintf("could not convert '%s' to integer", value)
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/crc/machine/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ type MachineConfig struct {
// Virtual machine configuration
Name string
// Memory holds value in MiB
Memory uint
CPUs uint
DiskSize int
Memory uint
CPUs uint
// DiskSize holds value in GiB
DiskSize uint
ImageSourcePath string
ImageFormat string
SSHKeyPath string
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/machine/config/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/crc-org/machine/libmachine/drivers"
)

func ConvertGiBToBytes(gib int) uint64 {
func ConvertGiBToBytes(gib uint) uint64 {
return uint64(gib) * 1024 * 1024 * 1024
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/machine/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func setVcpus(host *host.Host, vcpus uint) error {
return updateDriverValue(host, vcpuSetter)
}

func setDiskSize(host *host.Host, diskSizeGiB int) error {
func setDiskSize(host *host.Host, diskSizeGiB uint) error {
diskSizeSetter := func(driver *libmachine.VMDriver) bool {
capacity := config.ConvertGiBToBytes(diskSizeGiB)
if driver.DiskCapacity == capacity {
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/machine/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type StartConfig struct {
// Hypervisor
Memory uint // Memory size in MiB
CPUs uint
DiskSize int // Disk size in GiB
DiskSize uint // Disk size in GiB

// Nameserver
NameServer string
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func ValidateMemory(value uint, preset crcpreset.Preset) error {
return ValidateEnoughMemory(value)
}

func ValidateDiskSize(value int) error {
func ValidateDiskSize(value uint) error {
if value < constants.DefaultDiskSize {
return fmt.Errorf("requires disk size in GiB >= %d", constants.DefaultDiskSize)
}
Expand Down

0 comments on commit 329d1cd

Please sign in to comment.