Skip to content

Complete transfer of kpt updates from Porch to kpt#4355

Open
liamfallon wants to merge 9 commits intokptdev:mainfrom
Nordix:refactor-kpt
Open

Complete transfer of kpt updates from Porch to kpt#4355
liamfallon wants to merge 9 commits intokptdev:mainfrom
Nordix:refactor-kpt

Conversation

@liamfallon
Copy link
Contributor

@liamfallon liamfallon commented Jan 20, 2026

This PR completes the transfer of updates to cloned kpt code in Porch to kpt.

Once this PR is merged, all cloned kpt code in Porch can be removed and Porch can use the definitive kpt code.

When this PR and its companion PR in Porch are merged, the kpt code base will increase by 2357 lines of code (1703 lines of go code) and the Porch codebase will decrease by 24,757 lines of code (22,948 lines of go code)

This PR also removes the porch dependency in kpt.

Fixes: #4271
Fixes: #4276
Fixes: #4356

See also the corresponding PR in Nephio: nephio-project/porch#411

Summary of Changes

Transferred kpt operations from Porch

Porch has the following macro kpt operations that properly belong in kpt:

  • Clone a kpt package
  • Order a 'kpt fn eval' invocation
  • Order a 'kpt fn render' invocation

These operations are transferred to kpt from Porch. By having them in kpt as operations that users can call, it reduces the dependencies
from Porch on the internals of kpt drastically. Porch just calls the operaitons, which delegates the implementaitons to kpt.

We may not need the internal/kptops package because it contains translators and amendments of "apply-setters", "set-labels", and "set-namespace". These
translators and amendments should probably be in the function implementations in the "krm-functions-catalog" repo,
see this issue

New files in kpt:

pkg/lib/kptops/clone_test.go
pkg/lib/kptops/clone.go
pkg/lib/kptops/eval_test.go
pkg/lib/kptops/eval.go
pkg/lib/kptops/fnruntime.go
pkg/lib/kptops/fs_test.go
pkg/lib/kptops/pkgupdate.go
pkg/lib/kptops/render_test.go
pkg/lib/kptops/render.go
pkg/lib/kptops/testdata/bucket/bucket.yaml
pkg/lib/kptops/testdata/render-with-function-config/expected.txt
pkg/lib/kptops/testdata/render-with-function-config/simple-bucket/bucket.yaml
pkg/lib/kptops/testdata/render-with-function-config/simple-bucket/Kptfile
pkg/lib/kptops/testdata/render-with-function-config/simple-bucket/setters.yaml
pkg/lib/kptops/testdata/render-with-inline-config/expected.txt
pkg/lib/kptops/testdata/render-with-inline-config/simple-bucket/bucket.yaml
pkg/lib/kptops/testdata/render-with-inline-config/simple-bucket/Kptfile
internal/kptops/apply-setters.go
internal/kptops/doc.go
internal/kptops/functions.go
internal/kptops/set-labels.go
internal/kptops/set-namespace.go

Transfer three way merge from Porch to kpt

New files in kpt:

