From 38ac7dc5341de60645fa4b0d35de953cdd9971dd Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Wed, 12 Jun 2024 12:49:04 +0200 Subject: [PATCH] [pod_log] Add new pod_log plugin In Kubernetes/OpenShift rotated logs have no symbolic link in /var/log/containers and they cannot be retrieved using `oc logs` either, so there is no way to get these rotated logs in a SOS report. This patch proposes a new plugin called `pod_log`, similar to the xisting `container_log`, that can retrieve rotated logs for the containers. The plugin will not only download the `/var/log/pods` files but also the `/var/log/container` symlinks. The plugin doesn't use the `all_logs` flag, since the usage of the plugin assumes the intent of getting rotated logs, otherwise the `container_log` plugin can be used. An alternative would be to extend the existing `container_log` plugin to also retrieve rotated container logs. This approach has been discarded because we would either have to modify existing behavior for the `all_logs` flag (breaking backward compatibility) or add a new parser arguments just to tell it to also gather rotated logs (not reasonable). Closes #3677 Signed-off-by: Gorka Eguileor --- sos/report/plugins/pod_log.py | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 sos/report/plugins/pod_log.py diff --git a/sos/report/plugins/pod_log.py b/sos/report/plugins/pod_log.py new file mode 100644 index 0000000000..7987cc5ea6 --- /dev/null +++ b/sos/report/plugins/pod_log.py @@ -0,0 +1,39 @@ +# Copyright (C) 2024 Red Hat, Inc. +# +# This file is part of the sos project: https://github.com/sosreport/sos +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions of +# version 2 of the GNU General Public License. +# +# See the LICENSE file in the source distribution for further information. + +import os +from sos.report.plugins import IndependentPlugin, Plugin, PluginOpt + + +class PodLog(Plugin, IndependentPlugin): + + short_desc = 'All logs under /var/log/pods' + long_desc = ('Get all the logs from /var/log/pods and also recreate the ' + '/var/log/containers symlinks to them. This will get rotated ' + 'logs in Kubernetes/OpenShift') + plugin_name = 'pod_log' + logdirs = ('/var/log/pods/', '/var/log/containers/') + files = (logdirs[0], ) + option_list = [ + PluginOpt('anysize', default=False, val_type=bool, + desc='gather all pod logs ignoring size limits'), + PluginOpt('maxage', default=None, val_type=int, + desc='gather only pod logs with `mtime` not older than this ' + 'many hours') + ] + + def setup(self): + self.add_copy_spec( + self.logdirs, + sizelimit=0 if self.get_option('anysize') else None, + maxage=self.get_option('maxage'), + ) + +# vim: set et ts=4 sw=4 :