chore: allow not preallocated disks for QEMU cluster

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>
This commit is contained in:
Dmitry Sharshakov 2024-02-23 12:43:08 +03:00 committed by Andrey Smirnov
parent 0bddfea818
commit 4575dd8e74
No known key found for this signature in database
GPG Key ID: FE042E3D4085A811
4 changed files with 17 additions and 6 deletions

View File

@ -76,6 +76,7 @@ const (
networkCIDRFlag = "cidr" networkCIDRFlag = "cidr"
nameserversFlag = "nameservers" nameserversFlag = "nameservers"
clusterDiskSizeFlag = "disk" clusterDiskSizeFlag = "disk"
clusterDiskPreallocateFlag = "disk-preallocate"
clusterDisksFlag = "user-disk" clusterDisksFlag = "user-disk"
customCNIUrlFlag = "custom-cni-url" customCNIUrlFlag = "custom-cni-url"
talosVersionFlag = "talos-version" talosVersionFlag = "talos-version"
@ -124,6 +125,7 @@ var (
controlPlaneMemory int controlPlaneMemory int
workersMemory int workersMemory int
clusterDiskSize int clusterDiskSize int
clusterDiskPreallocate bool
clusterDisks []string clusterDisks []string
extraDisks int extraDisks int
extraDiskSize int extraDiskSize int
@ -797,6 +799,7 @@ func create(ctx context.Context, flags *pflag.FlagSet) error {
for i := 0; i < extraDisks; i++ { for i := 0; i < extraDisks; i++ {
disks = append(disks, &provision.Disk{ disks = append(disks, &provision.Disk{
Size: uint64(extraDiskSize) * 1024 * 1024, Size: uint64(extraDiskSize) * 1024 * 1024,
SkipPreallocate: !clusterDiskPreallocate,
}) })
} }
@ -998,6 +1001,7 @@ func getDisks() ([]*provision.Disk, error) {
disks := []*provision.Disk{ disks := []*provision.Disk{
{ {
Size: uint64(clusterDiskSize) * 1024 * 1024, Size: uint64(clusterDiskSize) * 1024 * 1024,
SkipPreallocate: !clusterDiskPreallocate,
}, },
} }
@ -1044,6 +1048,7 @@ func getDisks() ([]*provision.Disk, error) {
// add 1 MB to make extra room for GPT and alignment // add 1 MB to make extra room for GPT and alignment
Size: diskSize + 2*1024*1024, Size: diskSize + 2*1024*1024,
Partitions: diskPartitions, Partitions: diskPartitions,
SkipPreallocate: !clusterDiskPreallocate,
}) })
} }
@ -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(&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(&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().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().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(&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)") createCmd.Flags().IntVar(&extraDiskSize, "extra-disks-size", 5*1024, "default limit on disk size in MB (each VM)")

View File

@ -42,9 +42,11 @@ func (p *Provisioner) CreateDisks(state *State, nodeReq provision.NodeRequest) (
return nil, err return nil, err
} }
if !disk.SkipPreallocate {
if err = syscall.Fallocate(int(diskF.Fd()), 0, 0, int64(disk.Size)); err != nil { 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) fmt.Fprintf(os.Stderr, "WARNING: failed to preallocate disk space for %q (size %d): %s", diskPath, disk.Size, err)
} }
}
diskPaths[i] = diskPath diskPaths[i] = diskPath
} }

View File

@ -150,6 +150,8 @@ func (reqs NodeRequests) PXENodes() (nodes []NodeRequest) {
type Disk struct { type Disk struct {
// Size in bytes. // Size in bytes.
Size uint64 Size uint64
// Whether to skip preallocating the disk space.
SkipPreallocate bool
// Partitions represents the list of partitions. // Partitions represents the list of partitions.
Partitions []*v1alpha1.DiskPartition Partitions []*v1alpha1.DiskPartition
} }

View File

@ -112,6 +112,7 @@ talosctl cluster create [flags]
--disk int default limit on disk size in MB (each VM) (default 6144) --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-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-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") --dns-domain string the dns domain to use for cluster (default "cluster.local")
--docker-disable-ipv6 skip enabling IPv6 in containers (Docker only) --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") --docker-host-ip string Host IP to forward exposed ports to (Docker provisioner only) (default "0.0.0.0")