From fe6480594e6589f887499ce31978935d1ddac2e9 Mon Sep 17 00:00:00 2001 From: Fabian von Feilitzsch Date: Tue, 31 Mar 2020 14:52:52 -0400 Subject: [PATCH] k8s_log no longer attempts to parse log as JSON Fixes #68 Rather than relying on the default serialization logic (which attempts to parse a log as JSON and then load it into a wrapper class), we now simply return the raw log data as expected. The previous behavior worked in many cases because the log was serialized into a JSON string, but in the case of #68 the log was loaded as a JSON float, which made the error handling fail to fallback to returning the raw data. --- plugins/modules/k8s_log.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/modules/k8s_log.py b/plugins/modules/k8s_log.py index 6a0b55ff..fa31f8bc 100644 --- a/plugins/modules/k8s_log.py +++ b/plugins/modules/k8s_log.py @@ -6,6 +6,8 @@ from __future__ import absolute_import, division, print_function +from ansible.module_utils.six import PY2 + __metaclass__ = type @@ -182,11 +184,12 @@ class KubernetesLogModule(KubernetesAnsibleModule): if self.params.get('container'): kwargs['query_params'] = dict(container=self.params['container']) - log = resource.log.get( + log = serialize_log(resource.log.get( name=name, namespace=self.params.get('namespace'), + serialize=False, **kwargs - ) + )) self.exit_json(changed=False, log=log, log_lines=log.split('\n')) @@ -228,6 +231,12 @@ class KubernetesLogModule(KubernetesAnsibleModule): return selectors +def serialize_log(response): + if PY2: + return response.data + return response.data.decode('utf8') + + def main(): KubernetesLogModule().execute_module()