Blame SOURCES/sos-collector-nested-container-fix.patch

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