mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-07-28 10:24:45 +00:00
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.
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
from ansible.module_utils.six import PY2
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
@@ -182,11 +184,12 @@ class KubernetesLogModule(KubernetesAnsibleModule):
|
|||||||
if self.params.get('container'):
|
if self.params.get('container'):
|
||||||
kwargs['query_params'] = dict(container=self.params['container'])
|
kwargs['query_params'] = dict(container=self.params['container'])
|
||||||
|
|
||||||
log = resource.log.get(
|
log = serialize_log(resource.log.get(
|
||||||
name=name,
|
name=name,
|
||||||
namespace=self.params.get('namespace'),
|
namespace=self.params.get('namespace'),
|
||||||
|
serialize=False,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
))
|
||||||
|
|
||||||
self.exit_json(changed=False, log=log, log_lines=log.split('\n'))
|
self.exit_json(changed=False, log=log, log_lines=log.split('\n'))
|
||||||
|
|
||||||
@@ -228,6 +231,12 @@ class KubernetesLogModule(KubernetesAnsibleModule):
|
|||||||
return selectors
|
return selectors
|
||||||
|
|
||||||
|
|
||||||
|
def serialize_log(response):
|
||||||
|
if PY2:
|
||||||
|
return response.data
|
||||||
|
return response.data.decode('utf8')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
KubernetesLogModule().execute_module()
|
KubernetesLogModule().execute_module()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user