Skip to content

Commit

Permalink
cephadm: add --container_cli_args parameter
Browse files Browse the repository at this point in the history
So we can add any extra parameters to any calls to `podman run` executed
by cephadm.

Fixes: https://tracker.ceph.com/issues/52065

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
  • Loading branch information
guits committed Aug 5, 2021
1 parent f1aca8d commit c09c797
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion doc/man/8/cephadm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Synopsis
| **cephadm**** [-h] [--image IMAGE] [--docker] [--data-dir DATA_DIR]
| [--log-dir LOG_DIR] [--logrotate-dir LOGROTATE_DIR]
| [--unit-dir UNIT_DIR] [--verbose] [--timeout TIMEOUT]
| [--retry RETRY] [--no-container-init]
| [--retry RETRY] [--no-container-init] [--container_cli_args]
| {version,pull,inspect-image,ls,list-networks,adopt,rm-daemon,rm-cluster,run,shell,enter,ceph-volume,unit,logs,bootstrap,deploy,check-host,prepare-host,add-repo,rm-repo,install}
| ...
Expand Down Expand Up @@ -159,6 +159,10 @@ Options

do not run podman/docker with `--init` (default: False)

.. option:: --container-cli-args

pass any additional flags to podman/docker cli (default: None)


Commands
========
Expand Down
15 changes: 15 additions & 0 deletions src/cephadm/cephadm
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class BaseConfig:

def __init__(self) -> None:
self.image: str = ''
self.container_cli_args: Optional[str] = None
self.docker: bool = False
self.data_dir: str = DATA_DIR
self.log_dir: str = LOG_DIR
Expand Down Expand Up @@ -2567,6 +2568,9 @@ def get_container(ctx: CephadmContext,
if ctx.container_engine.version >= CGROUPS_SPLIT_PODMAN_VERSION:
container_args.append('--cgroups=split')

if ctx.container_cli_args is not None:
container_args.extend(shlex.split(ctlx.container_cli_args))

return CephContainer.for_daemon(
ctx,
fsid=fsid,
Expand Down Expand Up @@ -3212,6 +3216,7 @@ class CephContainer:
host_network: bool = True,
memory_request: Optional[str] = None,
memory_limit: Optional[str] = None,
container_cli_args: Optional[List[str]] = None,
) -> None:
self.ctx = ctx
self.image = image
Expand All @@ -3228,6 +3233,7 @@ class CephContainer:
self.host_network = host_network
self.memory_request = memory_request
self.memory_limit = memory_limit
self.container_cli_args = container_cli_args if container_cli_args else ctx.container_cli_args

@classmethod
def for_daemon(cls,
Expand Down Expand Up @@ -3308,6 +3314,9 @@ class CephContainer:
'--stop-signal=SIGTERM',
]

if self.container_cli_args is not None:
cmd_args.extend(shlex.split(self.container_cli_args))

if isinstance(self.ctx.container_engine, Podman):
if os.path.exists('/etc/ceph/podman-auth.json'):
cmd_args.append('--authfile=/etc/ceph/podman-auth.json')
Expand Down Expand Up @@ -4319,6 +4328,9 @@ def command_bootstrap(ctx):

enable_cephadm_mgr_module(cli, wait_for_mgr_restart)

if ctx.container_cli_args is not None:
cli(['config', 'set', 'mgr', 'mgr/cephadm/container_cli_args', '--value={}'.format(ctx.container_cli_args), '--force'])

# ssh
if not ctx.skip_ssh:
prepare_ssh(ctx, cli, wait_for_mgr_restart)
Expand Down Expand Up @@ -7733,6 +7745,9 @@ def _get_parser():
'--image',
help='container image. Can also be set via the "CEPHADM_IMAGE" '
'env var')
parser.add_argument(
'--container-cli-args',
help='Run the container cli with extra args')
parser.add_argument(
'--docker',
action='store_true',
Expand Down
7 changes: 7 additions & 0 deletions src/pybind/mgr/cephadm/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule,
default='root',
desc='mode for remote execution of cephadm',
),
Option(
'container_cli_args',
type='str',
default=None,
desc='Run the container cli with extra args',
),
Option(
'container_image_base',
default=DEFAULT_IMAGE,
Expand Down Expand Up @@ -370,6 +376,7 @@ def __init__(self, *args: Any, **kwargs: Any):
self.host_check_interval = 0
self.max_count_per_host = 0
self.mode = ''
self.container_cli_args = None
self.container_image_base = ''
self.container_image_prometheus = ''
self.container_image_grafana = ''
Expand Down
3 changes: 3 additions & 0 deletions src/pybind/mgr/cephadm/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,9 @@ def _run_cephadm(self,
if not self.mgr.container_init:
final_args += ['--no-container-init']

if self.mgr.container_cli_args is not None:
final_args.append('--container-cli-args="{}"'.format(self.mgr.container_cli_args))

# subcommand
final_args.append(command)

Expand Down

0 comments on commit c09c797

Please sign in to comment.