internal/util/update/merge3/merge3_test.go
internal/util/update/merge3/merge3_util_test.go
internal/util/update/merge3/merge3.go
internal/util/update/merge3/MergeTestResources.go
internal/util/update/merge3/resource_matcher.go
internal/util/update/merge3/schema.go
internal/util/update/merge3/strategy_test.go
internal/util/update/merge3/strategy.go
internal/util/update/merge3/testdata/infer-crd-empty-dest/destination.yaml
internal/util/update/merge3/testdata/infer-crd-empty-dest/original.yaml
internal/util/update/merge3/testdata/infer-crd-empty-dest/updated.yaml
internal/util/update/merge3/testdata/infer-crd-empty-orig/destination.yaml
internal/util/update/merge3/testdata/infer-crd-empty-orig/original.yaml
internal/util/update/merge3/testdata/infer-crd-empty-orig/updated.yaml
internal/util/update/merge3/testdata/infer-crd-empty-updated/destination.yaml
internal/util/update/merge3/testdata/infer-crd-empty-updated/original.yaml
internal/util/update/merge3/testdata/infer-crd-empty-updated/updated.yaml
internal/util/update/merge3/testdata/infer-crd/destination.yaml
internal/util/update/merge3/testdata/infer-crd/original.yaml
internal/util/update/merge3/testdata/infer-crd/updated.yaml
internal/util/update/merge3/testdata/one-key-crd-empty-dest/destination.yaml
internal/util/update/merge3/testdata/one-key-crd-empty-dest/fruitstore.crd.yaml
internal/util/update/merge3/testdata/one-key-crd-empty-dest/original.yaml
internal/util/update/merge3/testdata/one-key-crd-empty-dest/updated.yaml
internal/util/update/merge3/testdata/one-key-crd-empty-orig/destination.yaml
internal/util/update/merge3/testdata/one-key-crd-empty-orig/fruitstore.crd.yaml
internal/util/update/merge3/testdata/one-key-crd-empty-orig/original.yaml
internal/util/update/merge3/testdata/one-key-crd-empty-orig/updated.yaml
internal/util/update/merge3/testdata/one-key-crd-empty-updated/destination.yaml
internal/util/update/merge3/testdata/one-key-crd-empty-updated/fruitstore.crd.yaml
internal/util/update/merge3/testdata/one-key-crd-empty-updated/original.yaml
internal/util/update/merge3/testdata/one-key-crd-empty-updated/updated.yaml
internal/util/update/merge3/testdata/one-key-crd/destination.yaml
internal/util/update/merge3/testdata/one-key-crd/fruitstore.crd.yaml
internal/util/update/merge3/testdata/one-key-crd/original.yaml
internal/util/update/merge3/testdata/one-key-crd/updated.yaml
internal/util/update/merge3/testdata/simple-conflict/destination.yaml
internal/util/update/merge3/testdata/simple-conflict/original.yaml
internal/util/update/merge3/testdata/simple-conflict/updated.yaml
internal/util/update/merge3/testdata/simple-subpackage-conflict/destination.yaml
internal/util/update/merge3/testdata/simple-subpackage-conflict/original.yaml
internal/util/update/merge3/testdata/simple-subpackage-conflict/updated.yaml
internal/util/update/merge3/tuple.go

Remove missed Porch reference from alpha commands

When the Porch commands (kpt alpha rpkg) was removed, a reference to the porch packagewas missed in commands/alpha/alphacmd.go, the reference is removed in this PR

Change in file:

commands/alpha/alphacmd.go

Remove KRM function suggestion that uses Porch

Kpt had a KRM function search/suggestion feature on kpt fn doc that returned a list of KRM functions that matched the KRM function string entered by the user.
This suggestion feature relies on searches of the Porch KRM function repositories. Porch has removed support for KRM function repositories.

This PR removes the references to the Porch function search support that no longer works. This functionality also made kpt dependent on
Porch, that dependency is gone

Modified file:

commands/fn/doc/cmdfndoc.go
pkg/lib/util/cmdutil/cmdutil_test.go
pkg/lib/util/cmdutil/cmdutil.go
thirdparty/cmdconfig/commands/cmdeval/cmdeval_test.go
thirdparty/cmdconfig/commands/cmdeval/cmdeval.go

Removed files:

pkg/lib/cmdutil/util.go
internal/util/function/catalogfn.go
internal/util/function/matcher.go
internal/util/porch/approval.go
internal/util/porch/client.go
internal/util/porch/function.go
internal/util/porch/name.go

Move builtin KRM functions back into the "intenal" directory and just expose the Package Context generator over an interface

In kpt, there is a directory internal/builtins that contains builtin KRM functions. Today there is only only one builtin KRM function, the Package Context generator.
Rather than exposing all builtin functions, this PR puts the buitlin functions back under the "internal" directory. It exposes a "builtin" interface in "pkg/lib/builtin" where
a user can look up and get a reference to a builtin function without kpt having to expose the entire builtin function implementation.

New interface to look up and get a handle on builtin functions

Instead of having to explicitly call a builtin function, a user can now use the GetBuiltinFn function in pkg/lib/builtins to get
an implementation of a builtin function that implements the BuiltinFunction interface defined in pkg/lib/builtins/builtintypes.
This means that the implementation of the builtin functions no longer needs to be exposed and can be moved back from pkg/lib/builtins to
interna/buiultins.

The data declarations below are moved from internal/builtins/pkg_context.go to pkg/lib/builtins/builtintypes/builtintypes.go because
users of the interface need access to those types:

const (
	PkgContextFile = "package-context.yaml"
	PkgContextName = "kptfile.kpt.dev"

	ConfigKeyPackagePath = "package-path"
)
type PackageConfig struct {
	// PackagePath is the path to the package, as determined by the names of the parent packages.
	// The path to a package is the parent package path joined with the package name.
	PackagePath string
}

