Skip to content

Extract the kpt CLI into it's own go module - #4811

Open
mozesl-nokia wants to merge 26 commits into
kptdev:mainfrom
nokia:cli-mod
Open

mozesl-nokia wants to merge 26 commits into
kptdev:mainfrom
nokia:cli-mod

Conversation

@mozesl-nokia

@mozesl-nokia mozesl-nokia commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Exactly as the title says, moved all the CLI related code into it's own module in cli/, leaving the main "library" part as the root module.

Had to do some auxiliary moving around to avoid weird circular and cross-dependencies. Renamed commands/ to cli/. All of the make targets and workflows should be working. I also redid the api make targets to match Porch and the new cli ones.

Related to #4647 and closes #4554

Obsoletes #4739 by moving all of the third-party code into their respective folders.

For reviewers: You can go through commit-by-commit to avoid big diffs as I tried to logically separate the migration steps as much as possible.

I have used AI in the PR:

  • Cursor Grok 4.7 for debugging why the ldflags -X flag was not working correctly; and then later to restructure the release actions and makefiles
  • Cursor Composer 2.5 for verifying the release workflows
  • Claude Haiku 4.5 for finding more workflow issues and replacing the shlex dependency

Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Assisted-by: Cursor:grok-4.7
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Assisted-by: Cursor:composer-2.5
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Assisted-by: Cursor:claude-haiku-4.5
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
@mozesl-nokia
mozesl-nokia requested review from a team and a balanced review from Copilot October 15, 2026 13:13
@mozesl-nokia mozesl-nokia added area/pkg area/live dependencies Pull requests that update a dependency file area/fn-runtime KRM function runtime go Pull requests that update Go code labels Oct 15, 2026
@netlify

netlify Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for kptdocs ready!

Name Link
🔨 Latest commit b9f00c7
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/6ada0426fad22fd5f3b666b4
😎 Deploy Preview https://deploy-preview-4811--kptdocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Module wiring, build and validation targets, and omitted CLI test execution leave significant integration failures unresolved.

5 open findings
What changed in this PR

Separates kpt’s CLI from its reusable library, supporting #4647, and absorbs third-party code into its owning packages for #4554.

Changes:

  • Moves commands, entry points, tests, and fixtures into the new cli module.
  • Moves shared inventory errors into the library and updates imports.
  • Updates Make targets, release builds, and CI paths.
