mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-21 14:41:12 +02:00
User-disks are supported by QEMU and Firecracker providers. Can be defined by using the following parameters: ``` --user-disk /mount/path:1GB ``` Can get more than 1 user disk. Same set of user disks will be created for all master and worker nodes. Additionally enable user-disks in qemu e2e test. Signed-off-by: Artem Chernyshev <artem.0xD2@gmail.com>
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package vm
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/talos-systems/talos/pkg/provision"
|
|
)
|
|
|
|
// UserDiskName returns disk device path.
|
|
func (p *Provisioner) UserDiskName(index int) string {
|
|
res := "/dev/vd"
|
|
|
|
var convert func(i int) string
|
|
|
|
convert = func(i int) string {
|
|
remainder := i % 26
|
|
divider := i / 26
|
|
|
|
prefix := ""
|
|
|
|
if divider != 0 {
|
|
prefix = convert(divider - 1)
|
|
}
|
|
|
|
return fmt.Sprintf("%s%s", prefix, string(rune('a'+remainder)))
|
|
}
|
|
|
|
return res + convert(index)
|
|
}
|
|
|
|
// CreateDisks creates empty disk files for each disk.
|
|
func (p *Provisioner) CreateDisks(state *State, nodeReq provision.NodeRequest) (diskPaths []string, err error) {
|
|
diskPaths = make([]string, len(nodeReq.Disks))
|
|
|
|
for i, disk := range nodeReq.Disks {
|
|
diskPath := state.GetRelativePath(fmt.Sprintf("%s-%d.disk", nodeReq.Name, i))
|
|
|
|
var diskF *os.File
|
|
|
|
diskF, err = os.Create(diskPath)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
defer diskF.Close() //nolint: errcheck
|
|
|
|
err = diskF.Truncate(int64(disk.Size))
|
|
diskPaths[i] = diskPath
|
|
}
|
|
|
|
if len(diskPaths) == 0 {
|
|
err = fmt.Errorf("node request must have at least one disk defined to be used as primary disk")
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|