From 7435a5981e09146db48a6232da1de73c1e4a560a Mon Sep 17 00:00:00 2001 From: summer <42436637+qiao-summer@users.noreply.github.com> Date: Thu, 5 Dec 2024 00:02:55 +0800 Subject: [PATCH] config: ability to specifying memory in decimal GiB (#1206) Co-authored-by: summer --- cmd/start.go | 2 +- config/config.go | 2 +- environment/vm/lima/yaml.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/start.go b/cmd/start.go index 600ae7b7c..eac419e79 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -158,7 +158,7 @@ func init() { startCmd.Flags().BoolVar(&startCmdArgs.Flags.ActivateRuntime, "activate", true, "set as active Docker/Kubernetes context on startup") startCmd.Flags().IntVarP(&startCmdArgs.CPU, "cpu", "c", defaultCPU, "number of CPUs") startCmd.Flags().StringVar(&startCmdArgs.CPUType, "cpu-type", "", "the CPU type, options can be checked with 'qemu-system-"+defaultArch+" -cpu help'") - startCmd.Flags().IntVarP(&startCmdArgs.Memory, "memory", "m", defaultMemory, "memory in GiB") + startCmd.Flags().Float32VarP(&startCmdArgs.Memory, "memory", "m", defaultMemory, "memory in GiB") startCmd.Flags().IntVarP(&startCmdArgs.Disk, "disk", "d", defaultDisk, "disk size in GiB") startCmd.Flags().StringVarP(&startCmdArgs.Arch, "arch", "a", defaultArch, "architecture (aarch64, x86_64)") startCmd.Flags().BoolVarP(&startCmdArgs.Flags.Foreground, "foreground", "f", false, "Keep colima in the foreground") diff --git a/config/config.go b/config/config.go index 071aadac6..9c904b383 100644 --- a/config/config.go +++ b/config/config.go @@ -28,7 +28,7 @@ var ( type Config struct { CPU int `yaml:"cpu,omitempty"` Disk int `yaml:"disk,omitempty"` - Memory int `yaml:"memory,omitempty"` + Memory float32 `yaml:"memory,omitempty"` Arch string `yaml:"arch,omitempty"` CPUType string `yaml:"cpuType,omitempty"` Network Network `yaml:"network,omitempty"` diff --git a/environment/vm/lima/yaml.go b/environment/vm/lima/yaml.go index a6c041dd7..33e0dabdb 100644 --- a/environment/vm/lima/yaml.go +++ b/environment/vm/lima/yaml.go @@ -60,7 +60,7 @@ func newConf(ctx context.Context, conf config.Config) (l limaconfig.Config, err l.CPUs = &conf.CPU } if conf.Memory > 0 { - l.Memory = fmt.Sprintf("%dGiB", conf.Memory) + l.Memory = fmt.Sprintf("%dMiB", uint32(conf.Memory*1024)) } if conf.Disk > 0 { l.Disk = fmt.Sprintf("%dGiB", conf.Disk)