get_logs_for_cronjob
Retrieves logs from a Kubernetes CronJob's last run by locating the job and pod created for that run, removing the need to manually find short-lived pods.
Instructions
Retrieves logs from the most-recent run of a CronJob.
Finds the newest Job owned by the CronJob, then returns the logs of that Job's
most-recently-created pod. Removes the need to manually locate the right
short-lived pod for a CronJob's last tick.
Parameters
----------
cronjob_name : str
Name of the CronJob.
namespace : str, optional
Namespace of the CronJob (default is "default").
container_name : str, optional
Container within the pod. If None, defaults to the first container.
tail : int, optional
Number of lines from the end of the log (default: last 1000).
since_seconds : int, optional
If set, only return logs newer than this many seconds.
previous : bool, default False
If True, return logs from the previous terminated container instance.
See `get_logs_for_pod_and_container` for the cases - CrashLoopBackOff, a
restart racing the call, a reclaimed log file - where that legitimately
returns the same text as `previous=False`, or a 200 whose body is an
error message.
Returns
-------
str, optional
Log content, or None if the CronJob has no jobs/pods yet.
Raises
------
K8sConfigError
If unable to initialize the K8S API.
K8sApiError
If the API call fails.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tail | No | ||
| previous | No | ||
| namespace | No | default | |
| cronjob_name | Yes | ||
| since_seconds | No | ||
| container_name | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |