Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize ceph.pp to allow multiple cephfs mounting #313

Merged
merged 12 commits into from
May 14, 2024
134 changes: 67 additions & 67 deletions site/profile/manifests/ceph.pp
Original file line number Diff line number Diff line change
@@ -1,62 +1,37 @@
type BindMount = Struct[{
'src' => Stdlib::Unixpath,
'dst' => Stdlib::Unixpath,
'type' => Optional[Enum['file', 'directory']],
}]

type CephFS = Struct[
{
'share_name' => String,
'access_key' => String,
'export_path' => Stdlib::Unixpath,
'bind_mounts' => Optional[Array[BindMount]],
'binds_fcontext_equivalence' => Optional[Stdlib::Unixpath],
}
]

class profile::ceph::client (
String $share_name,
String $access_key,
String $export_path,
Array[String] $mon_host,
Array[String] $mount_binds = [],
String $mount_name = 'cephfs01',
String $binds_fcontext_equivalence = '/home',
Hash[String, CephFS] $shares,
) {
class { 'profile::ceph::client::config':
share_name => $share_name,
access_key => $access_key,
export_path => $export_path,
mon_host => $mon_host,
}

file { "/mnt/${mount_name}":
ensure => directory,
}
require profile::ceph::client::install

$mon_host_string = join($mon_host, ',')
mount { "/mnt/${mount_name}":
ensure => 'mounted',
fstype => 'ceph',
device => "${mon_host_string}:${export_path}",
options => "name=${share_name},secretfile=/etc/ceph/client.keyonly.${share_name}",
require => Class['profile::ceph::client::config'],
}

$mount_binds.each |$mount| {
file { "/mnt/${mount_name}/${mount}":
ensure => directory,
require => Class['profile::ceph::client::config'],
}
file { "/${mount}":
ensure => directory,
require => Class['profile::ceph::client::config'],
}
mount { "/${mount}":
ensure => 'mounted',
fstype => 'none',
options => 'rw,bind',
device => "/mnt/${mount_name}/${mount}",
require => [
File["/mnt/${mount_name}/${mount}"],
File["/${mount}"],
],
}
$ceph_conf = @("EOT")
[client]
client quota = true
mon host = ${mon_host_string}
| EOT

if ($binds_fcontext_equivalence != '' and "/${mount}" != $binds_fcontext_equivalence) {
selinux::fcontext::equivalence { "/${mount}":
ensure => 'present',
target => $binds_fcontext_equivalence,
require => Mount["/${mount}"],
notify => Selinux::Exec_restorecon["/${mount}"],
}
selinux::exec_restorecon { "/${mount}": }
}
file { '/etc/ceph/ceph.conf':
content => $ceph_conf,
}

ensure_resources(profile::ceph::client::share, $shares, { 'mon_host' => $mon_host, 'bind_mounts' => [] })
}

class profile::ceph::client::install {
Expand Down Expand Up @@ -90,41 +65,66 @@
}
}

class profile::ceph::client::config (
define profile::ceph::client::share (
Array[String] $mon_host,
String $share_name,
String $access_key,
String $export_path,
Array[String] $mon_host,
Stdlib::Unixpath $export_path,
Array[BindMount] $bind_mounts,
Optional[Stdlib::Unixpath] $binds_fcontext_equivalence = undef,
) {
require profile::ceph::client::install

$client_fullkey = @("EOT")
[client.${share_name}]
[client.${name}]
key = ${access_key}
| EOT

file { "/etc/ceph/client.fullkey.${share_name}":
file { "/etc/ceph/client.fullkey.${name}":
content => $client_fullkey,
mode => '0600',
owner => 'root',
group => 'root',
}

file { "/etc/ceph/client.keyonly.${share_name}":
file { "/etc/ceph/client.keyonly.${name}":
content => Sensitive($access_key),
mode => '0600',
owner => 'root',
group => 'root',
}
file { "/mnt/${name}":
ensure => directory,
}

$mon_host_string = join($mon_host, ',')
$ceph_conf = @("EOT")
[client]
client quota = true
mon host = ${mon_host_string}
| EOT
mount { "/mnt/${name}":
ensure => 'mounted',
fstype => 'ceph',
device => "${mon_host_string}:${export_path}",
options => "name=${share_name},secretfile=/etc/ceph/client.keyonly.${name}",
require => File['/etc/ceph/ceph.conf'],
}

file { '/etc/ceph/ceph.conf':
content => $ceph_conf,
$bind_mounts.each |$mount| {
file { $mount['dst']:
ensure => pick($mount['type'], 'directory'),
}
mount { $mount['dst']:
ensure => 'mounted',
fstype => 'none',
options => 'rw,bind',
device => "/mnt/${name}${mount['src']}",
require => [
File[$mount['dst']],
Mount["/mnt/${name}"]
],
}

if ($binds_fcontext_equivalence and $binds_fcontext_equivalence != $mount['dst']) {
selinux::fcontext::equivalence { $mount['dst']:
ensure => 'present',
target => $binds_fcontext_equivalence,
require => Mount[$mount['dst']],
}
}
}
}
Loading