Skip to content

cephadm: add support for sidecar containers - #54722

Merged
adk3798 merged 35 commits into
ceph:mainfrom
phlogistonjohn:jjm-cephadm-sidecars
Jan 5, 2024
Merged

adk3798 merged 35 commits into
ceph:mainfrom
phlogistonjohn:jjm-cephadm-sidecars

Conversation

@phlogistonjohn

@phlogistonjohn phlogistonjohn commented Nov 29, 2023 •

Copy link
Copy Markdown
Contributor

Depends on #54536

Add the initial support for creating sidecar containers. Sidecar containers are tightly coupled with a primary service container. This PR only adds the ability to create and delete sidecars via systemd service unit files. As part of the work updating systemd integration to use additional services the init containers are moved into a dedicated systemd service. The cephadm ls output and the mgr are ignorant of sidecars and init containers.

The iscsi service had a special care where the tcmu runner container was started as part of the unit.run file in the background. This has been converted to a sidecar container. The lack of insight into the sidecars should be no worse than before as the tcmu runner container was largely "invsible" to systemd & the mgr before this change.

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands
  • jenkins retest this please
  • jenkins test classic perf
  • jenkins test crimson perf
  • jenkins test signed
  • jenkins test make check
  • jenkins test make check arm64
  • jenkins test submodules
  • jenkins test dashboard
  • jenkins test dashboard cephadm
  • jenkins test api
  • jenkins test docs
  • jenkins render docs
  • jenkins test ceph-volume all
  • jenkins test ceph-volume tox
  • jenkins test windows
  • jenkins test rook e2e

@github-actions

github-actions Bot commented Dec 4, 2023

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@github-actions

github-actions Bot commented Dec 9, 2023

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@phlogistonjohn

Copy link
Copy Markdown
Contributor Author

Updated to disable Restart=on-failure line in init container service template.

There are a bunch of places in the code that wants the full systemd
service name but the code generally is just doing string concatenation.
Add a method to avoid stringing it all the time. This will help as there
will be more systemd work in the future.

Signed-off-by: John Mulligan <[email protected]>
Use the new service_name method of the DaemonIdentity type in some basic
cases where string concatenation was being used.
I also converted the name of the agent's helper method to match and made
it private to avoid future confusion.

Signed-off-by: John Mulligan <[email protected]>
Add a method for duplicating the container properties into a new object.

Signed-off-by: John Mulligan <[email protected]>
Add a new type representing sidecar containers.

Signed-off-by: John Mulligan <[email protected]>
Add a `must` method that ensures a DaemonIdentity is a DaemonSubIdentity
in a single call.

Signed-off-by: John Mulligan <[email protected]>
Do not have data dir depend on the daemon_name property. This property
is overriden by the subclass(es) but we want DaemonIdentities and
DaemonSubIdentities to share the same data_dir.

Signed-off-by: John Mulligan <[email protected]>
Add templates that will be used for advanced systemd services: sidecars,
init containers, and drop-in files to glue them all together.

Signed-off-by: John Mulligan <[email protected]>
Convert the call that writes out files for a daemon to use the new
dedicated systemd-unit support for init containers.

Signed-off-by: John Mulligan <[email protected]>
Add support for producing sidecar containers to the container daemon
form type and pass the sidecars through to the unit/script management
function.

Signed-off-by: John Mulligan <[email protected]>
Convert the iscsi container daemon form class to produce a sidecar
container for the tcmu runner and reduce the amount of special casing
for iscsi.

Signed-off-by: John Mulligan <[email protected]>
Rename get_unit_name_by_daemon_name to lookup__unit_name_by_daemon_name
to emphasize that the function does a full lookup (via the daemon list)
to determine the systemd service name for the given values and that
there's a potential performance implication to doing that.

Signed-off-by: John Mulligan <[email protected]>
Add the unlink_file function to file_utils. This fills in a gap between
python 3.6 and features provided in pathlib.Path in later versions of
python. Adds an option to ignore all errors for good measure.

Signed-off-by: John Mulligan <[email protected]>
This will become handy later when we need DaemonSubIdentity objects and
are not on the deploy path.

Signed-off-by: John Mulligan <[email protected]>
Add a sidecars_from_dropin function that takes a minimal PathInfo object
and returns a PathInfo populated with sidecars information based on
reading the content of the dropin file. This will be useful when we need
information on configured sidecars but are not on the deploy path.

Signed-off-by: John Mulligan <[email protected]>
Add a function that encapsulates the common 3-step process found in
cephadm of stopping, resetting errors, and disabling a service.
This will be used to handle new services to stop as well as cleaning
up some places where the three steps are performed inline.

Signed-off-by: John Mulligan <[email protected]>
Make a few small chanes to command_rm_daemon to clean it up in
preparation for future changes. Move the construction of a
DaemonIdentity earlier and use the service name derived directly from it
if possible. I didn't remove the old approach of looking up a service
name in the listing because I don't know if doing so would break
old/adopted services and there's no unit test coverage for that.

Signed-off-by: John Mulligan <[email protected]>
This should be a little cleaner, perhaps a tiny performance improvement,
and most importantly work better with the virtual-fs provided for the
unit tests and make this function more testable in the future.

Signed-off-by: John Mulligan <[email protected]>
Add support to the command_rm_daemon function to remove systemd services
and corresponding unit files for any sidecars or init-containers
associated with a primary daemon.

