Skip to content

Commit

Permalink
Check default osd pool size before setting on create. (#14642)
Browse files Browse the repository at this point in the history
Fixes `lxd-ci` pipeline errors from `mon_allow_pool_size_one` not being
set
  • Loading branch information
tomponline authored Dec 12, 2024
2 parents c9e5049 + 1f8765b commit 1cf1cdb
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 53 deletions.
47 changes: 21 additions & 26 deletions lxd/storage/drivers/driver_ceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,12 @@ func (d *ceph) FillConfig() error {
}

if d.config["ceph.osd.pool_size"] == "" {
size, err := shared.TryRunCommand("ceph",
"--name", "client."+d.config["ceph.user.name"],
"--cluster", d.config["ceph.cluster_name"],
"config",
"get",
"mon",
"osd_pool_default_size",
"--format",
"json")
if err != nil {
return err
}

var sizeInt int
err = json.Unmarshal([]byte(size), &sizeInt)
defaultSize, err := d.getOSDPoolDefaultSize()
if err != nil {
return err
}

d.config["ceph.osd.pool_size"] = strconv.Itoa(sizeInt)
d.config["ceph.osd.pool_size"] = strconv.Itoa(defaultSize)
}

return nil
Expand Down Expand Up @@ -196,20 +182,29 @@ func (d *ceph) Create() error {

revert.Add(func() { _ = d.osdDeletePool() })

_, err = shared.TryRunCommand("ceph",
"--name", "client."+d.config["ceph.user.name"],
"--cluster", d.config["ceph.cluster_name"],
"osd",
"pool",
"set",
d.config["ceph.osd.pool_name"],
"size",
d.config["ceph.osd.pool_size"],
"--yes-i-really-mean-it")
// Fetch the default OSD pool size.
defaultSize, err := d.getOSDPoolDefaultSize()
if err != nil {
return err
}

// If the OSD pool size in the config for this pool is different than the default OSD pool size, then set the pool size for the pool.
if d.config["ceph.osd.pool_size"] != strconv.Itoa(defaultSize) {
_, err = shared.TryRunCommand("ceph",
"--name", "client."+d.config["ceph.user.name"],
"--cluster", d.config["ceph.cluster_name"],
"osd",
"pool",
"set",
d.config["ceph.osd.pool_name"],
"size",
d.config["ceph.osd.pool_size"],
"--yes-i-really-mean-it")
if err != nil {
return err
}
}

// Initialize the pool. This is not necessary but allows the pool to be monitored.
_, err = shared.TryRunCommand("rbd",
"--id", d.config["ceph.user.name"],
Expand Down
25 changes: 25 additions & 0 deletions lxd/storage/drivers/driver_ceph_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,31 @@ func (d *ceph) rbdListVolumeSnapshots(vol Volume) ([]string, error) {
return snapshots, nil
}

// getOSDPoolDefaultSize gets the global OSD default pool size that is used for
// all pools created without an explicit OSD pool size.
func (d *ceph) getOSDPoolDefaultSize() (int, error) {
defaultSize, err := shared.TryRunCommand("ceph",
"--name", "client."+d.config["ceph.user.name"],
"--cluster", d.config["ceph.cluster_name"],
"config",
"get",
"mon",
"osd_pool_default_size",
"--format",
"json")
if err != nil {
return -1, err
}

var defaultSizeInt int
err = json.Unmarshal([]byte(defaultSize), &defaultSizeInt)
if err != nil {
return -1, err
}

return defaultSizeInt, nil
}

// copyVolumeDiff creates a sparse copy of a volume by exporting and importing the diff
// between `sourceVolumeName` and its optional `sourceParentSnapshot` onto `targetVolumeName`.
// This does not introduce a dependency relation between the source RBD storage
Expand Down
46 changes: 19 additions & 27 deletions lxd/storage/drivers/driver_cephfs.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package drivers

import (
"encoding/json"
"fmt"
"os"
"os/exec"
Expand Down Expand Up @@ -105,26 +104,12 @@ func (d *cephfs) FillConfig() error {
}

if d.config["cephfs.osd_pool_size"] == "" {
size, err := shared.TryRunCommand("ceph",
"--name", "client."+d.config["cephfs.user.name"],
"--cluster", d.config["cephfs.cluster_name"],
"config",
"get",
"mon",
"osd_pool_default_size",
"--format",
"json")
defaultSize, err := d.getOSDPoolDefaultSize()
if err != nil {
return err
}

var sizeInt int
err = json.Unmarshal([]byte(size), &sizeInt)
if err != nil {
return err
}

d.config["cephfs.osd_pool_size"] = strconv.Itoa(sizeInt)
d.config["cephfs.osd_pool_size"] = strconv.Itoa(defaultSize)
}

return nil
Expand Down Expand Up @@ -227,19 +212,26 @@ func (d *cephfs) Create() error {
)
})

_, err = shared.TryRunCommand("ceph",
"--name", "client."+d.config["cephfs.user.name"],
"--cluster", d.config["cephfs.cluster_name"],
"osd",
"pool",
"set",
pool,
"size",
d.config["cephfs.osd_pool_size"],
"--yes-i-really-mean-it")
defaultSize, err := d.getOSDPoolDefaultSize()
if err != nil {
return err
}

if strconv.Itoa(defaultSize) != d.config["cephfs.osd_pool_size"] {
_, err = shared.TryRunCommand("ceph",
"--name", "client."+d.config["cephfs.user.name"],
"--cluster", d.config["cephfs.cluster_name"],
"osd",
"pool",
"set",
pool,
"size",
d.config["cephfs.osd_pool_size"],
"--yes-i-really-mean-it")
if err != nil {
return err
}
}
}
}

Expand Down
27 changes: 27 additions & 0 deletions lxd/storage/drivers/driver_cephfs_utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package drivers

import (
"encoding/json"

"github.com/canonical/lxd/shared"
)

Expand Down Expand Up @@ -42,6 +44,31 @@ func (d *cephfs) osdPoolExists(clusterName string, userName string, osdPoolName
return true, nil
}

// getOSDPoolDefaultSize gets the global OSD default pool size that is used for
// all pools created without an explicit OSD pool size.
func (d *cephfs) getOSDPoolDefaultSize() (int, error) {
size, err := shared.TryRunCommand("ceph",
"--name", "client."+d.config["cephfs.user.name"],
"--cluster", d.config["cephfs.cluster_name"],
"config",
"get",
"mon",
"osd_pool_default_size",
"--format",
"json")
if err != nil {
return -1, err
}

var sizeInt int
err = json.Unmarshal([]byte(size), &sizeInt)
if err != nil {
return -1, err
}

return sizeInt, nil
}

// getConfig parses the Ceph configuration file and returns the list of monitors and secret key.
func (d *cephfs) getConfig(clusterName string, userName string) ([]string, string, error) {
// Get the monitor list.
Expand Down

0 comments on commit 1cf1cdb

Please sign in to comment.