View Kubernetes Logs in PRs
Stoat can help you easily view and access logs for Kubernetes clusters (Minikube, k3s, etc.) in your GitHub workflows from a comment on your pull request.
Here's an example of a Stoat comment that links to an interactive log viewer for Kubernetes:
Example Repo
See a real build that links to a log viewer for Kubernetes logs this pull request.
Adding Kubernetes log previews to the Stoat comment
In this tutorial we will show how to add a Kubernetes log preview to the Stoat comment.
-
Set up Stoat with our getting started guide.
-
Add an action to dump logs to some directory using
stoat-dev/kubernetes-log-export-action@v1
and add the Stoat Action to upload the log outputs to Stoat..github/workflows/kubernetes.yaml# ... cluster initialization ...
# ... tests that run on Kubernetes ...
- name: Dump Kubernetes Logs
if: always()
uses: stoat-dev/kubernetes-log-export-action@v1
with:
namespaces: default,kube-system
show_timestamps: 'true'
output_dir: kube-logs-output
- name: Run Stoat Action
uses: stoat-dev/stoat-action@v0
if: always()Note that if you don't include
if: always()
the results will not be captured on test failure. -
Point Stoat at the generated logs by adding a new task that uses the
static_hosting
plugin:.stoat/config.yaml---
version: 1
enabled: true
plugins:
static_hosting:
kube_logs:
metadata:
name: "Kubernetes Logs"
path: kube-logs-output
file_viewer: trueNote that this uses the
file_viewer: true
option to provide an interactive log viewing experience. -
That's it! Now, every time you open a pull request, Stoat will host the Kubernetes logs and post a comment with a link to the preview. See an example in this pull request.