New files to expose the types and interface:

pkg/lib/builtins/builtins.go
pkg/lib/builtins/builtins_test.go
pkg/lib/builtins/builtintypes/builtintypes.go

Moved from pkg/lib/builtins to internal/builtins

These files are moved back into internal/builtins so that theya re not exposed:

internal/builtins/pkg_context.go
internal/builtins/pkg_context_test.go
internal/builtins/testdata/pkg-with-existing-ctx/in.yaml
internal/builtins/testdata/pkg-with-existing-ctx/out.yaml
internal/builtins/testdata/pkg-with-nesting/in.yaml
internal/builtins/testdata/pkg-with-nesting/out.yaml
internal/builtins/testdata/pkg-wo-nesting/in.yaml
internal/builtins/testdata/pkg-wo-nesting/out.yaml

Move fnruntime back into "internal" so it is not externally exposed

We don not have to expose the function runtime in internal/fnruntime in order for external users to use the functionruntime. We just
have to expose the funciton runner options and the image pull policy. The following new files are added to provide
the runtime options and image pull policy on the kpt lib:

The following types and functions were extracacted from internal/fnruntime into pkg/lib/runneroptions because
users of the function runtime need access to them to use the function runtime

  • Move the FunctionRuntime interface from Porch to pkg/lib/kptops/fnruntime.go
  • ImagePullPolicy.go stays in pkg/lib/runneroptions as the pull policy must be exposed to users
  • The function fnruntime.ResolveToImageForCLIFunc() is moved from internal/fnruntime/container.go to pkg/lib/runneroptions.go
  • The constants FuncGenPkgContext and GHCRImagePrefix are moved from internal/fnruntime/runner.go to pkg/lib/runneroptions.go
  • The type ImageResolveFunc is moved from internal/fnruntime/runner.go to pkg/lib/runneroptions.go
  • The structs RunnerOptions and SingleLineFormatter are moved from internal/fnruntime/runner.go to pkg/lib/runneroptions.go
  • The function InitDefaults is moved from internal/fnruntime/runner.go to pkg/lib/runneroptions.go

New files for the extracted parts of fnruntime:

pkg/lib/kptops/fnruntime.go
pkg/lib/runneroptions/imagepullpolicy.go
pkg/lib/runneroptions/imagepullpolicy.go
pkg/lib/runneroptions/runneroptions.go

Move the following files from pkg/lib/fnruntime back to internal/fnruntime

internal/fnruntime/container_test.go
internal/fnruntime/container.go
internal/fnruntime/exec.go
internal/fnruntime/fnerrors_test.go
internal/fnruntime/imagepullpolicy.go
internal/fnruntime/jsglue.go
internal/fnruntime/nodejs.go
internal/fnruntime/runner.go
internal/fnruntime/utils_test.go
internal/fnruntime/wasm.go
internal/fnruntime/wasmtime_unsupported.go
internal/fnruntime/wasmtime.go

Port Porch Breadth First Rendering across to kpt

Porch supports breadth first rendering of kpt files if the annotation "kpt.dev/bfs-rendering" is set to "true".

