Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sinceSeconds parameter to k8s_logs #142

Merged
merged 8 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/142-add-sinceseconds-param-for-logs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- k8s_log - Add since-seconds parameter to the k8s_log module (https://github.com/ansible-collections/kubernetes.core/pull/142).
11 changes: 11 additions & 0 deletions plugins/modules/k8s_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
- If there is more than one container, this option is required.
required: no
type: str
since_seconds:
description:
- A relative time in seconds before the current time from which to show logs.
Akasurde marked this conversation as resolved.
Show resolved Hide resolved
required: no
type: str
stg-0 marked this conversation as resolved.
Show resolved Hide resolved
version_added: '2.2.0'

requirements:
- "python >= 3.6"
Expand Down Expand Up @@ -83,6 +89,7 @@
kind: Deployment
namespace: testing
name: example
since_seconds: "4000"
register: log

# This will get the log from a single Pod managed by this DeploymentConfig
Expand Down Expand Up @@ -124,6 +131,7 @@ def argspec():
dict(
kind=dict(type='str', default='Pod'),
container=dict(),
since_seconds=dict(),
label_selectors=dict(type='list', elements='str', default=[]),
)
)
Expand Down Expand Up @@ -159,6 +167,9 @@ def execute_module(module, k8s_ansible_mixin):
if module.params.get('container'):
kwargs['query_params'] = dict(container=module.params['container'])

if module.params.get('since_seconds'):
kwargs.setdefault('query_params', {}).update({'sinceSeconds': module.params['since_seconds']})

log = serialize_log(resource.log.get(
name=name,
namespace=namespace,
Expand Down