Skip to content

Commit e339cf5

Browse files
committed
update docs
1 parent 45e1a98 commit e339cf5

File tree

1 file changed

+130
-6
lines changed

1 file changed

+130
-6
lines changed

src/content/docs/reference/CRDs/module.md

Lines changed: 130 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ The `helm` field specifies Helm chart deployment configuration.
257257
|-------|------|-------------|----------|
258258
| `chart` | object | Helm chart source specification. See [Chart](#chart). | Yes |
259259
| `namespace` | string | Target Kubernetes namespace for the Helm release. Supports templating. | Yes |
260+
| `releaseName` | string | Custom Helm release name (DNS-1035 compliant). Auto-generated if not specified. **Immutable after creation.** See [Release Names](#release-names). | No |
260261
| `existingRelease` | object | Reference to an existing Helm release to adopt. See [ExistingRelease](#existingrelease). | No |
261262
| `values` | array | Array of value sources (raw, file, configMap). | No |
262263
| `outputs` | array | Output values to expose after installation. | No |
@@ -345,6 +346,44 @@ spec:
345346
| `namespace` | string | Namespace of the ConfigMap | No (default: `default`) |
346347
| `key` | string | Key containing the chart archive (`.tgz` file) | No (default: `chart.tgz`) |
347348

349+
### Release Names
350+
351+
The `releaseName` field allows you to specify a custom name for the Helm release. If not specified, Forkspacer automatically generates a unique release name.
352+
353+
**Auto-generated Release Names:**
354+
355+
When `releaseName` is not provided, the operator automatically generates a unique release name using the format:
356+
357+
```
358+
<namespace>-<11-character-uuid>
359+
```
360+
361+
For example: `default-a1b2c3d4e5f`
362+
363+
**Custom Release Names:**
364+
365+
You can specify a custom release name that must comply with DNS-1035 label standards:
366+
- Start with a lowercase letter
367+
- Contain only lowercase letters, numbers, and hyphens
368+
- End with a lowercase letter or number
369+
- Be 63 characters or less
370+
371+
```yaml
372+
spec:
373+
helm:
374+
releaseName: my-custom-release
375+
chart:
376+
repo:
377+
url: https://charts.bitnami.com/bitnami
378+
chart: redis
379+
namespace: default
380+
```
381+
382+
**Important Notes:**
383+
- The `releaseName` field is **immutable** after the Module is created
384+
- Once set (either automatically or manually), it cannot be changed
385+
- When adopting an existing release with `existingRelease`, the release name comes from `existingRelease.name` instead
386+
348387
### ExistingRelease
349388

350389
The `existingRelease` field allows you to adopt and track existing Helm releases without reinstalling them.
@@ -590,6 +629,37 @@ spec:
590629
name: dev-environment
591630
```
592631

632+
### Helm Module with Custom Release Name
633+
634+
```yaml
635+
apiVersion: batch.forkspacer.com/v1
636+
kind: Module
637+
metadata:
638+
name: my-redis
639+
namespace: default
640+
641+
spec:
642+
helm:
643+
releaseName: prod-redis-primary # Custom release name
644+
645+
chart:
646+
repo:
647+
url: https://charts.bitnami.com/bitnami
648+
chart: redis
649+
version: "21.2.9"
650+
651+
namespace: default
652+
653+
values:
654+
- raw:
655+
fullnameOverride: "{{.releaseName}}" # Uses the custom name
656+
657+
workspace:
658+
name: production-workspace
659+
```
660+
661+
This Module uses a custom release name instead of the auto-generated one. The `releaseName` is immutable after creation.
662+
593663
### Adopting an Existing Helm Release
594664

595665
```yaml
@@ -617,7 +687,7 @@ spec:
617687
name: production-workspace
618688
```
619689

620-
This Module will track the existing `redis` Helm release without reinstalling it.
690+
This Module will track the existing `redis` Helm release without reinstalling it. When `existingRelease` is set, the release name comes from `existingRelease.name`.
621691

622692
### Custom Module
623693

@@ -698,7 +768,7 @@ The Module CRD supports powerful Go template rendering for both Helm and Custom
698768
When a Module is processed, the operator:
699769

700770
1. **Validates Configuration**: Validates user-provided `spec.config` values against the `config` schema
701-
2. **Generates Release Name** (Helm only): Creates or retrieves a unique Helm release name (format: `<namespace>-<module-name>`)
771+
2. **Determines Release Name** (Helm only): Uses the configured `releaseName` if provided, or the auto-generated unique name (format: `<namespace>-<11-char-uuid>`). For adopted releases, uses `existingRelease.name`.
702772
3. **Renders Namespace** (Helm only): Renders the namespace field first with available context
703773
4. **Renders Spec**: Recursively processes the entire spec, replacing template expressions with actual values
704774
5. **Type Preservation**: Automatically converts numeric and boolean strings to their proper types
@@ -710,7 +780,7 @@ When a Module is processed, the operator:
710780
Available template variables in Helm specs:
711781

712782
- **`.config.<alias>`**: User-provided configuration values (validated)
713-
- **`.releaseName`**: Generated Helm release name (e.g., `default-redis`)
783+
- **`.releaseName`**: The Helm release name - either custom-specified via `releaseName` field, auto-generated (e.g., `default-a1b2c3d4e5f`), or from `existingRelease.name` for adopted releases
714784
- **`.namespace`**: Rendered namespace value (available in all fields except namespace itself)
715785

716786
#### Custom Modules
@@ -748,6 +818,47 @@ storageClass: "{{ default \"standard\" .config.storageClass }}"
748818
maxConnections: "{{ mul .config.replicas 10 }}"
749819
```
750820

821+
### Template Functions
822+
823+
In addition to Go's standard template functions (like `default`, `eq`, `gt`, `mul`, etc.), Forkspacer provides custom functions for common use cases.
824+
825+
#### randBase62
826+
827+
Generates a random string using base62 characters (0-9, A-Z, a-z). Useful for creating unique identifiers, passwords, or tokens.
828+
829+
**Syntax:**
830+
```yaml
831+
{{ randBase62 <length> }}
832+
```
833+
834+
**Parameters:**
835+
- `length` (integer): The number of characters to generate
836+
837+
**Example:**
838+
```yaml
839+
spec:
840+
helm:
841+
values:
842+
- raw:
843+
# Generate a 16-character random API key
844+
apiKey: "{{ randBase62 16 }}"
845+
846+
# Generate a 32-character random token
847+
token: "{{ randBase62 32 }}"
848+
849+
# Generate a short random suffix
850+
instanceId: "app-{{ randBase62 8 }}"
851+
```
852+
853+
**Output examples:**
854+
```yaml
855+
apiKey: "aB3dE5fG7hJ9kL2m"
856+
token: "xY1zA2bC3dE4fG5hI6jK7lM8nO9pQ0rS"
857+
instanceId: "app-xY7zA2bC"
858+
```
859+
860+
**Note:** Each time the template is rendered, a new random value is generated. If you need consistent values across updates, use configuration values instead of `randBase62`.
861+
751862
### Type Preservation
752863

753864
The rendering engine automatically preserves types:
@@ -855,11 +966,11 @@ helm:
855966
readReplicas: 2 # Type preserved as integer
856967
persistence:
857968
size: "50Gi"
858-
fullnameOverride: "default-postgresql-db"
969+
fullnameOverride: "default-a1b2c3d4e5f-db" # Using auto-generated releaseName
859970
860971
outputs:
861972
- name: "Database Host"
862-
value: "default-postgresql-postgresql.production-database.svc.cluster.local"
973+
value: "default-a1b2c3d4e5f-postgresql.production-database.svc.cluster.local" # Using auto-generated releaseName
863974
```
864975

865976
#### Custom Module with Templating
@@ -927,7 +1038,11 @@ spec:
9271038
host: "app.{{.namespace}}.example.com"
9281039
```
9291040

930-
### GetNamespace() Method
1041+
### Effective Namespace and Release Name
1042+
1043+
When working with Helm modules, especially with adopted releases, Forkspacer uses helper methods to determine the effective namespace and release name.
1044+
1045+
#### GetNamespace() Method
9311046

9321047
When `existingRelease` is specified, the effective namespace is determined by `GetNamespace()`:
9331048

@@ -936,6 +1051,15 @@ When `existingRelease` is specified, the effective namespace is determined by `G
9361051

9371052
This ensures proper namespace handling for adopted Helm releases.
9381053

1054+
#### GetReleaseName() Method
1055+
1056+
The effective release name is determined by `GetReleaseName()`:
1057+
1058+
- If `existingRelease` is set: returns `existingRelease.name` (for adopted releases)
1059+
- Otherwise: returns `helm.releaseName` (either custom or auto-generated)
1060+
1061+
This ensures that templates always have access to the correct release name through `.releaseName`, regardless of whether the release is newly created or adopted.
1062+
9391063
### Best Practices for Templating
9401064

9411065
1. **Always quote template expressions**: Use `"{{.config.value}}"` to ensure valid YAML

0 commit comments

Comments
 (0)