Improve logs and case-sensitive on k8s-coredump

Improving logging by adding timestamp and
show error in case we have a KeyError while
trying to verify configurations set by
pod annotations.
Also allowing case-sensitive paths to be
configured as the path to save the coredumps.

PASS: AIO-SX install and bootstrap.
PASS: On a AIO-SX test if k8s-coredump is executed
	successfully.
PASS: On a AIO-DX test if k8s-coredump is executed
        successfully.
PASS: On a Standard test if k8s-coredump is executed
        successfully.
PASS: On a Standard test if k8s-coredump is executed
	successfully using a PVC setup.

Partial-Bug: 2045789

Change-Id: I942253468a596b7d68d6a3733b24062cfb4661f7
Signed-off-by: Heron Vieira <heron.vieira@windriver.com>
This commit is contained in:
Heron Vieira 2023-11-29 11:38:14 -03:00
parent 5e7fd494a0
commit 0f3b062fa3
3 changed files with 17 additions and 6 deletions

View File

@ -14,5 +14,7 @@ LOCALHOST_URL = "https://localhost:10250/pods"
SYSTEMD_COREDUMP = "/usr/lib/systemd/systemd-coredump"
logging.basicConfig(filename=K8S_COREDUMP_LOG, level=logging.DEBUG)
logging.basicConfig(filename=K8S_COREDUMP_LOG, level=logging.DEBUG,
format='%(asctime)s %(levelname)s %(message)s',
datefmt='%FT%T')
LOG = logging.getLogger("k8s-coredump")

View File

@ -66,9 +66,12 @@ def parse_core_pattern(string_core_pattern, **kwargs):
str
String with all the information replaced accordingly
"""
string_core_pattern = string_core_pattern.lower()
LOG.info(f'Full path passed to parse_core_pattern: {string_core_pattern}')
splited_path = string_core_pattern.split("/")
string_core_pattern = splited_path[splited_path.__len__()-1]
LOG.info(f'Parsing core pattern: {string_core_pattern}')
processed_string = string_core_pattern
processed_string = string_core_pattern.lower()
processed_string = processed_string.replace('%p', kwargs['pid'])
processed_string = processed_string.replace('%u', kwargs['uid'])
processed_string = processed_string.replace('%g', kwargs['gid'])
@ -77,7 +80,12 @@ def parse_core_pattern(string_core_pattern, **kwargs):
processed_string = processed_string.replace('%h', kwargs['hostname'])
processed_string = processed_string.replace('%e', kwargs['comm2'])
LOG.info(f'Core pattern parsed to {processed_string}')
return processed_string
splited_path[splited_path.__len__()-1] = processed_string
full_path_processed = "/".join(splited_path)
LOG.info(f'Full path parsed by parse_core_pattern: {full_path_processed}')
return full_path_processed
def parse_size_config(string_config):
@ -108,6 +116,7 @@ def parse_size_config(string_config):
f'(Multiplier of bytes: {size_properties["multiplier"]})')
return float(value), size_properties
LOG.info(f'Unable to parse size configuration from: {string_config}')
return None

View File

@ -127,8 +127,8 @@ def CoreDumpHandler(**kwargs):
except ValueError as e:
LOG.error("Pod defined an invalid core dump annotation: %s" % e)
sys.exit(-1)
except KeyError:
LOG.debug("Pod does have annotations defined")
except KeyError as e:
LOG.debug("Pod does have annotations defined but some configuration is missing: %s" % e)
pass
# not handled by pod, redirect to systemd coredump handler