cephfs: make getMetadataPool() a method of volumeOptions

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-10-02 13:09:49 +02:00 committed by mergify[bot]
parent 551a5018d0
commit cabdac4913
2 changed files with 7 additions and 7 deletions

View File

@ -55,13 +55,13 @@ type CephFilesystem struct {
DataPoolIDs []int `json:"data_pool_ids"` DataPoolIDs []int `json:"data_pool_ids"`
} }
func getMetadataPool(ctx context.Context, monitors string, cr *util.Credentials, fsName string) (string, error) { func (vo *volumeOptions) getMetadataPool(ctx context.Context, cr *util.Credentials) (string, error) {
// ./tbox ceph fs ls --format=json // ./tbox ceph fs ls --format=json
// [{"name":"myfs","metadata_pool":"myfs-metadata","metadata_pool_id":4,...},...] // [{"name":"myfs","metadata_pool":"myfs-metadata","metadata_pool_id":4,...},...]
var filesystems []CephFilesystem var filesystems []CephFilesystem
err := execCommandJSON(ctx, &filesystems, err := execCommandJSON(ctx, &filesystems,
"ceph", "ceph",
"-m", monitors, "-m", vo.Monitors,
"--id", cr.ID, "--id", cr.ID,
"--keyfile="+cr.KeyFile, "--keyfile="+cr.KeyFile,
"-c", util.CephConfigPath, "-c", util.CephConfigPath,
@ -72,12 +72,12 @@ func getMetadataPool(ctx context.Context, monitors string, cr *util.Credentials,
} }
for _, fs := range filesystems { for _, fs := range filesystems {
if fs.Name == fsName { if fs.Name == vo.FsName {
return fs.MetadataPool, nil return fs.MetadataPool, nil
} }
} }
return "", fmt.Errorf("%w: fsName (%s) not found in Ceph cluster", util.ErrPoolNotFound, fsName) return "", fmt.Errorf("%w: fsName (%s) not found in Ceph cluster", util.ErrPoolNotFound, vo.FsName)
} }
func (vo *volumeOptions) getFsName(ctx context.Context) (string, error) { func (vo *volumeOptions) getFsName(ctx context.Context) (string, error) {

View File

@ -220,7 +220,7 @@ func newVolumeOptions(ctx context.Context, requestName string, req *csi.CreateVo
return nil, err return nil, err
} }
opts.MetadataPool, err = getMetadataPool(ctx, opts.Monitors, cr, opts.FsName) opts.MetadataPool, err = opts.getMetadataPool(ctx, cr)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -295,7 +295,7 @@ func newVolumeOptionsFromVolID(ctx context.Context, volID string, volOpt, secret
return nil, nil, err return nil, nil, err
} }
volOptions.MetadataPool, err = getMetadataPool(ctx, volOptions.Monitors, cr, volOptions.FsName) volOptions.MetadataPool, err = volOptions.getMetadataPool(ctx, cr)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -503,7 +503,7 @@ func newSnapshotOptionsFromID(ctx context.Context, snapID string, cr *util.Crede
return &volOptions, nil, &sid, err return &volOptions, nil, &sid, err
} }
volOptions.MetadataPool, err = getMetadataPool(ctx, volOptions.Monitors, cr, volOptions.FsName) volOptions.MetadataPool, err = volOptions.getMetadataPool(ctx, cr)
if err != nil { if err != nil {
return &volOptions, nil, &sid, err return &volOptions, nil, &sid, err
} }