Porch Lazy Dog (Lathund)
A quick reference Lazy Dog/Lathund of tips, tricks, workarounds, and shortcuts for developers working with Porch. Please raise a PR to add your Porch magic spells to the Lazy Dog.
Debugging Starlark scripts
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:
def set_package_name(resources, root_kptfile_path, root_package_name):
for r in resources:
resource_path = r["metadata"]["annotations"]["internal.config.kubernetes.io/package-path"]
resource_name = r["metadata"]["annotations"]["config.kubernetes.io/path"]
print("Resource Path: " + resource_path)
print("Resource Name: " + resource_name)
But that’s not enough in Porch.
To force output of the result of partial rendering of failing pipelines in kpt, you must set
the following annotation on the Kptfile:
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: wordpress
annotations:
kpt.dev/save-on-render-failure: "true"
You also must set an annotation on the Package Revision so that Porch will push draft package revisions even when they fail.
kubectl annotate packagerevision <name> porch.kpt.dev/push-on-render-failure=true
If the mutation pipeline is passing, you won’t get any output from your print() statement because Porch assumes
everything is OK and does not print any output. The easiest way to work around this is to put a deliberate runtime error
into your Starlark script, which will cause an error and trigger the output:
set_package_name(ctx.resource_list["items"], root_kptfile_path, root_package_name)
i = 10/0 # Deliberate division by zero error