-
Notifications
You must be signed in to change notification settings - Fork 36
Adding creating first package tutorial #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8d9730c
adding creating first package tutorial
Catalin-Stratulat-Ericsson 5e3c708
amended comments
Catalin-Stratulat-Ericsson 815aaef
reformating to PackageRevision
Catalin-Stratulat-Ericsson aca8880
changed alert color
Catalin-Stratulat-Ericsson 9402197
adding clarity to function rendering
Catalin-Stratulat-Ericsson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
357 changes: 357 additions & 0 deletions
357
content/en/docs/neo-porch/4_tutorials_and_how-tos/initializing-first-package.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,357 @@ | ||
| --- | ||
| title: "Creating Package Revisions" | ||
| type: docs | ||
| weight: 3 | ||
| description: "A step by step guide to creating a package revision in Porch" | ||
| --- | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Porch deployed on a Kubernetes cluster [Setup Porch Guide]({{% relref "/docs/neo-porch/3_getting_started/installing-porch.md" %}}). | ||
| - **Porchctl** CLI tool installed [Setup Porchctl Guide]({{% relref "/docs/neo-porch/3_getting_started/installing-porch.md" %}}). | ||
| - A Git repository registered with Porch [Setup Repositories Guide]({{% relref "/docs/neo-porch/4_tutorials_and_how-tos/setting-up-repositories.md" %}}). | ||
Catalin-Stratulat-Ericsson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - **Kubectl** configured to access your cluster. | ||
|
|
||
| ## Tutorial Overview | ||
|
|
||
| You will learn how to: | ||
|
|
||
| 1. Initialize a new package revision | ||
| 2. Pull the package revision locally | ||
| 3. Modify the package revision contents | ||
| 4. Push changes back to Porch | ||
| 5. Propose the package revision for review | ||
| 6. Approve or reject the package revision | ||
|
|
||
| {{% alert title="Understanding Terminology" color="primary" %}} | ||
| In Porch, you work with **PackageRevisions** - there is no separate "Package" resource. When we say "package" colloquially, we're referring to a PackageRevision. The `rpkg` command stands for "revision package". | ||
| {{% /alert %}} | ||
|
|
||
| --- | ||
|
|
||
| {{% alert title="Note" color="primary" %}} | ||
| Please note the tutorial assumes a porch repository is initialized with the "porch-test" name. | ||
| We recommended to use this for simpler copy pasting of commands otherwise replace any "porch-test" value with your repository's name in the below commands. | ||
| {{% /alert %}} | ||
|
|
||
| ## Step 1: Initialize Your First Package Revision | ||
|
|
||
| Create a new package revision in Porch using the `init` command: | ||
|
|
||
| ```bash | ||
| porchctl rpkg init my-first-package \ | ||
| --namespace=default \ | ||
| --repository=porch-test \ | ||
| --workspace=v1 \ | ||
| --description="My first Porch package" | ||
| ``` | ||
|
|
||
| **What this does:** | ||
|
|
||
| - Creates a new PackageRevision named `my-first-package` | ||
| - Places it in the `porch-test` repository | ||
| - Uses `v1` as the workspace name (must be unique within this package) | ||
| - Starts in `Draft` lifecycle state | ||
|
|
||
|  | ||
|
|
||
| **Verify the package revision was created:** | ||
|
|
||
| ```bash | ||
| porchctl rpkg get --namespace default | ||
| ``` | ||
|
|
||
| You should see your package revision listed with lifecycle `Draft`: | ||
|
|
||
| ```bash | ||
| NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY | ||
| porch-test.my-first-package.v1 my-first-package v1 0 false Draft porch-test | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Step 2: Pull the Package Revision Locally | ||
|
|
||
| Download the package revision contents to your local filesystem: | ||
|
|
||
| ```bash | ||
| porchctl rpkg pull porch-test.my-first-package.v1 ./my-first-package --namespace default | ||
| ``` | ||
|
|
||
| **What this does:** | ||
|
|
||
| - Fetches all resources from the PackageRevision | ||
| - Saves them to the `./my-first-package` directory | ||
| - Includes the Kptfile and any other resources | ||
|
|
||
|  | ||
|
|
||
| **Explore the package revision contents:** | ||
|
|
||
| ```bash | ||
| ls -al ./my-first-package | ||
| ``` | ||
|
|
||
| You'll see: | ||
|
|
||
| - The `Kptfile` - PackageRevision metadata and pipeline configuration | ||
| - Other YAML files (if any were created) | ||
|
|
||
| ```bash | ||
| total 24 | ||
| drwxr-x--- 2 user user 4096 Nov 24 13:27 . | ||
| drwxr-xr-x 4 user user 4096 Nov 24 13:27 .. | ||
| -rw-r--r-- 1 user user 259 Nov 24 13:27 .KptRevisionMetadata | ||
| -rw-r--r-- 1 user user 177 Nov 24 13:27 Kptfile | ||
| -rw-r--r-- 1 user user 488 Nov 24 13:27 README.md | ||
| -rw-r--r-- 1 user user 148 Nov 24 13:27 package-context.yaml | ||
| ``` | ||
|
|
||
| **Alternatively:** | ||
|
|
||
| If you have the tree command installed on your system you can use it to view the hierarchy of the package | ||
|
|
||
| ```bash | ||
| tree ./my-first-package/ | ||
| ``` | ||
|
|
||
| Should return the following output: | ||
|
|
||
| ```bash | ||
| my-first-package/ | ||
| ├── Kptfile | ||
| ├── README.md | ||
| └── package-context.yaml | ||
|
|
||
| 1 directory, 3 files | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Step 3: Modify the Package Revision | ||
|
|
||
| Let's add a simple KRM function to the pipeline. | ||
|
|
||
| Open the `Kptfile` in your editor of choice: | ||
|
|
||
| ```bash | ||
| vim ./my-first-package/Kptfile | ||
| ``` | ||
|
|
||
| Add a mutator function to the pipeline section so that your `Kptfile` looks like so: | ||
|
|
||
| ```yaml | ||
| apiVersion: kpt.dev/v1 | ||
| kind: Kptfile | ||
| metadata: | ||
| name: my-first-package | ||
| annotations: | ||
| config.kubernetes.io/local-config: "true" | ||
| info: | ||
| description: My first Porch package | ||
| pipeline: | ||
| mutators: | ||
| - image: gcr.io/kpt-fn/set-namespace:v0.4.1 | ||
| configMap: | ||
| namespace: production | ||
| ``` | ||
|
|
||
| **What this does:** | ||
|
|
||
| - Adds a `set-namespace` function to the pipeline | ||
| - This function will set the namespace to `production` for all resources | ||
| - These Functions are not rendered until the package is "pushed" to porch | ||
|
|
||
| **Add new resource:** | ||
|
|
||
| Create a new configmap: | ||
|
|
||
| ```bash | ||
| vim ./my-first-package/test-config.yaml | ||
| ``` | ||
|
|
||
| Now add the following content to this new configmap | ||
|
|
||
| ```yaml | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: test-config | ||
| data: | ||
| key: "value" | ||
| ``` | ||
|
|
||
| **Save and close the file.** | ||
|
|
||
| {{% alert title="Note" color="primary" %}} | ||
| Changes are LOCAL ONLY (Porch doesn't know about them yet) at this stage | ||
| {{% /alert %}} | ||
|
|
||
| --- | ||
|
|
||
| ## Step 4: Push Changes Back to Porch | ||
|
|
||
| Upload your modified package revision back to Porch: | ||
|
|
||
| ```bash | ||
| porchctl rpkg push porch-test.my-first-package.v1 ./my-first-package --namespace default | ||
| ``` | ||
|
|
||
| **What this does:** | ||
|
|
||
| - Updates the PackageRevision in Porch | ||
| - Triggers rendering (executes pipeline functions) | ||
| - PackageRevision remains in `Draft` state | ||
|
|
||
|  | ||
|
|
||
| **Successful output:** | ||
|
|
||
| This describes how the KRM function was run by porch and has updated the namespace in our new configmap. | ||
|
|
||
| ```bash | ||
| [RUNNING] "gcr.io/kpt-fn/set-namespace:v0.4.1" | ||
| [PASS] "gcr.io/kpt-fn/set-namespace:v0.4.1" | ||
| Results: | ||
| [info]: namespace "" updated to "production", 1 value(s) changed | ||
| porch-test.my-first-package.v1 pushed | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Step 5: Propose the Package Revision | ||
|
|
||
| Move the package revision to `Proposed` state for review: | ||
|
|
||
| ```bash | ||
| porchctl rpkg propose porch-test.my-first-package.v1 --namespace default | ||
| ``` | ||
|
|
||
| **What this does:** | ||
|
|
||
| - Changes lifecycle from `Draft` to `Proposed` | ||
| - Signals the package revision is ready for review | ||
| - PackageRevision can still be modified if needed | ||
|
|
||
|  | ||
|
|
||
| {{% alert title="Note" color="primary" %}} | ||
| A lifecycle state change from `Draft` to `Proposed` means that in Git the package revision has moved from the `draft` branch to the `proposed` branch | ||
| {{% /alert %}} | ||
|
|
||
| **Verify the state change:** | ||
|
|
||
| ```bash | ||
| porchctl rpkg get porch-test.my-first-package.v1 --namespace default | ||
| ``` | ||
|
|
||
| The lifecycle should now show `Proposed`. | ||
|
|
||
| ```bash | ||
| NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY | ||
| porch-test.my-first-package.v1 my-first-package v1 0 false Proposed porch-test | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Step 6a: Approve the Package Revision | ||
|
|
||
| If the package revision looks good, approve it to publish: | ||
|
|
||
| ```bash | ||
| porchctl rpkg approve porch-test.my-first-package.v1 --namespace default | ||
| ``` | ||
|
|
||
| **What this does:** | ||
|
|
||
| - Changes PackageRevision lifecycle from `Proposed` (revision 0) to `Published` (revision 1) | ||
| - PackageRevision becomes **immutable** (content cannot be changed) | ||
| - Records who approved and when | ||
| - PackageRevision is now available for cloning/deployment | ||
|
|
||
Catalin-Stratulat-Ericsson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|  | ||
|
|
||
| **Verify publication:** | ||
|
|
||
| ```bash | ||
| porchctl rpkg get porch-test.my-first-package.v1 --namespace default -o yaml | grep -E "lifecycle|publishedBy|publishTimestamp" | ||
| ``` | ||
|
|
||
| **Verify the state change:** | ||
|
|
||
| ```bash | ||
| porchctl rpkg get porch-test.my-first-package.v1 --namespace default | ||
| ``` | ||
|
|
||
| The lifecycle should now show `Published`. | ||
|
|
||
| ```bash | ||
| NAME PACKAGE WORKSPACENAME REVISION LATEST LIFECYCLE REPOSITORY | ||
| porch-test.my-first-package.v1 my-first-package v1 1 true Published porch-test | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Step 6b: Reject the Package Revision (Alternative) | ||
|
|
||
| If the package revision needs more work, reject it to return to `Draft`: | ||
|
|
||
| ```bash | ||
| porchctl rpkg reject porch-test.my-first-package.v1 --namespace default | ||
| ``` | ||
|
|
||
| **What this does:** | ||
|
|
||
| - Changes lifecycle from `Proposed` back to `Draft` | ||
| - Allows further modifications | ||
| - You can then make changes and re-propose | ||
|
|
||
|  | ||
|
|
||
| If the package revision is rejected, the process begins again from Step 2 until the desired state is achieved. | ||
|
|
||
|  | ||
|
|
||
| --- | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| **PackageRevision stuck in Draft?** | ||
|
|
||
| - Check readiness conditions: `porchctl rpkg get <PACKAGE-REVISION> -o yaml | grep -A 5 conditions` | ||
|
|
||
| **Push fails with conflict?** | ||
|
|
||
| - Pull the latest version first: `porchctl rpkg pull <PACKAGE-REVISION> ./dir` | ||
| - The PackageRevision may have been modified by someone else | ||
|
|
||
| **Cannot modify Published PackageRevision?** | ||
|
|
||
| - Published PackageRevisions are immutable | ||
| - Create a new revision using `porchctl rpkg copy` [Copying Package Revisions Guide]({{% relref "/docs/neo-porch/4_tutorials_and_how-tos/copying-packages.md" %}}). | ||
|
|
||
| --- | ||
|
|
||
| ## Understanding PackageRevision Names | ||
|
|
||
| Porch generates PackageRevision names automatically: | ||
|
|
||
| - Format: `{repoName}.{packageName}.{workspaceName}` | ||
| - Example: `porch-test.my-first-package.v1` | ||
| - The workspace name must be unique within the package | ||
| - Multiple PackageRevisions can share the same package name but have different workspaces | ||
|
|
||
| --- | ||
|
|
||
| ## Key Concepts | ||
|
|
||
| - **PackageRevision**: The Kubernetes resource managed by Porch (there is no separate "Package" resource) | ||
| - **Draft**: Work in progress, fully editable | ||
| - **Proposed**: Ready for review, still editable | ||
| - **Published**: Approved and immutable | ||
| - **Workspace**: Unique identifier for a PackageRevision within a package | ||
| - **Repository**: Git repo where PackageRevisions are stored | ||
| - **Pipeline**: KRM functions that transform PackageRevision resources | ||
| - **Revision Number**: 0 for Draft/Proposed, 1+ for Published (increments with each publication) | ||
|
|
||
| --- | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.