Skip to content

Commit 74d82d5

Browse files
authored
Add a Tips, tricks, and shortcuts for Porch developers (Lazy Dog) to Porch documentation (#955)
* Add Lazy Dog to Porch documentation Signed-off-by: liamfallon <liam.fallon@est.tech> * Fix typo in reference Signed-off-by: liamfallon <liam.fallon@est.tech> * Deleted irrelevant comment at bottom Signed-off-by: liamfallon <liam.fallon@est.tech> * Fix typo Signed-off-by: liamfallon <liam.fallon@est.tech> * Fix typo Signed-off-by: liamfallon <liam.fallon@est.tech> * Fix copilot comments Signed-off-by: liamfallon <liam.fallon@est.tech> * Fix copilot comments Signed-off-by: liamfallon <liam.fallon@est.tech> * Fix copilot comments Signed-off-by: liamfallon <liam.fallon@est.tech> --------- Signed-off-by: liamfallon <liam.fallon@est.tech>
1 parent e2017b4 commit 74d82d5

3 files changed

Lines changed: 5377 additions & 0 deletions

File tree

docs/content/en/docs/9_troubleshooting_and_faq/_index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ Recovering from data loss scenarios:
3737
- DB cache loss with and without backups
3838
- Backup strategies for Porch components
3939

40+
### [Porch Lazy Dog (Lathund)]({{% relref "lazy-dog" %}})
41+
42+
A quick reference of tips, tricks, workarounds, and shortcuts for developers working with Porch. Please raise a PR to
43+
add your Porch magic spells to the Lazy Dog.
44+
4045
## Getting Help
4146

4247
If you encounter issues not covered in this guide:
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: "Porch Lazy Dog (Lathund)"
3+
type: docs
4+
weight: 9
5+
description: Tips, tricks, and shortcuts for Porch developers
6+
---
7+
8+
![Lazy Dog](/images/porch/LazyDog.svg)
9+
10+
A quick reference [Lazy Dog/Lathund](https://watchingtheswedes.com/2021/09/05/swedish-expression-lazy-dog/) of tips,
11+
tricks, workarounds, and shortcuts for developers working with Porch. Please raise a PR to add your Porch magic spells to the Lazy Dog.
12+
13+
## Debugging Starlark scripts
14+
15+
Debugging Starlark scripts can be difficult, especially when running mutation pipelines in Porch. One technique is to put `print` statements in the code to print the value of variables. For example:
16+
17+
```python
18+
def set_package_name(resources, root_kptfile_path, root_package_name):
19+
for r in resources:
20+
resource_path = r["metadata"]["annotations"]["internal.config.kubernetes.io/package-path"]
21+
resource_name = r["metadata"]["annotations"]["config.kubernetes.io/path"]
22+
print("Resource Path: " + resource_path)
23+
print("Resource Name: " + resource_name)
24+
```
25+
26+
But that's not enough in Porch.
27+
28+
To force output of the result of partial rendering of failing pipelines in kpt, you must set [the following annotation](https://kpt.dev/book/04-using-functions/#debugging-render-failures) on the `Kptfile`:
29+
30+
```yaml
31+
apiVersion: kpt.dev/v1
32+
kind: Kptfile
33+
metadata:
34+
name: wordpress
35+
annotations:
36+
kpt.dev/save-on-render-failure: "true"
37+
```
38+
39+
You also must set an annotation on the Package Revision so that Porch will [push draft package revisions even when they
40+
fail](https://docs.porch.nephio.org/docs/4_tutorials_and_how-tos/working_with_package_revisions/#troubleshooting).
41+
42+
```bash
43+
kubectl annotate packagerevision <name> porch.kpt.dev/push-on-render-failure=true
44+
```
45+
46+
If the mutation pipeline is passing, you won't get any output from your `print()` statement because Porch assumes
47+
everything is OK and does not print any output. The easiest way to work around this is to put a deliberate runtime error
48+
into your Starlark script, which will cause an error and trigger the output:
49+
50+
```python
51+
set_package_name(ctx.resource_list["items"], root_kptfile_path, root_package_name)
52+
53+
i = 10/0 # Deliberate division by zero error
54+
```

docs/static/images/porch/LazyDog.svg

Lines changed: 5318 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)