Skip to content

Commit

Permalink
chore: allow not preallocated disks for QEMU cluster
Browse files Browse the repository at this point in the history
Preallocation still done by default for correct max usage estimates, but
in development environment it could be beneficial not to use up that
space, so I added a flag to disable preallocation

Signed-off-by: Dmitry Sharshakov <d3dx12.xx@gmail.com>
Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
  • Loading branch information
dsseng authored and smira committed Feb 23, 2024
1 parent 0bddfea commit 4575dd8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
14 changes: 10 additions & 4 deletions cmd/talosctl/cmd/mgmt/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const (
networkCIDRFlag = "cidr"
nameserversFlag = "nameservers"
clusterDiskSizeFlag = "disk"
clusterDiskPreallocateFlag = "disk-preallocate"
clusterDisksFlag = "user-disk"
customCNIUrlFlag = "custom-cni-url"
talosVersionFlag = "talos-version"
Expand Down Expand Up @@ -124,6 +125,7 @@ var (
controlPlaneMemory int
workersMemory int
clusterDiskSize int
clusterDiskPreallocate bool
clusterDisks []string
extraDisks int
extraDiskSize int
Expand Down Expand Up @@ -796,7 +798,8 @@ func create(ctx context.Context, flags *pflag.FlagSet) error {
// append extra disks
for i := 0; i < extraDisks; i++ {
disks = append(disks, &provision.Disk{
Size: uint64(extraDiskSize) * 1024 * 1024,
Size: uint64(extraDiskSize) * 1024 * 1024,
SkipPreallocate: !clusterDiskPreallocate,
})
}

Expand Down Expand Up @@ -997,7 +1000,8 @@ func getDisks() ([]*provision.Disk, error) {
// should have at least a single primary disk
disks := []*provision.Disk{
{
Size: uint64(clusterDiskSize) * 1024 * 1024,
Size: uint64(clusterDiskSize) * 1024 * 1024,
SkipPreallocate: !clusterDiskPreallocate,
},
}

Expand Down Expand Up @@ -1042,8 +1046,9 @@ func getDisks() ([]*provision.Disk, error) {

disks = append(disks, &provision.Disk{
// add 1 MB to make extra room for GPT and alignment
Size: diskSize + 2*1024*1024,
Partitions: diskPartitions,
Size: diskSize + 2*1024*1024,
Partitions: diskPartitions,
SkipPreallocate: !clusterDiskPreallocate,
})
}

Expand Down Expand Up @@ -1091,6 +1096,7 @@ func init() {
createCmd.Flags().IntVar(&controlPlaneMemory, "memory", 2048, "the limit on memory usage in MB (each control plane/VM)")
createCmd.Flags().IntVar(&workersMemory, "memory-workers", 2048, "the limit on memory usage in MB (each worker/VM)")
createCmd.Flags().IntVar(&clusterDiskSize, clusterDiskSizeFlag, 6*1024, "default limit on disk size in MB (each VM)")
createCmd.Flags().BoolVar(&clusterDiskPreallocate, clusterDiskPreallocateFlag, true, "whether disk space should be preallocated")
createCmd.Flags().StringSliceVar(&clusterDisks, clusterDisksFlag, []string{}, "list of disks to create for each VM in format: <mount_point1>:<size1>:<mount_point2>:<size2>")
createCmd.Flags().IntVar(&extraDisks, "extra-disks", 0, "number of extra disks to create for each worker VM")
createCmd.Flags().IntVar(&extraDiskSize, "extra-disks-size", 5*1024, "default limit on disk size in MB (each VM)")
Expand Down
6 changes: 4 additions & 2 deletions pkg/provision/providers/vm/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ func (p *Provisioner) CreateDisks(state *State, nodeReq provision.NodeRequest) (
return nil, err
}

if err = syscall.Fallocate(int(diskF.Fd()), 0, 0, int64(disk.Size)); err != nil {
fmt.Fprintf(os.Stderr, "WARNING: failed to preallocate disk space for %q (size %d): %s", diskPath, disk.Size, err)
if !disk.SkipPreallocate {
if err = syscall.Fallocate(int(diskF.Fd()), 0, 0, int64(disk.Size)); err != nil {
fmt.Fprintf(os.Stderr, "WARNING: failed to preallocate disk space for %q (size %d): %s", diskPath, disk.Size, err)
}
}

diskPaths[i] = diskPath
Expand Down
2 changes: 2 additions & 0 deletions pkg/provision/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ func (reqs NodeRequests) PXENodes() (nodes []NodeRequest) {
type Disk struct {
// Size in bytes.
Size uint64
// Whether to skip preallocating the disk space.
SkipPreallocate bool
// Partitions represents the list of partitions.
Partitions []*v1alpha1.DiskPartition
}
Expand Down
1 change: 1 addition & 0 deletions website/content/v1.7/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ talosctl cluster create [flags]
--disk int default limit on disk size in MB (each VM) (default 6144)
--disk-encryption-key-types stringArray encryption key types to use for disk encryption (uuid, kms) (default [uuid])
--disk-image-path string disk image to use
--disk-preallocate whether disk space should be preallocated (default true)
--dns-domain string the dns domain to use for cluster (default "cluster.local")
--docker-disable-ipv6 skip enabling IPv6 in containers (Docker only)
--docker-host-ip string Host IP to forward exposed ports to (Docker provisioner only) (default "0.0.0.0")
Expand Down

0 comments on commit 4575dd8

Please sign in to comment.