File Description
thirdparty/​README.md Removes obsolete third-party directory documentation.
release/​tag/​goreleaser.yaml Builds CLI with updated version metadata.
pkg/​lib/​errors/​resolver/​live.go Resolves library-owned inventory errors.
pkg/​lib/​errors/​inventory.go Defines shared inventory errors.
Makefile Delegates module tasks and adds workspace targets.
make/​info.mk Updates version linker symbol.
make/​cli.mk Adds CLI task wrappers.
make/​api.mk Extracts API task wrappers.
go.sum Removes unused dependency checksums.
go.mod Adjusts library dependencies.
cli/​util/​factory.go Relocates Kubernetes client factory.
cli/​util/​common.go Relocates CLI constants.
cli/​run.go Moves command setup into main package.
cli/​run_test.go Updates command setup test package.
cli/​pkg/​update/​cmdupdate.go Relocates package update command.
cli/​pkg/​update/​cmdupdate_test.go Updates CLI imports.
cli/​pkg/​pkgcmd.go Updates package command registration imports.
cli/​pkg/​init/​cmdinit.go Relocates package initialization command.
cli/​pkg/​init/​cmdinit_test.go Updates CLI import.
cli/​pkg/​get/​cmdget.go Relocates package retrieval command.
cli/​pkg/​get/​cmdget_test.go Updates CLI import.
cli/​pkg/​diff/​cmddiff.go Relocates package diff command.
cli/​pkg/​diff/​cmddiff_test.go Updates CLI imports.
cli/​pkg/​cmdtree/​tree.go Simplifies relocated tree field assembly.
cli/​pkg/​cmdtree/​cmdtree.go Uses relocated command helpers.
cli/​pkg/​cmdtree/​cmdtree_test.go Relocates tree command tests.
cli/​pkg/​cmdsource/​cmdsource.go Uses relocated error handler.
cli/​pkg/​cmdsource/​cmdsource_test.go Relocates source command tests.
cli/​pkg/​cmdcat/​runner.go Consolidates helpers into cmdcat.
cli/​pkg/​cmdcat/​runner_test.go Updates helper test package.
cli/​pkg/​cmdcat/​cmdcat.go Uses consolidated local helpers.
cli/​Makefile Adds CLI module tasks.
cli/​main.go Relocates entry point and generation paths.
cli/​live/​status/​fake-loader.go Relocates fake inventory loader.
cli/​live/​status/​cmdstatus.go Relocates status command.
cli/​live/​status/​cmdstatus_test.go Relocates status tests.
cli/​live/​migrate/​migratecmd.go Updates imports and inventory error reference.
cli/​live/​migrate/​migratecmd_test.go Relocates migration tests.
cli/​live/​livecmd.go Updates live command imports.
cli/​live/​installrg/​cmdinstallrg.go Relocates ResourceGroup installation command.
cli/​live/​init/​cmdliveinit.go Uses shared inventory errors.
cli/​live/​init/​cmdliveinit_test.go Relocates initialization tests.
cli/​live/​destroy/​cmddestroy.go Relocates destroy command.
cli/​live/​destroy/​cmddestroy_test.go Relocates destroy tests.
cli/​live/​apply/​cmdapply.go Relocates apply command.
cli/​live/​apply/​cmdapply_test.go Relocates apply tests.
cli/​k8s.go Adds adapted Kubernetes command execution helpers.
cli/​go.mod Defines independent CLI module dependencies.
cli/​fn/​render/​cmdrender.go Relocates render command.
cli/​fn/​render/​cmdrender_test.go Relocates render tests.
cli/​fn/​fncmd.go Updates function command imports.
cli/​fn/​doc/​cmdfndoc.go Relocates function documentation command.
cli/​fn/​doc/​cmdfndoc_test.go Updates CLI import.
cli/​fn/​cmdsink/​cmdsink.go Relocates sink command.
cli/​fn/​cmdsink/​cmdsink_test.go Relocates sink tests.
cli/​fn/​cmdeval/​test/​testdata/​java/​java-service.resource.yaml Relocates service fixture.
cli/​fn/​cmdeval/​test/​testdata/​java/​java-deployment.resource.yaml Relocates deployment fixture.
cli/​fn/​cmdeval/​test/​testdata/​java/​java-configmap.resource.yaml Relocates ConfigMap fixture.
cli/​fn/​cmdeval/​runfn.go Consolidates runner into cmdeval.
cli/​fn/​cmdeval/​runfn_test.go Updates runner test package.
cli/​fn/​cmdeval/​cmdeval.go Uses consolidated runner and relocated helpers.
cli/​fn/​cmdeval/​cmdeval_test.go Updates runner references.
cli/​commands.go Moves command registration into main package.
cli/​alpha/​wasm/​wasmcmd.go Updates WASM command imports.
cli/​alpha/​wasm/​push/​command.go Relocates WASM push command.
cli/​alpha/​wasm/​pull/​command.go Relocates WASM pull command.
cli/​alpha/​live/​plan/​diff.go Relocates plan diff helpers.
cli/​alpha/​live/​plan/​command.go Relocates plan command.
cli/​alpha/​live/​plan/​command_test.go Relocates plan tests.
cli/​alpha/​live/​livecmd.go Updates alpha live imports.
cli/​alpha/​alphacmd.go Updates alpha command imports.
.github/​workflows/​release.yml Uses CLI Go version and checks replacements.
.github/​workflows/​go.yml Updates changed-code path filters.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Makefile
Comment thread cli/Makefile Outdated
Comment thread cli/go.mod
Comment thread .github/workflows/go.yml
Comment thread Makefile Outdated
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Assisted-by: Cursor:claude-haiku-4.5
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The CLI module blocks release and versioned installation, and command parsing and plan output have unresolved correctness issues.

2 open findings
5 resolved since last review

🧠 Review effort: Lite

Comment thread cli/go.mod
Comment thread pkg/lib/util/shlex/shlex.go Outdated
Assisted-by: Cursor:grok-4.7
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Live E2E filters miss relocated commands, and dependency-at-HEAD builds ignore their overrides.

0 open findings

2 resolved since last review
Previously missed (2)

In code that hasn't changed since last review

Medium severity Update E2E path filters for relocated CLI files

.github/​workflows/​go.yml:44

