diff --git a/changelogs/fragments/142-add-sinceseconds-param-for-logs.yaml b/changelogs/fragments/142-add-sinceseconds-param-for-logs.yaml new file mode 100644 index 0000000000..7b2189e83b --- /dev/null +++ b/changelogs/fragments/142-add-sinceseconds-param-for-logs.yaml @@ -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). diff --git a/plugins/modules/k8s_log.py b/plugins/modules/k8s_log.py index e3be18bf4f..0c07ce7077 100644 --- a/plugins/modules/k8s_log.py +++ b/plugins/modules/k8s_log.py @@ -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. + required: no + type: str + version_added: '2.2.0' requirements: - "python >= 3.6" @@ -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 @@ -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=[]), ) ) @@ -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,