Signed-off-by: John Mulligan <[email protected]>
The terminate_service function was added to encapsulate the act of
terminating a systemd service. The rm-deamon handler was updated to use
this function previously; this commit updates rm-cluster function(s)
to do the same. This needed a bunch of test updates do to how the tests
were mocking commands.

Signed-off-by: John Mulligan <[email protected]>
A previous patch updated the rm-daemon functionality to remove sidecar
and init-container systemd services. This patch does the same for the
rm-cluster codepath.

Signed-off-by: John Mulligan <[email protected]>
Remove a line from _rm_cluster that has no effect. The line uses
call_throws to execute an `rm -rf` command. The argument contains
asterisk chars that indicate that the file(s)/dir(s) to be created are
expected to match the given pattern. However, globs do not work in this
context in contemporary versions of cephadm.

To double check I added the following temporary unit test:
```
def test_does_it_glob(tmp_path):
    from cephadmlib.call_wrappers import call_throws

    d1 = (tmp_path / 'dir1')
    d1.mkdir()
    fns = ['f1.txt', 'f2.txt', 'f3.txt', 'f4']
    for fn in fns:
        with open(d1/fn, "w") as fh:
            fh.write("xxx")
    assert d1.exists()
    for fn in fns:
        assert (d1 / fn).exists()

    ctx = FakeContext()
    call_throws(ctx, ['rm', '-rf', f'{d1}/*.txt'])
    print('files:', os.listdir(d1))
    assert d1.exists()
    for fn in fns:
        if fn.endswith('.txt'):
            assert not (d1 / fn).exists()
        else:
            assert (d1 / fn).exists()
```

If globs worked in this context this test would have passed. It does
not. I confirmed that the current implementation of call/call_wrapper
does not execute the command in a shell context.

I wondered if it was possible that an earlier version of cephadm did
execute this command in a shell context and some changes along the way
changed the behavior. I tracked the origin of the line back to
16ebc62 the first change to implement
rm-cluster. In this commit the code uses subprocess.check_output
directly. I am familiar with check_output and unless `shell=True` is
passed this function doesn't execute the args in a shell context.  The
`shell=True` argument is not passed to check_output. This means that the
very first implementation of this line suffered from the same issue
- it would have no effect on any files except one named with actual
  asterisk (`*`) characters.

While I'm sure there was a good intention behind this line, the fact
that it persisted in the code so long in a non-functional state and no
one noticed in both production and qa testing makes me feel that it can
be safely removed with no negative effect. Removing the line simplifies
the code and avoids needing to spend effort unit-testing or manually
checking a fix.

Signed-off-by: John Mulligan <[email protected]>
Convert a bunch of invocations of rm via a subprocess to function calls.
This should make it easier (or possible?) to test the function
in the unit test framework as well as possibly saving a few resources.

Signed-off-by: John Mulligan <[email protected]>
Move the generation of the init container run script to a small function
fixing a missing `set -e` along the way. This isolates the logic of
generating this run script.

Signed-off-by: John Mulligan <[email protected]>
Convert the init containers run script to be based on a template, like
the sidecar run scripts are. The new script is loosely based on the
sidecars run script but only does actions in batches - logically
iterating over each init container configured.

Signed-off-by: John Mulligan <[email protected]>
Now that there is a more robust init_containers.run script, we can use
the new stop and poststop subcommands from the systemd unit.

Signed-off-by: John Mulligan <[email protected]>
Disable the Restart= line in the init containers systemd template.
It is commented out as there are probably more appropriate workarounds
to use in the future but this should fix testing on centos8 based
systems.

Signed-off-by: John Mulligan <[email protected]>
Comment thread src/cephadm/cephadmlib/runscripts.py Resolved
Comment thread src/cephadm/cephadm.py Resolved
@adk3798

adk3798 commented Jan 5, 2024

Copy link
Copy Markdown
Contributor

https://pulpito.ceph.com/adking-2024-01-02_14:31:29-orch:cephadm-wip-adk-testing-2024-01-02-0614-distro-default-smithi/

reruns of failed/dead jobs: https://pulpito.ceph.com/adking-2024-01-03_10:25:36-orch:cephadm-wip-adk-testing-2024-01-02-0614-distro-default-smithi/

After reruns: 3 failed/dead jobs:

  • 1 instance of https://tracker.ceph.com/issues/62958
  • 1 failure in test_iscsi_container timing out on rhel 8.6. Stil haven't figured this out totaly but might have something to do with the fact it seems to be trying to set the OS as bot hrhel 8.6 and centos 8.stream (title for that job is orch:cephadm/workunits/{0-distro/rhel_8.6_container_tools_rhel8 agent/on mon_election/connectivity task/test_iscsi_container/{centos_8.stream_container_tools test_iscsi_container}}) still needs more investigation, but the failure predates this run, so unrelated to PRs in the run.
  • 1 failure in test_orch_cli task. After investigating, it turned out the agent was getting marked down as it failed to send messages to the mgr because it was configured with the incorrect port (was trying to send to port 7150, but mgr was listening on 7152). Will also need a further look, but I don't think it's caused by any PRs in this run either

Overall, nothing to block merging.

@adk3798
adk3798 merged commit cd3c697 into ceph:main Jan 5, 2024
@phlogistonjohn
phlogistonjohn deleted the jjm-cephadm-sidecars branch January 5, 2024 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants