From e48b38f10e364a89b78f0ce59c1a0516cd594302 Mon Sep 17 00:00:00 2001 From: Santiago Sanchez Paz Date: Mon, 21 Jun 2021 18:19:52 +0200 Subject: [PATCH 1/8] Add sinceSeconds parameter to k8s_logs --- plugins/modules/k8s_log.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/modules/k8s_log.py b/plugins/modules/k8s_log.py index e3be18bf4f..9973f70885 100644 --- a/plugins/modules/k8s_log.py +++ b/plugins/modules/k8s_log.py @@ -54,6 +54,11 @@ - 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 requirements: - "python >= 3.6" @@ -124,6 +129,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 +165,12 @@ def execute_module(module, k8s_ansible_mixin): if module.params.get('container'): kwargs['query_params'] = dict(container=module.params['container']) + if self.params.get('since_seconds'): + if not kwargs['query_params']: + kwargs['query_params'] = dict(sinceSeconds=self.params['since_seconds']) + else: + kwargs['query_params'].update(dict(sinceSeconds=self.params['since_seconds'])) + log = serialize_log(resource.log.get( name=name, namespace=namespace, From ea650730a77df31c6995723d6aee264ef6ba5e8c Mon Sep 17 00:00:00 2001 From: Santiago Sanchez Paz Date: Tue, 22 Jun 2021 12:25:30 +0200 Subject: [PATCH 2/8] Update documentation --- docs/kubernetes.core.k8s_log_module.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/kubernetes.core.k8s_log_module.rst b/docs/kubernetes.core.k8s_log_module.rst index edea0a8c31..03e14e5ec0 100644 --- a/docs/kubernetes.core.k8s_log_module.rst +++ b/docs/kubernetes.core.k8s_log_module.rst @@ -144,6 +144,21 @@ Parameters
If there is more than one container, this option is required.
+ + +
+ since_seconds + +
+ string +
+ + + + +
A relative time in seconds before the current time from which to show logs.
+ +
@@ -457,6 +472,7 @@ Examples kind: Deployment namespace: testing name: example + sinceSeconds: "4000" register: log # This will get the log from a single Pod managed by this DeploymentConfig From 8e4173b0f72ce27c0c1ed97a40464a1d46ecbe3f Mon Sep 17 00:00:00 2001 From: stg <65890694+stg-0@users.noreply.github.com> Date: Tue, 22 Jun 2021 14:29:24 +0200 Subject: [PATCH 3/8] Update plugins/modules/k8s_log.py Co-authored-by: Abhijeet Kasurde --- plugins/modules/k8s_log.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/k8s_log.py b/plugins/modules/k8s_log.py index 9973f70885..90d1e95f07 100644 --- a/plugins/modules/k8s_log.py +++ b/plugins/modules/k8s_log.py @@ -59,6 +59,7 @@ - A relative time in seconds before the current time from which to show logs. required: no type: str + version_added: '2.1.0' requirements: - "python >= 3.6" From 7ff595aeaeb435dc65bb57d30e32f81b5ae244b3 Mon Sep 17 00:00:00 2001 From: Santiago Sanchez Paz Date: Tue, 22 Jun 2021 14:45:17 +0200 Subject: [PATCH 4/8] Add changelog fragment --- changelogs/fragments/142-add-sinceseconds-param-for-logs.yaml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/142-add-sinceseconds-param-for-logs.yaml 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). From 52ac586953ec508c9d6463e7e7ba02227903c47e Mon Sep 17 00:00:00 2001 From: Santiago Sanchez Paz Date: Tue, 22 Jun 2021 14:47:58 +0200 Subject: [PATCH 5/8] Fix/example --- docs/kubernetes.core.k8s_log_module.rst | 16 ---------------- plugins/modules/k8s_log.py | 1 + 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/docs/kubernetes.core.k8s_log_module.rst b/docs/kubernetes.core.k8s_log_module.rst index 03e14e5ec0..edea0a8c31 100644 --- a/docs/kubernetes.core.k8s_log_module.rst +++ b/docs/kubernetes.core.k8s_log_module.rst @@ -144,21 +144,6 @@ Parameters
If there is more than one container, this option is required.
- - -
- since_seconds - -
- string -
- - - - -
A relative time in seconds before the current time from which to show logs.
- -
@@ -472,7 +457,6 @@ Examples kind: Deployment namespace: testing name: example - sinceSeconds: "4000" register: log # This will get the log from a single Pod managed by this DeploymentConfig diff --git a/plugins/modules/k8s_log.py b/plugins/modules/k8s_log.py index 90d1e95f07..6c86b12a8c 100644 --- a/plugins/modules/k8s_log.py +++ b/plugins/modules/k8s_log.py @@ -89,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 From 161137a36ff0bd828ef127e6610149988ce63f04 Mon Sep 17 00:00:00 2001 From: Santiago Sanchez Paz Date: Tue, 22 Jun 2021 18:55:04 +0200 Subject: [PATCH 6/8] Fix/self references --- plugins/modules/k8s_log.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/modules/k8s_log.py b/plugins/modules/k8s_log.py index 6c86b12a8c..e0ff6b05d1 100644 --- a/plugins/modules/k8s_log.py +++ b/plugins/modules/k8s_log.py @@ -167,11 +167,11 @@ def execute_module(module, k8s_ansible_mixin): if module.params.get('container'): kwargs['query_params'] = dict(container=module.params['container']) - if self.params.get('since_seconds'): + if module.params.get('since_seconds'): if not kwargs['query_params']: - kwargs['query_params'] = dict(sinceSeconds=self.params['since_seconds']) + kwargs['query_params'] = dict(sinceSeconds=module.params['since_seconds']) else: - kwargs['query_params'].update(dict(sinceSeconds=self.params['since_seconds'])) + kwargs['query_params'].update(dict(sinceSeconds=module.params['since_seconds'])) log = serialize_log(resource.log.get( name=name, From 60981ad6e878bc5ce6e1a78db6b5d9d642974568 Mon Sep 17 00:00:00 2001 From: stg <65890694+stg-0@users.noreply.github.com> Date: Tue, 29 Jun 2021 10:29:46 +0200 Subject: [PATCH 7/8] Update plugins/modules/k8s_log.py Co-authored-by: Mike Graves --- plugins/modules/k8s_log.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/modules/k8s_log.py b/plugins/modules/k8s_log.py index e0ff6b05d1..3154b99577 100644 --- a/plugins/modules/k8s_log.py +++ b/plugins/modules/k8s_log.py @@ -168,10 +168,8 @@ def execute_module(module, k8s_ansible_mixin): kwargs['query_params'] = dict(container=module.params['container']) if module.params.get('since_seconds'): - if not kwargs['query_params']: - kwargs['query_params'] = dict(sinceSeconds=module.params['since_seconds']) - else: - kwargs['query_params'].update(dict(sinceSeconds=module.params['since_seconds'])) + kwargs.setdefault('query_params', {}).update({'sinceSeconds': module.params['since_seconds']}) + log = serialize_log(resource.log.get( name=name, From 8ca53217b014723f1bb0996bb6c451b7d9a7fcdb Mon Sep 17 00:00:00 2001 From: Santiago Sanchez Paz Date: Tue, 29 Jun 2021 15:02:20 +0200 Subject: [PATCH 8/8] fix/sanity --- plugins/modules/k8s_log.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/modules/k8s_log.py b/plugins/modules/k8s_log.py index 3154b99577..0c07ce7077 100644 --- a/plugins/modules/k8s_log.py +++ b/plugins/modules/k8s_log.py @@ -59,7 +59,7 @@ - A relative time in seconds before the current time from which to show logs. required: no type: str - version_added: '2.1.0' + version_added: '2.2.0' requirements: - "python >= 3.6" @@ -170,7 +170,6 @@ def execute_module(module, k8s_ansible_mixin): 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,