From b2c28197a166d406ed7dd843571a86710f148cd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix-Antoine=20Fortin?= Date: Tue, 14 May 2024 14:36:50 -0400 Subject: [PATCH] Generalize ceph.pp to allow multiple cephfs mounting (#313) Co-authored-by: Maxime Boissonneault --- site/profile/manifests/ceph.pp | 134 ++++++++++++++++----------------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/site/profile/manifests/ceph.pp b/site/profile/manifests/ceph.pp index f4e546c61..4ba7536f6 100644 --- a/site/profile/manifests/ceph.pp +++ b/site/profile/manifests/ceph.pp @@ -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 { @@ -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']], + } + } } }