diff --git a/changelogs/fragments/437-k8s-add-support-for-previous-logs.yaml b/changelogs/fragments/437-k8s-add-support-for-previous-logs.yaml new file mode 100644 index 00000000..3328e1af --- /dev/null +++ b/changelogs/fragments/437-k8s-add-support-for-previous-logs.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: +- k8s_log - added the `previous` parameter for retrieving the previously terminated pod logs (https://github.com/ansible-collections/kubernetes.core/issues/437). diff --git a/plugins/modules/k8s_log.py b/plugins/modules/k8s_log.py index 0ba77912..db63e14b 100644 --- a/plugins/modules/k8s_log.py +++ b/plugins/modules/k8s_log.py @@ -60,6 +60,13 @@ options: required: no type: str version_added: '2.2.0' + previous: + description: + - If C(true), print the logs for the previous instance of the container in a pod if it exists. + required: no + type: bool + default: False + version_added: '2.4.0' requirements: - "python >= 3.6" @@ -138,6 +145,7 @@ def argspec(): container=dict(), since_seconds=dict(), label_selectors=dict(type="list", elements="str", default=[]), + previous=dict(type="bool", default=False), ) ) return args @@ -185,6 +193,11 @@ def execute_module(module, k8s_ansible_mixin): {"sinceSeconds": module.params["since_seconds"]} ) + if module.params.get("previous"): + kwargs.setdefault("query_params", {}).update( + {"previous": module.params["previous"]} + ) + log = serialize_log( resource.log.get(name=name, namespace=namespace, serialize=False, **kwargs) )