Skip to content

Error when explicit destination of pkg get already exists - #4696

Open
gangadhar-res wants to merge 1 commit into
kptdev:mainfrom
gangadhar-res:fix/pkg-get-explicit-dest-exists
Open

Error when explicit destination of pkg get already exists#4696
gangadhar-res wants to merge 1 commit into
kptdev:mainfrom
gangadhar-res:fix/pkg-get-explicit-dest-exists

Conversation

@gangadhar-res

Copy link
Copy Markdown

Fixes #2656

Problem: running kpt pkg get REPO_URI DEST a second time silently fetched the package into DEST/ instead of erroring. getDest() always defaulted to a repo-named subdirectory when the destination existed, even when the user explicitly named it.

Fix: when the destination was explicitly provided, already exists, and is not ., return the same "destination directory already exists" error the defaulted path produces. The . special case and the defaulting behavior for omitted destinations are unchanged.

Validation: ran the reproduction steps from the issue against this branch — first run fetches into packages/newDirName, second run now errors with destination directory "packages/newDirName" already exists, and no nested nginx/ directory is created. kpt pkg get with no destination still defaults to ./nginx. Added a Test_getDest table test covering explicit/defaulted/existing/./file/missing-parent cases.

@gangadhar-res
gangadhar-res requested review from a team August 12, 2026 23:46
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 12, 2026
@netlify

netlify Bot commented Aug 12, 2026

Copy link
Copy Markdown

Deploy Preview for kptdocs ready!

Name Link
🔨 Latest commit db01bbd
🔍 Latest deploy log https://app.netlify.com/projects/kptdocs/deploys/6a7d9e6362db550008a60961
😎 Deploy Preview https://deploy-preview-4696--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.

@dosubot dosubot Bot added the bug Something isn't working label Aug 12, 2026
@aravindtga
aravindtga requested a balanced review from Copilot August 13, 2026 10:04

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.

Pull request overview

Fixes repeated kpt pkg get calls incorrectly creating nested packages.

Changes:

  • Rejects explicitly provided destinations that already exist.
  • Adds unit coverage for destination resolution scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/lib/util/parse/parse.go Adds explicit-destination validation.
pkg/lib/util/parse/parse_test.go Tests destination handling and errors.

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

Comment thread pkg/lib/util/parse/parse.go Outdated
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Aug 13, 2026
A repeated `kpt pkg get REPO_URI DEST` silently fetched the package
into a nested subdirectory (DEST/<pkg-name>): getDest always defaulted
to a repo-named subdirectory when the destination existed, even when
the user explicitly named the directory that the first run created.

Reject an explicitly named destination only when it already contains a
Kptfile, which is exactly the repeated-fetch case. Existing directories
without a Kptfile keep working as containers to fetch into
(DEST/<pkg-name>), the '.' special case is unchanged, and omitted
destinations keep the defaulting behavior, so no existing tests change.

Fixes kptdev#2656

Signed-off-by: Gangadhar Chalapaka <gangadhar@resolve.ai>
@gangadhar-res
gangadhar-res force-pushed the fix/pkg-get-explicit-dest-exists branch from dd6159c to db01bbd Compare August 13, 2026 10:37
Comment thread pkg/lib/util/parse/parse.go
@gangadhar-res

gangadhar-res commented Aug 17, 2026

Copy link
Copy Markdown
Author

Hello CODEOWNERs

@liamfallon @kispaljr @mozesl-nokia @efiacor

Could one of your review and merge this code change ?

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

Labels

bug Something isn't working lgtm size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kpt pkg get duplicates a package as a subdirectory when attempting to override the local directory name

3 participants