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

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