The live E2E filters in .github/workflows/live-e2e.yml:43-44 and .github/workflows/e2eEnvironment.yml:43-44 still match commands/live/** and commands/pkg/**. After this move, changes confined to cli/live/** or cli/pkg/** skip both cluster test suites while their gates report success. Update both filters to the relocated paths and include cli/go.mod and cli/go.sum so CLI dependency changes also trigger validation.

Medium severity Apply build dependency replacements in cli/go.mod

e2e/​live/​end-to-end-test.sh:202

With -b, lines 195–197 still append the dependency replacements to the root go.mod, but this build now uses cli/go.mod as the main module. Go ignores replacements in dependency modules, so the cloned cli-utils and kyaml HEAD checkouts are not used despite the success message. Write the replacements into cli/go.mod and adjust their relative paths for the extra directory level.

🧠 Review effort: Balanced

Assisted-by: Cursor:grok-4.7
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Assisted-by: Cursor:grok-4.7
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical CLI release and KRM output issues remain, along with workflow and module-integration gaps.

1 open finding
Previously missed (1)

In code that hasn't changed since last review

Medium severity Make the go workspace setup command idempotent

Makefile:140

work is phony, so every repeated make work runs go work init again. go work init fails when go.work already exists, making the documented setup command non-idempotent; use go work use for an existing workspace or guard the init.

🧠 Review effort: Lite

Comment thread .github/workflows/release-cli.yml
Assisted-by: Cursor:grok-4.7
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
@aravindtga
aravindtga requested review from a team October 22, 2026 08:39

@aravindtga aravindtga left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Homebrew formula will break with this split (external follow-up needed).

The homebrew-core formula (Formula/k/kpt.rb (https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/k/kpt.rb)) builds from the source tarball at the repo root and injects -X github.com/kptdev/kpt/run.version.

It needs a coordinated homebrew-core PR to build the cli/ submodule, switch ldflags to -X main.version, and teach livecheck the cli/v* stream. Flagging so it isn't missed. likely belongs with the release-automation work in #4827.

Comment thread documentation/content/en/installation/kpt-cli.md Outdated
Comment thread release/tag/goreleaser.yaml Outdated
Comment thread release/tag/goreleaser.yaml Outdated
Comment thread .github/workflows/release-cli.yml Outdated
Comment thread .github/workflows/release-cli.yml Outdated
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
@mozesl-nokia

Copy link
Copy Markdown
Contributor Author

@aravindtga Not familiar with homebrew, but I think it can be done any time before the next release.

@aravindtga

Copy link
Copy Markdown
Contributor

@aravindtga Not familiar with homebrew, but I think it can be done any time before the next release.

Yes. It is a pre-requisite to the release after the merge of this PR.

goarch:
- amd64
ldflags: -s -w -X github.com/kptdev/kpt/run.version={{.Version}} -X github.com/kptdev/kpt/run.gitCommit={{.FullCommit}} -extldflags "-z noexecstack"
ldflags: -s -w -X main.version={{ trimprefix (base .Tag) "v" }} -X main.gitCommit={{.FullCommit}} -X main.gitCommit={{.FullCommit}} -extldflags "-z noexecstack"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ldflags: -s -w -X main.version={{ trimprefix (base .Tag) "v" }} -X main.gitCommit={{.FullCommit}} -X main.gitCommit={{.FullCommit}} -extldflags "-z noexecstack"
ldflags: -s -w -X main.version={{ trimprefix (base .Tag) "v" }} -X main.gitCommit={{.FullCommit}} -extldflags "-z noexecstack"

goarch:
- arm64
ldflags: -s -w -X github.com/kptdev/kpt/run.version={{.Version}} -X github.com/kptdev/kpt/run.gitCommit={{.FullCommit}} -extldflags "-z noexecstack"
ldflags: -s -w -X main.version={{ trimprefix (base .Tag) "v" }} -X main.gitCommit={{.FullCommit}} -X main.gitCommit={{.FullCommit}} -extldflags "-z noexecstack"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ldflags: -s -w -X main.version={{ trimprefix (base .Tag) "v" }} -X main.gitCommit={{.FullCommit}} -X main.gitCommit={{.FullCommit}} -extldflags "-z noexecstack"
ldflags: -s -w -X main.version={{ trimprefix (base .Tag) "v" }} -X main.gitCommit={{.FullCommit}} -extldflags "-z noexecstack"

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/fn-runtime KRM function runtime area/live area/pkg cleanup dependencies Pull requests that update a dependency file go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need to refactor / remove the "thirdparty" folder - refer to upstream or absorb

4 participants