Skip to content

Commit 2f4ff88

Browse files
Ilanit Steinclaude
andcommitted
docs: restructure documentation with updated command references
Reorganize documentation into docs/ with commands/ and development/ subdirectories. Add CONTRIBUTING.md for contributor onboarding. New structure: - docs/commands/ — reference for all 5 commands (export, transform, apply, validate, transfer-pvc) - docs/development/ — architecture, setup, testing, plugin development - docs/multistage-pipeline.md — multi-stage Kustomize pipeline guide - docs/plugins.md — plugin overview - docs/resource-compatibility.md — resource type compatibility matrix - docs/installation.md — installation and prerequisites Content updated to reflect current codebase: - crane apply uses embedded kustomize (no kubectl dependency) - crane apply supports --skip-cluster-scoped and --kustomize-args flags - crane validate supports offline mode via --api-resources - crane export documents CRD collection and _cluster/ subdirectory Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 652e9f2 commit 2f4ff88

17 files changed

Lines changed: 2494 additions & 1 deletion

CONTRIBUTING.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Contributing to Crane
2+
3+
Thank you for your interest in contributing to Crane! This guide will help you get started.
4+
5+
## Quick Start
6+
7+
1. Fork and clone the repository:
8+
```bash
9+
git clone https://github.com/<your-username>/crane.git
10+
cd crane
11+
```
12+
13+
2. Build the binary:
14+
```bash
15+
go build -o crane main.go
16+
```
17+
18+
3. Run tests:
19+
```bash
20+
go test ./...
21+
```
22+
23+
4. Submit a pull request
24+
25+
## Prerequisites
26+
27+
- **Go** 1.25+ (see `go.mod` for exact version)
28+
- **kubectl** (for deploying output to clusters and for `crane validate` with live cluster mode)
29+
- **Docker** (optional, for container-based testing)
30+
- Access to a Kubernetes cluster (for E2E testing)
31+
32+
## Development Setup
33+
34+
For detailed guides on architecture, testing, and advanced development workflows, see the [Development Documentation](docs/development/README.md).
35+
36+
## Code Standards
37+
38+
### Go Conventions
39+
40+
- Follow standard Go idioms and [Effective Go](https://go.dev/doc/effective_go) practices
41+
- Use `gofmt` for formatting
42+
- Prefer explicit error messages with context — include the actual type received, the API resource being processed, and enough context to debug without re-running
43+
44+
### Error Handling
45+
46+
Error messages must be actionable:
47+
48+
```go
49+
// Good — shows actual object type
50+
fmt.Errorf("expected *unstructured.Unstructured but got %T", object)
51+
52+
// Bad — shows nil pointer
53+
fmt.Errorf("expected *unstructured.Unstructured but got %T", u)
54+
```
55+
56+
### Working with Kubernetes API Objects
57+
58+
- Use `*unstructured.Unstructured` for dynamic resources
59+
- Always check type assertions and provide informative error messages
60+
- Include the actual resource type and API resource name in errors
61+
62+
## Commit Messages
63+
64+
Use conventional commits format:
65+
66+
- `fix:` for bug fixes
67+
- `feat:` for new features
68+
- `refactor:` for code restructuring
69+
- `test:` for test additions
70+
- `docs:` for documentation
71+
72+
Include issue references where applicable: `fix: improve error messages (#197)`
73+
74+
## Pull Request Guidelines
75+
76+
**Title:** Clear and concise (under 70 characters)
77+
78+
**Body must include:**
79+
- **Summary** — what changed and why
80+
- **Impact** — severity, affected components
81+
- **Test plan** — how to verify
82+
83+
**Before submitting:**
84+
85+
- [ ] Code compiles: `go build ./...`
86+
- [ ] Tests pass: `go test ./...`
87+
- [ ] Error messages are informative
88+
- [ ] No unnecessary refactoring in the same PR
89+
- [ ] Backward compatible (or documented breaking change)
90+
91+
## Testing
92+
93+
- All new features require tests
94+
- Bug fixes should include regression tests when possible
95+
- Use table-driven tests for multiple scenarios
96+
- Test files: `*_test.go` in the same package
97+
- E2E tests: `e2e-tests/`
98+
99+
See [Testing Guide](docs/development/testing.md) for detailed testing documentation.
100+
101+
## Reporting Issues
102+
103+
- Check existing issues before filing a new one
104+
- Include reproduction steps, expected behavior, and actual behavior
105+
- Include Crane version, Go version, and Kubernetes version
106+
107+
## Code of Conduct
108+
109+
Be respectful and constructive. We follow the [Konveyor community guidelines](https://www.konveyor.io/).

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ How does it work? Crane works by:
9999
* `$ cat transform/10_KubernetesPlugin/resources/secret.yaml` - Contains the original exported Secret with all metadata
100100

101101
5. `$ crane apply`
102-
* Runs `kubectl kustomize` on the transform stage to apply patches
102+
* Runs embedded kustomize on the transform stage to apply patches
103103
* Outputs clean, declarative YAML to `output/output.yaml`
104104
* Example:
105105
* `$ cat output/output.yaml`
@@ -117,6 +117,14 @@ How does it work? Crane works by:
117117
6. The content in `output/output.yaml` is now ready to be deployed to the target cluster or checked into Git for GitOps workflows:
118118
* `$ kubectl apply -f output/output.yaml`
119119

120+
## Documentation
121+
122+
For comprehensive documentation, see the [docs/](docs/README.md) directory:
123+
124+
- [Installation](docs/installation.md)
125+
- [Command Reference](docs/README.md#command-reference) — export, transform, apply, validate, transfer-pvc
126+
- [Contributing](CONTRIBUTING.md) | [Development Guide](docs/development/README.md)
127+
120128
## Further Examples
121129

122130
Please see [konveyor/crane-runner/main/examples](https://github.com/konveyor/crane-runner/tree/main/examples#readme) for further scenarios to explore what can be done with Crane + Tekton for migrating applications.

docs/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Crane Documentation
2+
3+
Welcome to the Crane documentation. Crane is a Kubernetes migration tool that helps migrate workloads between clusters using a non-destructive pipeline: **export → transform → apply → validate**.
4+
5+
## Getting Started
6+
7+
- [Installation](./installation.md) — Prerequisites, building, and verifying the Crane binary
8+
9+
## Command Reference
10+
11+
- [`crane export`](./commands/export.md) — Export namespace resources from a source cluster
12+
- [`crane transform`](./commands/transform.md) — Transform exported resources using plugins and Kustomize
13+
- [`crane apply`](./commands/apply.md) — Apply transformations and produce final manifests
14+
- [`crane validate`](./commands/validate.md) — Validate final manifests against a target cluster
15+
- [`crane transfer-pvc`](./commands/transfer-pvc.md) — Transfer PVC data between clusters via rsync
16+
17+
## Concepts
18+
19+
- [Multi-Stage Pipeline](./multistage-pipeline.md) — How Crane's multi-stage Kustomize transform pipeline works
20+
- [Plugins](./plugins.md) — Built-in and custom plugin overview
21+
22+
## Reference
23+
24+
- [Pre-Apply Validation Guide](./pre-apply-validation-guide.md) — Checklist for validating manifests before applying
25+
- [Resource Compatibility](./resource-compatibility.md) — Supported resource types and migration boundaries
26+
27+
## Development
28+
29+
- [Development Guide](./development/README.md) — Architecture, setup, testing, and plugin development
30+
- [Contributing](../CONTRIBUTING.md) — How to contribute to Crane

docs/commands/apply.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# crane apply
2+
3+
Apply transformations to exported resources and produce final manifests.
4+
5+
## Synopsis
6+
7+
```bash
8+
crane apply [flags]
9+
```
10+
11+
## Description
12+
13+
`crane apply` runs embedded kustomize on each transform stage to apply patches, producing clean, declarative YAML ready for deployment to a target cluster. By default, all stages are applied sequentially to maintain consistency across the pipeline. The output includes both a single multi-document YAML file and individual resource files organized by namespace.
14+
15+
Kustomize is embedded directly in the Crane binary (via the krusty API), so no external `kubectl` dependency is needed.
16+
17+
## Flags
18+
19+
| Flag | Short | Default | Description |
20+
|------|-------|---------|-------------|
21+
| `--export-dir` | `-e` | `export` | The path where exported resources are saved (kept for consistency; not used by apply) |
22+
| `--transform-dir` | `-t` | `transform` | The path where transform stage directories are located |
23+
| `--output-dir` | `-o` | `output` | The path where final manifests are written |
24+
| `--stage` | | | Apply a specific stage only (e.g., `10_KubernetesPlugin`). If not specified, all stages are applied |
25+
| `--kustomize-args` | | | Additional arguments for kustomize (e.g., `--enable-helm --helm-command=helm3`) |
26+
| `--skip-cluster-scoped` | | `false` | Exclude cluster-scoped resources (ClusterRole, ClusterRoleBinding, CRD, etc.) from output. Useful for non-admin migration scenarios |
27+
28+
## Output Structure
29+
30+
```text
31+
output/
32+
├── output.yaml # All resources in a single multi-document YAML
33+
└── resources/ # Individual resource files
34+
├── <namespace>/
35+
│ ├── Deployment_apps_v1_<ns>_<name>.yaml
36+
│ ├── Service__v1_<ns>_<name>.yaml
37+
│ └── ConfigMap__v1_<ns>_<name>.yaml
38+
└── _cluster/ # Cluster-scoped resources (when not skipped)
39+
├── ClusterRoleBinding_rbac.authorization.k8s.io_v1_clusterscoped_<name>.yaml
40+
└── ClusterRole_rbac.authorization.k8s.io_v1_clusterscoped_<name>.yaml
41+
```
42+
43+
- **`output.yaml`** — Ready for `kubectl apply -f`
44+
- **`resources/<namespace>/`** — Individual files for selective review or application
45+
- **`resources/_cluster/`** — Cluster-scoped resources (omitted when `--skip-cluster-scoped` is set)
46+
47+
## Examples
48+
49+
### Apply all stages (default)
50+
51+
```bash
52+
crane apply
53+
```
54+
55+
### Apply with custom directories
56+
57+
```bash
58+
crane apply --transform-dir ./migration/transform --output-dir ./migration/output
59+
```
60+
61+
### Apply a specific stage only
62+
63+
```bash
64+
crane apply --stage 10_KubernetesPlugin
65+
```
66+
67+
### Skip cluster-scoped resources
68+
69+
```bash
70+
crane apply --skip-cluster-scoped
71+
```
72+
73+
### Pass additional kustomize arguments
74+
75+
```bash
76+
crane apply --kustomize-args "--enable-helm --helm-command=helm3"
77+
```
78+
79+
### Deploy to target cluster
80+
81+
```bash
82+
crane apply
83+
kubectl apply -f output/output.yaml
84+
```
85+
86+
## Common Errors
87+
88+
| Error | Cause | Solution |
89+
|-------|-------|----------|
90+
| `kustomization.yaml validation failed` | Invalid Kustomize syntax or missing resource files | Run `crane apply --stage <stage>` to isolate the failing stage |
91+
| `invalid stage name` | Stage name doesn't follow `<number>_<name>` format | Use a valid stage name like `10_KubernetesPlugin` |
92+
| `invalid kustomize-args` | Unsupported or malformed kustomize arguments | Check supported kustomize flags |
93+
94+
## Next Steps
95+
96+
After applying, validate the manifests against your target cluster:
97+
98+
```bash
99+
crane validate --input-dir output --context target-cluster
100+
```
101+
102+
See [crane validate](./validate.md) for details. Or deploy directly:
103+
104+
```bash
105+
kubectl apply -f output/output.yaml
106+
```

docs/commands/export.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# crane export
2+
3+
Export namespace resources from a source Kubernetes cluster to disk.
4+
5+
## Synopsis
6+
7+
```bash
8+
crane export [flags]
9+
```
10+
11+
## Description
12+
13+
`crane export` discovers all API types in a Kubernetes cluster, lists objects in the specified namespace (plus related cluster-scoped RBAC resources), and writes manifests to an export directory. This is the first step in the Crane migration pipeline.
14+
15+
Exported resources are written as individual YAML files under `export/resources/<namespace>/`. Cluster-scoped resources related to the namespace (ClusterRoleBindings, ClusterRoles, SCCs) are written to `export/resources/<namespace>/_cluster/`. Any errors encountered during listing are recorded in `export/failures/<namespace>/`.
16+
17+
### CRD Collection
18+
19+
When custom resources are found in the namespace, Crane automatically collects their corresponding CustomResourceDefinitions. Operator-managed CRDs (identified via owner references) are skipped, since they should be installed by the operator on the target cluster rather than migrated directly. If the migration user lacks permission to read CRDs, Crane logs a warning and continues — the assumption is that the CRDs already exist on the target.
20+
21+
## Flags
22+
23+
| Flag | Short | Default | Description |
24+
|------|-------|---------|-------------|
25+
| `--export-dir` | `-e` | `export` | The path where files are exported |
26+
| `--label-selector` | `-l` | | Restrict export to resources matching a label selector |
27+
| `--namespace` | `-n` | _(context default)_ | Namespace to export |
28+
| `--crd-skip-group` | | | API groups to skip for CRD export (repeatable) |
29+
| `--crd-include-group` | | | API groups to force-include for CRD export (repeatable) |
30+
| `--as-extras` | | | Extra impersonation info (format: `key=val1,val2;key2=val3`) |
31+
| `--qps` | `-q` | `100` | Query-per-second rate for API requests |
32+
| `--burst` | `-b` | `1000` | API burst rate |
33+
34+
Standard kubeconfig flags (`--kubeconfig`, `--context`, `--cluster`, `--as`, `--as-group`, etc.) are also available.
35+
36+
## Output Structure
37+
38+
```text
39+
export/
40+
├── resources/
41+
│ └── <namespace>/
42+
│ ├── Deployment_apps_v1_<ns>_<name>.yaml
43+
│ ├── Service__v1_<ns>_<name>.yaml
44+
│ ├── ConfigMap__v1_<ns>_<name>.yaml
45+
│ └── _cluster/
46+
│ ├── ClusterRoleBinding_rbac.authorization.k8s.io_v1_clusterscoped_<name>.yaml
47+
│ ├── ClusterRole_rbac.authorization.k8s.io_v1_clusterscoped_<name>.yaml
48+
│ └── CustomResourceDefinition_apiextensions.k8s.io_v1_clusterscoped_<name>.yaml
49+
└── failures/
50+
└── <namespace>/
51+
└── <error-files>
52+
```
53+
54+
Resource filenames follow the format: `Kind_group_version_namespace_name.yaml`
55+
56+
## Examples
57+
58+
### Basic namespace export
59+
60+
```bash
61+
crane export -n my-app
62+
```
63+
64+
### Export with label selector
65+
66+
```bash
67+
crane export -n my-app --label-selector "app=frontend"
68+
```
69+
70+
### Export with custom directory
71+
72+
```bash
73+
crane export -n my-app --export-dir ./migration/export
74+
```
75+
76+
### Export with impersonation
77+
78+
```bash
79+
crane export -n my-app --as system:serviceaccount:my-app:deployer
80+
```
81+
82+
### Export with extra impersonation info
83+
84+
```bash
85+
crane export -n my-app \
86+
--as user@example.com \
87+
--as-extras "scope=read,write;project=my-project"
88+
```
89+
90+
### Export skipping specific CRD groups
91+
92+
```bash
93+
crane export -n my-app --crd-skip-group monitoring.coreos.com
94+
```
95+
96+
## Common Errors
97+
98+
| Error | Cause | Solution |
99+
|-------|-------|----------|
100+
| `namespace must be set` | No namespace specified and none in kubeconfig context | Use `-n <namespace>` |
101+
| `namespaces "X" not found` | Namespace does not exist | Verify namespace name |
102+
| `cannot verify namespace exists` | Insufficient RBAC (warning only) | Export proceeds; verify namespace exists manually |
103+
| `extras requires specifying a user or group` | `--as-extras` used without `--as` | Add `--as` or `--as-group` flag |
104+
105+
## Next Steps
106+
107+
After exporting, transform the resources:
108+
109+
```bash
110+
crane transform --export-dir export
111+
```
112+
113+
See [crane transform](./transform.md) for details.

0 commit comments

Comments
 (0)