github.com/wmuizelaar/kpt@v0.0.0-20221018115725-bd564717b2ed/site/book/04-using-functions/03-function-results.md (about) 1 In kpt, the counterpart to Unix philsophophy of "everything is a file" is "everything is a 2 Kubernetes resource". This also extends to the results of executing functions using `eval` or 3 `render`. In addition to providing a human-readable terminal output, these commands provide 4 structured results which can be consumed by other tools. This enables you to build robust UI layers 5 on top of kpt. For example: 6 7 - Create a custom dashboard that shows the results returned by functions 8 - Annotate a GitHub Pull Request with results returned by a validator function at the granularity of individuals fields 9 10 In both `render` and `eval`, structured results can be enabled using the `--results-dir` flag. 11 12 For example: 13 14 ```shell 15 $ kpt fn render wordpress --results-dir /tmp 16 Package "wordpress/mysql": 17 18 [PASS] "gcr.io/kpt-fn/set-labels:v0.1" 19 20 Package "wordpress": 21 22 [PASS] "gcr.io/kpt-fn/set-labels:v0.1" 23 [PASS] "gcr.io/kpt-fn/kubeval:v0.1" 24 25 Successfully executed 3 function(s) in 2 package(s). 26 For complete results, see /tmp/results.yaml 27 ``` 28 29 The results are provided as resource of kind `FunctionResultList`: 30 31 ```yaml 32 # /tmp/results.yaml 33 apiVersion: kpt.dev/v1 34 kind: FunctionResultList 35 metadata: 36 name: fnresults 37 exitCode: 0 38 items: 39 - image: gcr.io/kpt-fn/set-labels:v0.1 40 exitCode: 0 41 - image: gcr.io/kpt-fn/set-labels:v0.1 42 exitCode: 0 43 - image: gcr.io/kpt-fn/kubeval:v0.1 44 exitCode: 0 45 ``` 46 47 Let's see a more interesting result where the `kubeval` function catches a validation issue. 48 For example, change the value of `port` field in `service.yaml` from `80` to `"80"` and 49 rerun: 50 51 ```shell 52 $ kpt fn render wordpress --results-dir /tmp 53 Package "wordpress/mysql": 54 55 [PASS] "gcr.io/kpt-fn/set-labels:v0.1" 56 57 Package "wordpress": 58 59 [PASS] "gcr.io/kpt-fn/set-labels:v0.1" 60 [FAIL] "gcr.io/kpt-fn/kubeval:v0.1" 61 Results: 62 [ERROR] Invalid type. Expected: integer, given: string in object "v1/Service/wordpress" in file "service.yaml" in field "spec.ports.0.port" 63 Exit code: 1 64 65 For complete results, see /tmp/results.yaml 66 ``` 67 68 The results resource will now contain failure details: 69 70 ```yaml 71 # /tmp/results.yaml 72 apiVersion: kpt.dev/v1 73 kind: FunctionResultList 74 metadata: 75 name: fnresults 76 exitCode: 1 77 items: 78 - image: gcr.io/kpt-fn/set-labels:v0.1 79 exitCode: 0 80 - image: gcr.io/kpt-fn/set-labels:v0.1 81 exitCode: 0 82 - image: gcr.io/kpt-fn/kubeval:v0.1 83 exitCode: 1 84 results: 85 - message: "Invalid type. Expected: integer, given: string" 86 severity: error 87 resourceRef: 88 apiVersion: v1 89 kind: Service 90 name: wordpress 91 field: 92 path: spec.ports.0.port 93 file: 94 path: service.yaml 95 ```