mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-03-26 21:33:02 +00:00
Adding previous container log support (#436)
Adding previous container log support Signed-off-by: Joshua Eason josh.eason@anchore.com SUMMARY Adds support for the previous parameter in kubectl logs. This allows for the retrieval of the previously terminated containers logs which is useful for troubleshooting. ISSUE TYPE Feature Pull Request COMPONENT NAME k8s_log ADDITIONAL INFORMATION Adds the previous parameter (bool) to k8s_log module. This matches the documentation for kubectl logs --previous parameter. This parameter allows for retrieving the previously terminated containers logs. Output of the module is identical with the exception being the logs returned are from the previously terminated container. Reviewed-by: Mike Graves <mgraves@redhat.com> Reviewed-by: Abhijeet Kasurde <None> Reviewed-by: Joshua Eason <None>
This commit is contained in:
@@ -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).
|
||||
@@ -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)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user