From cabdac4913ed98f62b4a99988759782d187ed191 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Fri, 2 Oct 2020 13:09:49 +0200 Subject: [PATCH] cephfs: make getMetadataPool() a method of volumeOptions Signed-off-by: Niels de Vos --- internal/cephfs/cephfs_util.go | 8 ++++---- internal/cephfs/volumeoptions.go | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/cephfs/cephfs_util.go b/internal/cephfs/cephfs_util.go index 60754caf1..849c00fa2 100644 --- a/internal/cephfs/cephfs_util.go +++ b/internal/cephfs/cephfs_util.go @@ -55,13 +55,13 @@ type CephFilesystem struct { 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 // [{"name":"myfs","metadata_pool":"myfs-metadata","metadata_pool_id":4,...},...] var filesystems []CephFilesystem err := execCommandJSON(ctx, &filesystems, "ceph", - "-m", monitors, + "-m", vo.Monitors, "--id", cr.ID, "--keyfile="+cr.KeyFile, "-c", util.CephConfigPath, @@ -72,12 +72,12 @@ func getMetadataPool(ctx context.Context, monitors string, cr *util.Credentials, } for _, fs := range filesystems { - if fs.Name == fsName { + if fs.Name == vo.FsName { 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) { diff --git a/internal/cephfs/volumeoptions.go b/internal/cephfs/volumeoptions.go index 40f4a4d3e..ff51bfd99 100644 --- a/internal/cephfs/volumeoptions.go +++ b/internal/cephfs/volumeoptions.go @@ -220,7 +220,7 @@ func newVolumeOptions(ctx context.Context, requestName string, req *csi.CreateVo return nil, err } - opts.MetadataPool, err = getMetadataPool(ctx, opts.Monitors, cr, opts.FsName) + opts.MetadataPool, err = opts.getMetadataPool(ctx, cr) if err != nil { return nil, err } @@ -295,7 +295,7 @@ func newVolumeOptionsFromVolID(ctx context.Context, volID string, volOpt, secret return nil, nil, err } - volOptions.MetadataPool, err = getMetadataPool(ctx, volOptions.Monitors, cr, volOptions.FsName) + volOptions.MetadataPool, err = volOptions.getMetadataPool(ctx, cr) if err != nil { return nil, nil, err } @@ -503,7 +503,7 @@ func newSnapshotOptionsFromID(ctx context.Context, snapID string, cr *util.Crede 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 { return &volOptions, nil, &sid, err }