Skip to content
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

fix: Fix to allow users to configure disk size for finch space #715

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion e2e/vm/additional_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand Down Expand Up @@ -56,5 +57,13 @@ var testAdditionalDisk = func(o *option.Option) {
gomega.Expect(command.StdoutStr(o, "exec", containerName, "cat", "/tmp/test.txt")).
Should(gomega.Equal("foo"))
})

ginkgo.It("should correctly configure disk size as specified in finch.yaml", func() {
resetVM(o, installed)
resetDisks(o, installed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will users lose their persistent data if they have to resize their disk?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the resolution for this? Can this be run without resetDisks with a test that checks the containers prior to resize are available after resize. As mentioned in the ticket ".After I update the value, stop the VM, and then start the VM, the value should take effect."

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))
})
})
}
2 changes: 1 addition & 1 deletion e2e/vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion pkg/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -22,9 +23,11 @@ import (
const (
// diskName must always be consistent with the value under additionalDisks in finch.yaml.
diskName = "finch"
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 {
EnsureUserDataDisk() error
Expand Down Expand Up @@ -191,6 +194,13 @@ 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
vsiravar marked this conversation as resolved.
Show resolved Hide resolved
}
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)
Expand Down
Loading