Skip to content

Commit

Permalink
vm: support additional disks
Browse files Browse the repository at this point in the history
  • Loading branch information
Said Sakuh committed Nov 19, 2023
1 parent 0ab69ea commit e09ad4b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type Config struct {
type Disk struct {
Name string `yaml:"name"`
Size string `yaml:"size"`
Format string `yaml:"format"`
Format string `yaml:"format,omitempty"`
}

// Kubernetes is kubernetes configuration
Expand Down
10 changes: 10 additions & 0 deletions embedded/defaults/colima.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ sshConfig: true
# Default: []
mounts: []

# Configure additional disks
#
# EXAMPLE
# additionalDisks:
# - size: 10
# path: /tmp/colima/disk1.img
# - size: 20
# path: /tmp/colima/disk2.img
additionalDisks: []

# Environment variables for the virtual machine.
#
# EXAMPLE
Expand Down
19 changes: 19 additions & 0 deletions environment/vm/lima/lima.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ func (l *limaVM) resume(ctx context.Context, conf config.Config) error {

a.Add(l.writeNetworkFile)

if len(conf.Disks) > 0 {
for _, d := range conf.Disks {
log.Println("creating disk", d.Name)
a.Add(func() error {
return l.host.Run(limactl, "disk", "create", d.Name, "--size", d.Size, "--format", d.Format)
})
}
}

a.Stage("starting")
a.Add(func() error {
return l.host.Run(limactl, "start", config.CurrentProfile().ID)
Expand Down Expand Up @@ -227,6 +236,16 @@ func (l limaVM) Teardown(ctx context.Context) error {
return l.host.Run(limactl, "delete", "--force", config.CurrentProfile().ID)
})

conf, _ := limautil.InstanceConfig()

if len(conf.Disks) > 0 {
for _, d := range conf.Disks {
a.Add(func() error {
return l.host.Run(limactl, "disk", "delete", d.Name)
})
}
}

return a.Exec()
}

Expand Down

0 comments on commit e09ad4b

Please sign in to comment.