nephio-project / nephio

Nephio is a Kubernetes-based automation platform for deploying and managing highly distributed, interconnected workloads such as 5G Network Functions, and the underlying infrastructure on which those workloads depend.
Apache License 2.0
93 stars 52 forks source link

Porch returns a generic error when Kptfile validation fails on render #680

Closed liamfallon closed 1 week ago

liamfallon commented 2 months ago

Original issue URL: https://github.com/kptdev/kpt/issues/3423 Original issue user: https://github.com/ChristopherFry Original issue created at: 2022-07-30T03:03:30Z Original issue last updated at: 2022-08-24T20:43:54Z Original issue body: Porch always returns a generic error when a Kptfile validator function fails on render.

Expected behavior

Porch should return the fail message of the validator.

Actual behavior

Porch returns the following error regardless of the fail message of the validator

Error: Internal error occurred: fn.render: pkg .:
        pkg.render:
        pipeline.run: error: function failure 

Information

Both Porch and the CLI are on https://github.com/GoogleContainerTools/kpt/tree/208b4c422c85ff6da4cb4c2b9755f0a23a1329c6.

Steps to reproduce the behavior

  1. Create a simple Kpt package using kpt alpha rpkg init

  2. Use kpt alpha rpkg pull to save package to local filesystem

  3. Add a simple StarlarkRun validation resource to the package

    apiVersion: fn.kpt.dev/v1alpha1
    kind: StarlarkRun
    metadata:
    name: validate
    annotations:
    config.kubernetes.io/local-config: "true"
    source: |-
    fail("Validation always fails")
  4. Update Kptfile to reference StarlarkRun resource

    pipeline:
    validators:
    - image: gcr.io/kpt-fn/starlark:v0.4.3
    configPath: validate.yaml
  5. Using kpt fn render the expected error message returns

    Package "this-package": 
    [RUNNING] "gcr.io/kpt-fn/starlark:v0.4.3"
    [FAIL] "gcr.io/kpt-fn/starlark:v0.4.3" in 4.4s
    Results:
    [error]: fail: Validation always fails
    Stderr:
    "failed to evaluate function: error: function failure"
    Exit code: 1
  6. Using kpt alpha rpkg push to push the package to Porch the generic error message is returned

    Error: Internal error occurred: fn.render: pkg .:
        pkg.render:
        pipeline.run: error: function failure 

Original issue comments: Comment user: https://github.com/natasha41575 Comment created at: 2022-08-09T22:23:14Z Comment last updated at: 2022-08-09T22:23:35Z Comment body: https://github.com/GoogleContainerTools/kpt/pull/3451 will surface the validation error. Do you mind taking a quick look to see if the format of the returned error works for you?

Comment user: https://github.com/natasha41575 Comment created at: 2022-08-24T20:43:54Z Comment last updated at: 2022-08-24T20:43:54Z Comment body: Per offline discussion, @droot will be taking over this by surfacing the function results in the API.

liamfallon commented 1 week ago

This bug has already been fixed, following the steps above (log below) shows that the correct error message is emitted.

% porchctl rpkg init looby --repository mgmt --workspace liam -n zooby
mgmt-cc83c405baad19f7dfe2dd64db8dec71fad56041 created

% porchctl rpkg pull mgmt-cc83c405baad19f7dfe2dd64db8dec71fad56041 -n zooby looby

% echo "Added the Starlark pipeline entry"
Added the Starlark pipeline entry

% kpt fn render looby
Package "looby": 
[RUNNING] "gcr.io/kpt-fn/starlark:v0.4.3"
[FAIL] "gcr.io/kpt-fn/starlark:v0.4.3" in 200ms
  Results:
    [error]: fail: Validation always fails
  Stderr:
    "failed to evaluate function: error: function failure"
  Exit code: 1

% porchctl rpkg push mgmt-cc83c405baad19f7dfe2dd64db8dec71fad56041 -n zooby looby
Package is updated, but failed to render the package.
Error: fn.render: pkg /:
    pkg.render:
    pipeline.run: error: function failure
[RUNNING] "gcr.io/kpt-fn/starlark:v0.4.3" 
[FAIL] "gcr.io/kpt-fn/starlark:v0.4.3"
  Results:
    [error]: fail: Validation always fails
mgmt-cc83c405baad19f7dfe2dd64db8dec71fad56041 pushed

% porchctl rpkg delete -n zooby mgmt-cc83c405baad19f7dfe2dd64db8dec71fad56041
mgmt-cc83c405baad19f7dfe2dd64db8dec71fad56041 deleted
liamfallon commented 1 week ago

Already fixed in current version of Porch.