Move porch internal/kpt/util/render code to `internal/util/render'

Files changed:

internal/util/render/executor_test.go
internal/util/render/executor.go

Add an interface for updaters

This PR adds an interface in pkg/lib/update so that updaters in in internal/util/update do not have
to be directly exposed to users. Users can use the 'pkg/lib/update' interface to get an implementation of an updater.

The Updater type is moved from internal/util/update/update.go to pkg/lib/update/updatetypes/updatetypes.go.

The Update interface and types is moved from Porch to kpt. The files that publish the interface are:

pkg/lib/update/update.go
pkg/lib/update/updatetypes/updatetypes.go

Files updated to specify an implementation of the updatetypes/updater interface:

internal/util/update/copy-merge.go
internal/util/update/fastforward.go
internal/util/update/replace.go
internal/util/update/resource-merge.go

Bug fixes and improvements ported from Porch

Update of the root kpt file on "replace" updates:

internal/util/update/replace.go

Fixes to the "resource-merge" strategy:

internal/util/update/resource-merge.go

GetUpdater function ported from Porch:

internal/util/update/update.go

Support for running tests on MacOS:

pkg/test/runner/runner.go
pkg/test/runner/util.go

Move files from pkg/lib/ to internal/ that no longer need to be exported

pkg/lib/gitutil/errors.go -> internal/gitutil/errors.go
pkg/lib/gitutil/gitutil.go -> internal/gitutil/gitutil.go
pkg/lib/types/types.go -> internal/types/types.go

Move utility functions from internal/ to pkg/lib/ that need to be exported

internal/util/addmergecomment/addmergecomment_test.go -> pkg/lib/util/addmergecomment/addmergecomment_test.go
internal/util/addmergecomment/addmergecomment.go -> pkg/lib/util/addmergecomment/addmergecomment.go
internal/util/cfgflags/useragent_test.go -> pkg/lib/util/cfgflags/useragent_test.go
internal/util/cfgflags/useragent.go -> pkg/lib/util/cfgflags/useragent.go
internal/util/parse/parse_test.go -> pkg/lib/util/parse/parse_test.go

Go files

go.mod
go.sum

Makefile changes

Removed the defunct test-live-plan target from the Makefile, "kpt live plan" is no longer supported

Tweaks to E2E test data

e2e/testdata/fn-render/basicpipeline-symlink/.expected/config.yaml
e2e/testdata/fn-render/exec-function-stderr/.expected/config.yaml
e2e/testdata/fn-render/out-of-place-fnchain-stdout-results/.expected/config.yaml
e2e/testdata/fn-render/out-of-place-fnchain-stdout/.expected/config.yaml
e2e/testdata/fn-render/selectors/basicpipeline/.expected/config.yaml
e2e/testdata/fn-render/selectors/exclude/.expected/config.yaml
e2e/testdata/fn-render/selectors/generator/.expected/config.yaml
e2e/testdata/fn-render/selectors/selectors-with-exclude/.expected/config.yaml

Import path changes only

The imports on these files were changed due to restucturing in other parts of the code.

commands/fn/render/cmdrender.go
commands/live/apply/cmdapply.go
commands/live/init/cmdliveinit.go
commands/live/migrate/migratecmd.go
commands/pkg/diff/cmddiff.go
commands/pkg/get/cmdget.go
commands/pkg/init/cmdinit_test.go
commands/pkg/init/cmdinit.go
commands/pkg/update/cmdupdate_test.go
commands/pkg/update/cmdupdate.go
commands/util/factory.go
internal/fnruntime/fnerrors.go
internal/fnruntime/runner_test.go
internal/fnruntime/utils.go
internal/gitutil/gitutil_test.go
internal/hook/executor.go
internal/pkg/pkg.go
internal/testutil/setup_manager.go
internal/testutil/testutil.go
internal/util/diff/diff.go
internal/util/fetch/fetch.go
internal/util/get/get.go
internal/util/update/common.go
internal/util/update/copy-merge_test.go
internal/util/update/fastforward_test.go
internal/util/update/replace_test.go
internal/util/update/resource-merge_test.go
internal/util/update/update_test.go
main.go
pkg/api/kptfile/v1/validation_test.go
pkg/api/kptfile/v1/validation.go
pkg/fn/eval_test.go
pkg/fn/eval.go
pkg/fn/multiruntime.go
pkg/kptfile/kptfileutil/util.go
pkg/kptpkg/init.go
pkg/lib/errors/errors_test.go
pkg/lib/errors/errors.go
pkg/lib/errors/resolver/container.go
pkg/lib/errors/resolver/git.go
pkg/lib/errors/resolver/live.go
pkg/lib/errors/resolver/pkg.go
pkg/lib/errors/resolver/update.go
pkg/lib/util/cmdutil/get.go
pkg/lib/util/parse/parse.go
pkg/printer/printer_test.go
pkg/printer/printer.go
pkg/test/runner/config.go
run/run.go
thirdparty/cmdconfig/commands/cmdsink/cmdsink.go
thirdparty/cmdconfig/commands/cmdsource/cmdsource.go
thirdparty/kyaml/runfn/runfn.go
e2e/fn_test.go

Code volume changes

Before refactor

kpt codebase (kpt repo)

-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Go                             265           5916           7098          47997
YAML                           464            479           4733          18750
Markdown                       112           3274            238          11333
SVG                             55            868           5039           4580
Bourne Shell                    66            585           1615           3064
diff                            59              0           1101           1482
SCSS                            19            141             69           1292
HTML                            32             52             87            657
JSON                             4              0              0            606
make                             4            100            117            317
TOML                             2             45             64             98
JavaScript                       4             21             46             89
XML                              4              0              0             44
Text                             4              4              0             32
Dockerfile                       2              7             39             24
Ruby                             1              4             13             14
CSS                              1             13              0             13
INI                              1              3              0             13
Python                           1              1             13              1
-------------------------------------------------------------------------------
SUM:                          1100          11513          20272          90406
-------------------------------------------------------------------------------

Porch codebase (porch repo):

-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Go                            1494          40594          48610         289614
YAML                           199            242           1174          16380
Markdown                       120           3088              8          10279
Bourne Shell                    32            453            531           2070
JSON                            14              2              0            567
make                            16            133            236            484
HTML                             7             28             22            328
Text                             8             34              0            296
SQL                              4             43             50            185
Protocol Buffers                 5            132            382            162
Dockerfile                       7             48            100            128
TOML                             2             86             84             90
SVG                             20              0             15             64
INI                              2              9              0             34
Properties                       1              4              6             11
JavaScript                       1              2              0              5
SCSS                             2              0              0              3
Python                           1              1             13              1
-------------------------------------------------------------------------------
SUM:                          1935          44899          51231         320701
-------------------------------------------------------------------------------

After refactor:

kpt codebase (kpt repo)

-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Go                             285           6278           7514          49700
YAML                           480            474           4773          19256
Markdown                       112           3274            238          11333
SVG                             55            868           5039           4580
Bourne Shell                    66            585           1615           3064
diff                            59              0           1101           1482
SCSS                            19            141             69           1292
HTML                            32             52             87            657
JSON                             4              0              0            606
make                             4             99            116            315
Text                             6              4              0            182
TOML                             2             45             64             98
JavaScript                       4             21             46             89
XML                              4              0              0             44
Dockerfile                       2              7             39             24
Ruby                             1              4             13             14
CSS                              1             13              0             13
INI                              1              3              0             13
Python                           1              1             13              1
-------------------------------------------------------------------------------
SUM:                          1138          11869          20727          92763
-------------------------------------------------------------------------------

Porch codebase (porch repo):

-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Go                            1386          38222          45267         266666
YAML                           158            214            747          14724
Markdown                       120           3088              8          10279
Bourne Shell                    32            453            531           2070
JSON                            14              2              0            567
make                            16            133            236            484
HTML                             7             28             22            328
SQL                              4             43             50            185
Protocol Buffers                 5            132            382            162
Text                             4             34              0            144
Dockerfile                       7             48            100            128
TOML                             2             86             84             90
SVG                             20              0             15             64
INI                              2              9              0             34
Properties                       1              4              6             11
JavaScript                       1              2              0              5
SCSS                             2              0              0              3
-------------------------------------------------------------------------------
SUM:                          1781          42498          47448         295944
-------------------------------------------------------------------------------

@netlify
Copy link

netlify bot commented Jan 20, 2026

Deploy Preview for kptdocs ready!

Name Link
🔨 Latest commit bc1d07f
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/69837d13e86f0e0008e7942a
😎 Deploy Preview https://deploy-preview-4355--kptdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@liamfallon liamfallon added cleanup triaged Issue has been triaged by adding an `area/` label do-not-merge-work-in-progress Work in progress, do not merge labels Jan 20, 2026
@liamfallon liamfallon self-assigned this Jan 21, 2026
@liamfallon liamfallon removed the do-not-merge-work-in-progress Work in progress, do not merge label Jan 21, 2026
@liamfallon liamfallon removed the triaged Issue has been triaged by adding an `area/` label label Jan 28, 2026
Signed-off-by: liamfallon <liam.fallon@est.tech>
Signed-off-by: liamfallon <liam.fallon@est.tech>
Signed-off-by: liamfallon <liam.fallon@est.tech>
Signed-off-by: liamfallon <liam.fallon@est.tech>
Signed-off-by: liamfallon <liam.fallon@est.tech>
Signed-off-by: liamfallon <liam.fallon@est.tech>
Signed-off-by: liamfallon <liam.fallon@est.tech>
Signed-off-by: liamfallon <liam.fallon@est.tech>
Signed-off-by: liamfallon <liam.fallon@est.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transfer the remaining Porch improvements from Porch to kpt Resolve kpt dependency on porch EPIC: Align the kpt pipeline execution in kpt and Porch

1 participant