Repository navigation
feat(pkg): add --create-parents flag to kpt pkg get - #4854
Conversation
✅ Deploy Preview for kptdocs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the opt-in parent-directory creation change.
No open issues 🎉
What changed in this PR
Adds opt-in parent-directory creation to kpt pkg get, addressing #2824 while preserving the default error for missing parent directories.
Changes:
- Adds
--create-parents/-pand a hidden--parentsalias. - Allows nested destinations with missing parents when enabled.
- Adds parser and CLI flag tests and updates reference documentation and generated help.
| File | Description |
|---|---|
pkg/lib/util/parse/parse.go |
Threads the option through parsing and relaxes parent-directory validation when enabled. |
pkg/lib/util/parse/parse_test.go |
Tests missing-parent validation with the option enabled and disabled. |
internal/docs/generated/pkgdocs/docs.go |
Adds the flag to generated CLI help. |
documentation/content/en/reference/cli/pkg/get/_index.md |
Documents the flag and its default. |
cli/pkg/get/cmdget.go |
Registers the flags and passes the option to the parser. |
cli/pkg/get/cmdget_test.go |
Tests default rejection and acceptance with the long and shorthand flags. |
Review effort: Balanced
|
Thank you for the review, @aravindtga! Updated as requested:
|
|
What confused me on this PR was that I couldn't see where the parent directory is created in the new code so I pointed AI at the PR code. The AI solves the mystery (see below) and it recommends adding a unit test to prove parent directory creation. I agree with the AI. Please add a unit test to show path creation, preferably with a multi-directory parent like AI Generated Review The parent directories are created, but not by the code the PR adds. I ran the branch's CLI against a local repo, and it works: kpt pkg get -p file://…/repo.git /missing-parent/my-app created missing-parent/my-app and fetched the package. The unit test doesn't prove this. The create-parents case in cmdget_test.go runs with NoOpRunE, so it only checks argument parsing and never checks that the directory exists. A test that asserts the destination exists after a real fetch would cover the claim. |
|
Added execution unit tests in \cli/pkg/get/cmdget_test.go\ (\TestCmd_execute_createParents) verifying that both --create-parents\ and -p\ create multi-directory nested parent paths (such as \dir1/dir2/dir3) and fetch the package successfully into destination. Thanks @liamfallon! |
5144af4 to
042a19f
Compare
|
@Hrushikesh-ramilla CI is failing now, can you take a look please? |
Signed-off-by: hrushikeshramilla <ramillahrushikesh@gmail.com>
042a19f to
e3ae1ba
Compare
|
Rebased on upstream main and resolved the build failure by encapsulating parent creation within the CLI runner, keeping the library API signature unchanged. All tests are passing. |
|




Description
--create-parents/-pflag tokpt pkg getto automatically create parent directories if they do not exist when fetching a package to a nested destination path.kpt pkg get <REPO> ./apps/my-app/fails withparent directory "apps" does not existif the parent directory does not exist yet. Users had to manually create intermediate directories beforehand.--create-parents/-pflag (and--parentsalias) tokpt pkg get.pkg/lib/util/parse,getDestpermits destination paths with non-existent parents whencreateParentsis true.get.Command.Runusesos.MkdirAll, which creates all leading directories recursively.false, preserving the existing strict behavior unless explicitly enabled.Related Issue(s)
Type of Change
Checklist