diff --git a/porch/test/e2e/e2e_test.go b/porch/test/e2e/e2e_test.go index 9aaca03b9e..b79b91ebb1 100644 --- a/porch/test/e2e/e2e_test.go +++ b/porch/test/e2e/e2e_test.go @@ -556,6 +556,68 @@ func (t *PorchSuite) TestUpdateResources(ctx context.Context) { } } +// Test will initialize an empty package, update its resources, adding a function +// to the Kptfile's pipeline, and then check that the package was re-rendered. +func (t *PorchSuite) TestRenderFailureOnPkgUpdate(ctx context.Context) { + const ( + repository = "re-render-test" + packageName = "simple-package" + description = "description" + ) + + t.registerMainGitRepositoryF(ctx, repository) + + // Create a new package (via init) + pr := &porchapi.PackageRevision{ + TypeMeta: metav1.TypeMeta{ + Kind: "PackageRevision", + APIVersion: porchapi.SchemeGroupVersion.String(), + }, + ObjectMeta: metav1.ObjectMeta{ + Namespace: t.namespace, + }, + Spec: porchapi.PackageRevisionSpec{ + PackageName: packageName, + WorkspaceName: description, + RepositoryName: repository, + }, + } + t.CreateF(ctx, pr) + + // Get the package resources + var newPackage porchapi.PackageRevisionResources + t.GetF(ctx, client.ObjectKey{ + Namespace: t.namespace, + Name: pr.Name, + }, &newPackage) + + // Add a new resource + filename := filepath.Join("testdata", "render-status", "validate.yaml") + validationFn, err := os.ReadFile(filename) + if err != nil { + t.Fatalf("Failed to read validation function input from %q: %v", filename, err) + } + newPackage.Spec.Resources["validate.yaml"] = string(validationFn) + + // Add function into a pipeline + kptfile := t.ParseKptfileF(&newPackage) + if kptfile.Pipeline == nil { + kptfile.Pipeline = &kptfilev1.Pipeline{} + } + kptfile.Pipeline.Validators = append(kptfile.Pipeline.Validators, kptfilev1.Function{ + Image: "gcr.io/kpt-fn/starlark:v0.4.3", + Name: "always-fail", + ConfigPath: "validate.yaml", + }) + + t.SaveKptfileF(&newPackage, kptfile) + + t.UpdateF(ctx, &newPackage) + + renderStatus := newPackage.Status.RenderStatus + assert.NotEmpty(t, renderStatus.Err, "render error must be not empty for failed render operation.") +} + func (t *PorchSuite) TestFunctionRepository(ctx context.Context) { repo := &configapi.Repository{ ObjectMeta: metav1.ObjectMeta{ diff --git a/porch/test/e2e/testdata/render-status/validate.yaml b/porch/test/e2e/testdata/render-status/validate.yaml new file mode 100644 index 0000000000..0d861833c2 --- /dev/null +++ b/porch/test/e2e/testdata/render-status/validate.yaml @@ -0,0 +1,8 @@ +apiVersion: fn.kpt.dev/v1alpha1 +kind: StarlarkRun +metadata: + name: validate + annotations: + config.kubernetes.io/local-config: "true" +source: |- + fail("Validation always fails") \ No newline at end of file