mirror of
https://github.com/ansible-collections/kubernetes.core.git
synced 2026-05-07 05:22:39 +00:00
k8s_log - fix module traceback when resource not found (#493)
k8s_log - fix module traceback when resource not found Depends-on: #495 SUMMARY closes #479 ISSUE TYPE Bugfix Pull Request COMPONENT NAME k8s_log Reviewed-by: Mike Graves <mgraves@redhat.com>
This commit is contained in:
@@ -152,6 +152,12 @@ from ansible_collections.kubernetes.core.plugins.module_utils.k8s.service import
|
||||
K8sService,
|
||||
)
|
||||
|
||||
try:
|
||||
from kubernetes.client.exceptions import ApiException
|
||||
except ImportError:
|
||||
# ImportError are managed by the common module already.
|
||||
pass
|
||||
|
||||
|
||||
def argspec():
|
||||
args = copy.deepcopy(AUTH_ARG_SPEC)
|
||||
@@ -217,9 +223,17 @@ def execute_module(svc, params):
|
||||
{"tailLines": params["tail_lines"]}
|
||||
)
|
||||
|
||||
response = resource.log.get(
|
||||
name=name, namespace=namespace, serialize=False, **kwargs
|
||||
)
|
||||
try:
|
||||
response = resource.log.get(
|
||||
name=name, namespace=namespace, serialize=False, **kwargs
|
||||
)
|
||||
except ApiException as exc:
|
||||
if exc.reason == "Not Found":
|
||||
raise CoreException("Pod {0}/{1} not found.".format(namespace, name))
|
||||
raise CoreException(
|
||||
"Unable to retrieve log from Pod due to: {0}".format(exc.reason)
|
||||
)
|
||||
|
||||
log = response.data.decode("utf8")
|
||||
|
||||
return {"changed": False, "log": log, "log_lines": log.split("\n")}
|
||||
|
||||
Reference in New Issue
Block a user