Skip to content

Commit

Permalink
pkg: add support for systemd >= 240 and native btrfs parititions
Browse files Browse the repository at this point in the history
Systemd prior to version 240 was creating /var/lib/machines.raw as btrfs
volume for storing machined disks. However, this functionality is now
remove and now it stores it as regular files. More details here:
https://github.com/systemd/systemd/blob/401faa3533280b05fee972e0c64885caf4b31e4c/units/var-lib-machines.mount#L10

Additionally, it someone already have /var/lib/machines baked by btrfs,
machined won't create machines.raw, which will also cause setting up
cluster to fail.

This patch adds check, if machineImage exists and it not, it fallbacks
to just checking disk space available for /var/lib/machines.

Closes kinvolk#339 kinvolk#293

Signed-off-by: Mateusz Gozdek <mateusz@kinvolk.io>
  • Loading branch information
invidian committed May 23, 2019
1 parent 134eaed commit ce43282
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
32 changes: 27 additions & 5 deletions pkg/bootstrap/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,30 @@ func GetPoolSize(baseImageName string, nodes int) (int64, error) {
var extraSizeRatio float64 = 0.5
var err error

baseImageAbspath := path.Join(machinesDir, baseImageName+".raw")

if poolSize, err = getAllocatedFileSize(machinesImage); err != nil {
// Select correct path to check disk space. On older systemd versions
// machinesImage is used.
p := machinesDir
poolExists, err := CheckPoolExists()
if err != nil {
return 0, err
} else if poolExists {
p = machinesImage

if poolSize, err = getAllocatedFileSize(machinesImage); err != nil {
return 0, err
}

extraSize = int64(float64(poolSize) * extraSizeRatio)
}
extraSize = int64(float64(poolSize) * extraSizeRatio)

baseImageAbspath := path.Join(machinesDir, baseImageName+".raw")

if biSize, err = getAllocatedFileSize(baseImageAbspath); err != nil {
return 0, err
}
extraSize += int64(float64(biSize)*extraSizeRatio) * int64(nodes)

varDir, _ := path.Split(machinesImage)
varDir, _ := path.Split(p)
freeVolSpace, err := getVolFreeSpace(varDir)
if err != nil {
return 0, err
Expand All @@ -95,6 +106,17 @@ func GetPoolSize(baseImageName string, nodes int) (int64, error) {
return poolSize, nil
}

func CheckPoolExists() (bool, error) {
if _, err := os.Stat(machinesImage); err != nil {
if os.IsNotExist(err) {
return false, nil
} else {
return false, err
}
}
return true, nil
}

func setPoolLimit(poolSize int64) error {
var cmdPath string
var err error
Expand Down
20 changes: 17 additions & 3 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,29 @@ func (c *Cluster) Start(numberNodes int, cniPluginDir, cniPlugin, flatcarChannel
return err
}

poolSize, err := bootstrap.GetPoolSize(bootstrap.BaseImageName, numberNodes)
poolExists, err := bootstrap.CheckPoolExists()
if err != nil {
return err
}
log.Printf("new poolSize to be : %d\n", poolSize)
if err := bootstrap.EnlargeStoragePool(poolSize); err != nil {

// TODO This shouldn't be hardcoded, but I don't know where to put it yet
imageName := "flatcar"
if poolExists {
imageName = bootstrap.BaseImageName
}

poolSize, err := bootstrap.GetPoolSize(imageName, numberNodes)
if err != nil {
return err
}

if poolExists {
log.Printf("new poolSize to be : %d\n", poolSize)
if err := bootstrap.EnlargeStoragePool(poolSize); err != nil {
return err
}
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down

0 comments on commit ce43282

Please sign in to comment.