From 086df29562bded860e8dd6492fe0f7a81c7c7ecf Mon Sep 17 00:00:00 2001 From: Hayato Kiwata Date: Mon, 4 Dec 2023 03:11:27 +0900 Subject: [PATCH 1/3] fix: Fix to allow users to configure disk size for finch space In the current implementation, the disk space allocated for finch is hard-coded with a fixed value of 50G. Therefore, when users pull large docker images and use more than 50G of the allocated finch space, "no space left on device" error may occur. As mentioned above, the disk size available for finch is fixed at 50GB and cannot be set by users. To work around this setting, they need to rewrite the hard-coded parts and use their own build of finch, but this is very time-consuming. Alternatively, they can use the following method to change the disk size. - https://github.com/runfinch/finch/issues/275#issuecomment-1577010453 Thus, although there is some workarounds to adjust the disk size for finch, users will be able to use finch more flexibly if they are able to specify the disk size that finch can use at the time of vm init. Therefore, this fix improves usability by allowing users to run "finch vm init" and flexibly set the size of the disk created for finch based on the finchDiskSize in ~/.finch/finch.yaml. Note that for finch at present, the size of finchDiskSize becomes the disk size of the finch area only when the vm is initialized ("finch vm init"). Signed-off-by: Hayato Kiwata --- README.md | 3 +++ pkg/config/config.go | 3 +++ pkg/disk/disk.go | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/README.md b/README.md index d45ea8e9e..96b9fb646 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,9 @@ vmType: "qemu" # Only available when using vmType "vz" on Apple Silicon running macOS 13+. # If true, also sets vmType to "vz". rosetta: false +# finchDiskSize: the amount of disk size allocated for finch space in the virtual machine. (optional) +# Only takes effect when a new VM is launched (only on vm init). +finchDiskSize: 50GB ``` ### FAQ diff --git a/pkg/config/config.go b/pkg/config/config.go index 88416b03a..21e3e50ea 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -55,6 +55,9 @@ type Finch struct { // Has no effect on systems where Rosetta 2 is not available (Intel/AMD64 macs, or macOS < 13.0). // This setting will only be applied on vm init. Rosetta *bool `yaml:"rosetta,omitempty"` + // FinchDiskSize: the amount of disk size allocated for finch space in the virtual machine. + // This setting will only be applied on vm init. + FinchDiskSize *string `yaml:"finchDiskSize,omitempty"` } // Nerdctl is a copy from github.com/containerd/nerdctl/cmd/nerdctl/main.go diff --git a/pkg/disk/disk.go b/pkg/disk/disk.go index 553c260a0..ba089f7ff 100644 --- a/pkg/disk/disk.go +++ b/pkg/disk/disk.go @@ -22,6 +22,10 @@ import ( const ( // diskName must always be consistent with the value under additionalDisks in finch.yaml. diskName = "finch" +) + +var ( + // the amount of disk size allocated for finch space in the virtual machine. diskSize = "50G" ) @@ -191,6 +195,9 @@ func (m *userDataDiskManager) convertToRaw(diskPath string) error { } func (m *userDataDiskManager) createLimaDisk() error { + if m.config.FinchDiskSize != nil { + diskSize = *m.config.FinchDiskSize + } cmd := m.lcc.CreateWithoutStdio("disk", "create", diskName, "--size", diskSize, "--format", "raw") if logs, err := cmd.CombinedOutput(); err != nil { return fmt.Errorf("failed to create disk, debug logs:\n%s", logs) From 097187aa0870da8ea709974566029901b3c3fb7b Mon Sep 17 00:00:00 2001 From: Hayato Kiwata Date: Fri, 8 Dec 2023 01:18:03 +0900 Subject: [PATCH 2/3] fix: Fix to allow users to configure disk size for finch space Signed-off-by: Hayato Kiwata --- e2e/vm/additional_disk_test.go | 12 +++++++++++- e2e/vm/vm_test.go | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/e2e/vm/additional_disk_test.go b/e2e/vm/additional_disk_test.go index 7c0dfb3c6..3ee041e7c 100644 --- a/e2e/vm/additional_disk_test.go +++ b/e2e/vm/additional_disk_test.go @@ -8,6 +8,7 @@ import ( "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" + "github.com/onsi/gomega/gexec" "github.com/runfinch/common-tests/command" "github.com/runfinch/common-tests/option" ) @@ -19,7 +20,7 @@ const ( networkName = "test-network" ) -var testAdditionalDisk = func(o *option.Option) { +var testAdditionalDisk = func(o *option.Option, installed bool) { ginkgo.Describe("Additional disk", ginkgo.Serial, func() { ginkgo.It("Retains container user data after the VM is deleted", func() { command.Run(o, "volume", "create", volumeName) @@ -55,6 +56,15 @@ var testAdditionalDisk = func(o *option.Option) { command.Run(o, "start", containerName) gomega.Expect(command.StdoutStr(o, "exec", containerName, "cat", "/tmp/test.txt")). Should(gomega.Equal("foo")) + + }) + + ginkgo.It("finch vm init by the disk size for finch area configured in finchDiskSize of ~/.finch.yaml", func() { + resetVM(o, installed) + resetDisks(o, installed) + writeFile(finchConfigFilePath, []byte("cpus: 6\nmemory: 4GiB\nvmType: qemu\nrosetta: false\nfinchDiskSize: 3GB")) + initCmdSession := command.New(o, virtualMachineRootCmd, "init").WithTimeoutInSeconds(600).Run() + gomega.Expect(initCmdSession).Should(gexec.Exit(0)) }) }) } diff --git a/e2e/vm/vm_test.go b/e2e/vm/vm_test.go index 02245e356..9f0345471 100644 --- a/e2e/vm/vm_test.go +++ b/e2e/vm/vm_test.go @@ -46,7 +46,7 @@ func TestVM(t *testing.T) { ginkgo.Describe("", func() { testVMLifecycle(o) - testAdditionalDisk(o) + testAdditionalDisk(o, *e2e.Installed) testConfig(o, *e2e.Installed) testFinchConfigFile(o) testVersion(o) From 8c1df1aeaf3fb91cbc2367d7ce0fe17566422b94 Mon Sep 17 00:00:00 2001 From: Hayato Kiwata Date: Fri, 15 Dec 2023 01:39:25 +0900 Subject: [PATCH 3/3] fix: Fix to allow users to configure disk size for finch space The following parts have been corrected in accordance with the review. - Fix text for ginkgo.It blocks in e2e/vm/additional_disk_test.go - Apply golangci-lint - Add validation finchDiskSize from finch.yaml Signed-off-by: Hayato Kiwata --- e2e/vm/additional_disk_test.go | 3 +-- pkg/disk/disk.go | 11 +++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/e2e/vm/additional_disk_test.go b/e2e/vm/additional_disk_test.go index 3ee041e7c..bf2f8d01f 100644 --- a/e2e/vm/additional_disk_test.go +++ b/e2e/vm/additional_disk_test.go @@ -56,10 +56,9 @@ var testAdditionalDisk = func(o *option.Option, installed bool) { command.Run(o, "start", containerName) gomega.Expect(command.StdoutStr(o, "exec", containerName, "cat", "/tmp/test.txt")). Should(gomega.Equal("foo")) - }) - ginkgo.It("finch vm init by the disk size for finch area configured in finchDiskSize of ~/.finch.yaml", func() { + ginkgo.It("should correctly configure disk size as specified in finch.yaml", func() { resetVM(o, installed) resetDisks(o, installed) writeFile(finchConfigFilePath, []byte("cpus: 6\nmemory: 4GiB\nvmType: qemu\nrosetta: false\nfinchDiskSize: 3GB")) diff --git a/pkg/disk/disk.go b/pkg/disk/disk.go index ba089f7ff..e11708004 100644 --- a/pkg/disk/disk.go +++ b/pkg/disk/disk.go @@ -11,6 +11,7 @@ import ( "io/fs" "path" + "github.com/docker/go-units" limaStore "github.com/lima-vm/lima/pkg/store" "github.com/spf13/afero" @@ -24,10 +25,8 @@ const ( diskName = "finch" ) -var ( - // the amount of disk size allocated for finch space in the virtual machine. - diskSize = "50G" -) +// the amount of disk size allocated for finch space in the virtual machine. +var diskSize = "50G" // UserDataDiskManager is used to check the user data disk configuration and create it if needed. type UserDataDiskManager interface { @@ -196,6 +195,10 @@ func (m *userDataDiskManager) convertToRaw(diskPath string) error { func (m *userDataDiskManager) createLimaDisk() error { if m.config.FinchDiskSize != nil { + _, err := units.RAMInBytes(*m.config.FinchDiskSize) + if err != nil { + return err + } diskSize = *m.config.FinchDiskSize } cmd := m.lcc.CreateWithoutStdio("disk", "create", diskName, "--size", diskSize, "--format", "raw")