feat: Auto-create package directory in kpt pkg init#4405
feat: Auto-create package directory in kpt pkg init#4405liamfallon merged 2 commits intokptdev:mainfrom
Conversation
- Automatically create package directory if it doesn't exist - Update test to verify auto-creation behavior - Add user-friendly message when creating directory Fixes kptdev#1835 Signed-off-by: Surbhi <agarwalsurbhi1807@gmail.com>
✅ Deploy Preview for kptdocs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Documentation Updates 7 document(s) were updated by changes in this PR: _indexView Changes@@ -188,7 +188,7 @@

-- **Create**: Initialize a directory using `kpt pkg init`.
+- **Create**: Initialize a package using `kpt pkg init`. The command creates the directory if it doesn't exist.
Now, let's say you have rendered the package, and want to deploy it to a cluster. The workflow
may look like this:_indexView Changes@@ -34,9 +34,8 @@
Create a new kpt package:
```shell
-mkdir my-pkg
+kpt pkg init my-pkg
cd my-pkg
-kpt pkg init
```
Configure a local `ConfigMap`:_indexView Changes@@ -110,9 +110,8 @@
Create a new kpt package:
```shell
-mkdir my-pkg
+kpt pkg init my-pkg
cd my-pkg
-kpt pkg init
```
Configure two pods, with one that depends on the other:_indexView Changes@@ -281,8 +281,8 @@
This section highlights practices that commonly lead to CI failures, drift, or unintended cluster changes. Avoid the
following:
-- Running `kpt pkg init` in CI. Packages and `Kptfile` metadata should be authored by developers, not created during
- CI runs.
+- Running `kpt pkg init` in CI to create package metadata. The `Kptfile` and package structure should be authored by developers
+ and committed to Git, not generated during CI runs.
- Mutating packages in CI. CI should validate and render the declared intent, not change the source of truth.
- Storing secrets in configuration. Secrets must not appear in YAML files, the `Kptfile`, or `functionConfig`.
- Applying on pull requests. PRs should validate only; deployment belongs in gated, mainline workflows._indexView Changes@@ -314,13 +314,13 @@
```
## Creating a package
-Creating a new package is simple. Use the `pkg init` command to create a package directory with a minimal `Kptfile` and `README` files:
+Creating a new package is simple. Use the `pkg init` command to initialize a directory as a kpt package with a minimal `Kptfile` and `README` files:
```shell
kpt pkg init awesomeapp
```
-This will create the `awesomeapp` directory if it doesn't exist, and initialize it with the necessary files.
+The command will automatically create the `awesomeapp` directory if it doesn't exist, eliminating the need to manually create the directory beforehand.
Refer to the [init command reference](../../reference/cli/pkg/init/) for usage.
_indexView Changes@@ -35,9 +35,8 @@
Create a new kpt package:
```shell
-mkdir my-pkg
+kpt pkg init my-pkg
cd my-pkg
-kpt pkg init
```
Configure two pods, with one that depends on the other:namespace-provisioning-cliView Changes@@ -117,8 +117,9 @@
# You should be under the `./blueprint` git directory. If not, check the above
# section "Prerequisites | Repositories"
-# initialize the package (directory will be created automatically)
+# initialize the package (directory will be created automatically if it doesn't exist)
$ kpt pkg init basens --description "kpt package for provisioning namespace"
+creating package directory basens
writing basens/Kptfile
writing basens/README.md
writing basens/package-context.yaml |
Update description to reflect that pkg init now creates the directory automatically if it doesn't exist. Related to kptdev#1835 Signed-off-by: Surbhi <agarwalsurbhi1807@gmail.com>
|
Hi @kispaljr, @liamfallon, and @efiacor! This PR is ready for review and has:
The PR implements automatic package directory creation in Thank you! |
I think we should update the message as suggested in the dosubot comment above. |
|
Hello @liamfallon , I had updated the changes that you had suggested , is their any other changes ? |
Hi @SurbhiAgarwal1 , It's all good now. Thanks! |
Description
This PR enables
kpt pkg initto automatically create the package directory if it doesn't exist, eliminating the need for users to manually create directories before initializing packages.Motivation
Currently, users must create a directory before running
kpt pkg init, which adds an unnecessary manual step to the workflow. This change streamlines the package initialization process by automatically creating the directory when needed.Current workflow:
New workflow:
kpt pkg init my-package # Directory created automaticallyChanges
pkg/kptpkg/init.goto useMkdirAll()instead of returning an error when directory doesn't existcommands/pkg/init/cmdinit_test.goto verify auto-creation behaviorFeatures
kpt pkg init path/to/packageTesting
All tests pass including:
Fixes #1835