From 60a9a4f27aa1cddd717431abae7a26c46f5f8bd5 Mon Sep 17 00:00:00 2001 From: Ponnuvel Palaniyappan Date: Tue, 30 Jun 2020 17:27:09 +0100 Subject: [PATCH] Remove chrony if inside a container When running ceph-mon in containers, best practice is to have chrony/ntp configured and installed on the bare metal and then have the container trust the system clock, as the container should not manage the system clock. The chrony package get installed automatically as part of the dependencies of other packages, which gets removed in this change. Also contains related changes for charms.ceph. Change-Id: If8beb28ea5b5e6317180e52c3e32463e472276f4 Closes-Bug: #1852441 Depends-On: Ie3c9c5899c1d46edd21c32868938d3290db321e7 --- hooks/ceph_hooks.py | 4 ++++ lib/charms_ceph/utils.py | 28 ++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/hooks/ceph_hooks.py b/hooks/ceph_hooks.py index 3bda8f21..bcf68696 100755 --- a/hooks/ceph_hooks.py +++ b/hooks/ceph_hooks.py @@ -58,6 +58,7 @@ from charmhelpers.core.host import ( from charmhelpers.fetch import ( apt_install, apt_update, + apt_purge, filter_installed_packages, add_source, get_upstream_version, @@ -160,6 +161,9 @@ def install(): add_source(config('source'), config('key')) apt_update(fatal=True) apt_install(packages=ceph.determine_packages(), fatal=True) + rm_packages = ceph.determine_packages_to_remove() + if rm_packages: + apt_purge(packages=rm_packages, fatal=True) try: # we defer and explicitly run `ceph-create-keys` from # add_keyring_to_ceph() as part of bootstrap process diff --git a/lib/charms_ceph/utils.py b/lib/charms_ceph/utils.py index 72e6b921..53cff539 100644 --- a/lib/charms_ceph/utils.py +++ b/lib/charms_ceph/utils.py @@ -41,6 +41,7 @@ from charmhelpers.core.host import ( service_stop, CompareHostReleases, write_file, + is_container, ) from charmhelpers.core.hookenv import ( cached, @@ -54,8 +55,12 @@ from charmhelpers.core.hookenv import ( storage_list, ) from charmhelpers.fetch import ( + add_source, apt_cache, - add_source, apt_install, apt_update + apt_install, + apt_purge, + apt_update, + filter_missing_packages ) from charmhelpers.contrib.storage.linux.ceph import ( get_mon_map, @@ -85,6 +90,9 @@ PACKAGES = ['ceph', 'gdisk', 'radosgw', 'xfsprogs', 'lvm2', 'parted', 'smartmontools'] +REMOVE_PACKAGES = [] +CHRONY_PACKAGE = 'chrony' + CEPH_KEY_MANAGER = 'ceph' VAULT_KEY_MANAGER = 'vault' KEY_MANAGERS = [ @@ -2209,8 +2217,11 @@ def upgrade_monitor(new_version, kick_function=None): else: service_stop('ceph-mon-all') apt_install(packages=determine_packages(), fatal=True) - kick_function() + rm_packages = determine_packages_to_remove() + if rm_packages: + apt_purge(packages=rm_packages, fatal=True) + kick_function() owner = ceph_user() # Ensure the files and directories under /var/lib/ceph is chowned @@ -3252,6 +3263,19 @@ def determine_packages(): return packages +def determine_packages_to_remove(): + """Determines packages for removal + + :returns: list of packages to be removed + """ + rm_packages = REMOVE_PACKAGES.copy() + if is_container(): + install_list = filter_missing_packages(CHRONY_PACKAGE) + if not install_list: + rm_packages.append(CHRONY_PACKAGE) + return rm_packages + + def bootstrap_manager(): hostname = socket.gethostname() path = '/var/lib/ceph/mgr/ceph-{}'.format(hostname)