diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2019-04-08 15:51:05 -0400 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2019-05-14 11:22:25 +0100 |
commit | 877014bbfd85c02083a716212a5cbbe715f4b96a (patch) | |
tree | c591015d1d461112d7b2b9f92f0278427d619d85 | |
parent | bf73edcacdb2fa33510bbf73ab654345eba0a717 (diff) | |
download | sos-877014bbfd85c02083a716212a5cbbe715f4b96a.tar.gz |
[kubernetes] Allow only capturing logs for certain pods
The 'podlogs' option was previously an all-or-nothing toggle, which
could result in incredibly large amounts of data collection when only a
few pod's logs were needed.
This change adds a 'podlogs-filter' option that allows users to provide
either a specific pod name or a regex to match pod names against, to
limit the amount of pod logs we collect.
Resolves: #1640
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r-- | sos/plugins/kubernetes.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/sos/plugins/kubernetes.py b/sos/plugins/kubernetes.py index 4ae51162..dc7ee278 100644 --- a/sos/plugins/kubernetes.py +++ b/sos/plugins/kubernetes.py @@ -10,8 +10,11 @@ # See the LICENSE file in the source distribution for further information. from sos.plugins import Plugin, RedHatPlugin +from fnmatch import translate from os import path +import re + class kubernetes(Plugin, RedHatPlugin): @@ -35,6 +38,8 @@ class kubernetes(Plugin, RedHatPlugin): ("describe", "capture descriptions of all kube resources", 'fast', False), ("podlogs", "capture logs for pods", 'slow', False), + ("podlogs-filter", "only capture logs for pods matching this string", + 'fast', '') ] def check_is_master(self): @@ -134,7 +139,12 @@ class kubernetes(Plugin, RedHatPlugin): if r['status'] == 0: pods = [p.split()[0] for p in r['output'].splitlines()[1:]] + # allow shell-style regex + reg = (translate(self.get_option('podlogs-filter')) if + self.get_option('podlogs-filter') else None) for pod in pods: + if reg and not re.match(reg, pod): + continue self.add_cmd_output('%s logs %s' % (k_cmd, pod)) if not self.get_option('all'): |