From 0bc831a07be6ae837cb9029943c57255c47b647f Mon Sep 17 00:00:00 2001 From: Jake Hunsaker Date: Tue, 9 Apr 2019 12:59:03 -0400 Subject: [PATCH] [sosnode] Don't create a container if we're in a container If sos-collector is being launched from a container on a containerized host, we could potentially attempt to create a nested container. This change means we treat a sos-collector run that is already in a container as a "normal" host and don't attempt the containerized bits. Signed-off-by: Jake Hunsaker --- soscollector/sosnode.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/soscollector/sosnode.py b/soscollector/sosnode.py index a040244..405d05d 100644 --- a/soscollector/sosnode.py +++ b/soscollector/sosnode.py @@ -68,10 +68,14 @@ class SosNode(): self.connected = False self.close_ssh_session() return None + if self.local: + if self.check_in_container(): + self.host.containerized = False self.log_debug("Host facts found to be %s" % self.host.report_facts()) self.get_hostname() - self.create_sos_container() + if self.host.containerized: + self.create_sos_container() self._load_sos_info() def _create_ssh_command(self): @@ -84,6 +88,19 @@ class SosNode(): return '{:<{}} : {}'.format(self._hostname, self.config['hostlen'] + 1, msg) + def check_in_container(self): + ''' + Tries to identify if we are currently running in a container or not. + ''' + if os.path.exists('/run/.containerenv'): + self.log_debug('Found /run/.containerenv. Running in container.') + return True + if os.environ.get('container') is not None: + self.log_debug("Found env var 'container'. Running in container") + return True + return False + + def create_sos_container(self): '''If the host is containerized, create the container we'll be using ''' -- 2.17.2