Error when explicit destination of pkg get already exists - #4696
Error when explicit destination of pkg get already exists#4696gangadhar-res wants to merge 1 commit into
Conversation
✅ Deploy Preview for kptdocs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
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.
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>
dd6159c to
db01bbd
Compare
|
Hello CODEOWNERs @liamfallon @kispaljr @mozesl-nokia @efiacor Could one of your review and merge this code change ? |
|
@efiacor @mozesl-nokia this has an lgtm from @aravindtga and CI is green. Could one of you take a look when you get a chance? It errors when an explicit pkg get destination already contains a package, instead of silently nesting a second copy inside it. |
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.