Skip to content

Commit 78d4fe8

Browse files
committed
docs: changing the object to always be available
Signed-off-by: Andrew Shoell <mrlunchbox777@gmail.com>
1 parent f613f22 commit 78d4fe8

1 file changed

Lines changed: 70 additions & 78 deletions

File tree

hips/hip-0027.md

Lines changed: 70 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ status: "draft"
1111

1212
This HIP proposes exposing metadata from the currently deployed chart version during template rendering for upgrade and rollback operations. Currently, Helm templates have access to `.Chart` which provides metadata about the chart being installed (name, version, appVersion, etc.), but no equivalent access to information about the release currently deployed in the cluster. This limitation prevents chart authors from implementing upgrade-aware logic, forcing them to rely on complex workarounds such as post-renderers, pre-upgrade hooks, or manual values file conventions.
1313

14-
The proposal introduces a new `.DeployedChart` object available in the template context during `helm upgrade` and `helm rollback` operations. This object contains the same metadata structure as `.Chart` but is populated with values from the chart version currently running in the cluster. When no deployed release exists (such as during initial installation), `.DeployedChart` is nil, allowing templates to safely check for its existence with `{{ if .DeployedChart }}`.
14+
The proposal introduces a new `.DeployedChart` object available in the template context during all Helm operations. This object contains the same metadata structure as `.Chart` but is populated with values from the chart version currently running in the cluster during upgrade and rollback operations. When no deployed release exists (such as during initial installation, dry-run operations, or when explicitly disabled), `.DeployedChart` is nil, allowing templates to safely check for its existence with `{{ if .DeployedChart }}`.
1515

1616
This enhancement enables chart maintainers to build intelligent upgrade paths that can detect version transitions, implement breaking change migrations, conditionally apply resources based on version deltas, and provide seamless user experiences during chart lifecycle operations—all within the chart itself without requiring external tooling. An optional `--disable-deployed-chart` flag allows users to opt out of this feature for security or determinism requirements.
1717

@@ -93,16 +93,27 @@ This decision provides:
9393

9494
### Available During Upgrade and Rollback Operations
9595

96-
`.DeployedChart` is populated during both `helm upgrade` and `helm rollback` operations because both scenarios involve transitioning from one deployed state to another. In both cases:
96+
`.DeployedChart` is always available as a template object but is populated with chart metadata only during `helm upgrade` and `helm rollback` operations when a deployed release exists in the cluster. In all other scenarios, `.DeployedChart` is nil.
9797

98-
- There is a currently deployed release that templates may need to reason about
99-
- Version-aware logic is valuable (e.g., handling migrations, conditional resources)
100-
- The semantics of "deployed chart" remain clear and unambiguous
98+
**Populated with chart metadata:**
99+
- `helm upgrade` (when upgrading an existing release)
100+
- `helm rollback` (when rolling back to a previous revision)
101101

102-
`.DeployedChart` is explicitly **not** available (always nil) during:
103-
- `helm install`: No deployed chart exists
104-
- `helm template`: See "Dry-Run and Template Operations" below
105-
- `helm install --dry-run`: See "Dry-Run and Template Operations" below
102+
**Always nil:**
103+
- `helm install` - No deployed release exists yet
104+
- `helm upgrade` (first install) - Treated as install, no prior release
105+
- `helm template` - No cluster context available
106+
- `helm install --dry-run` - No cluster context available
107+
- `helm upgrade --dry-run` - No cluster access during dry-run
108+
- When `--disable-deployed-chart` flag is used - Explicitly disabled
109+
110+
The object is always present in the template context to ensure templates can be written consistently across all operations. Chart authors can rely on `.DeployedChart` being a valid object reference (though it may be nil) without worrying about undefined variable errors.
111+
112+
**Why always available but sometimes nil:**
113+
- Consistent template behavior - templates don't need to conditional logic to check if the object exists vs. if it has data
114+
- Follows Go template conventions - nil is the idiomatic way to represent absence of data
115+
- Simplifies template code - `{{ if .DeployedChart }}` works in all scenarios
116+
- Enables testing - templates using `.DeployedChart` can be tested with `helm template` without errors
106117

107118
### Chart Metadata Only (Not Full Release Data)
108119

@@ -167,7 +178,9 @@ Chart authors who need to inspect actual cluster state should use the `lookup()`
167178

168179
### Dry-Run and Template Operations
169180

170-
`.DeployedChart` is **not** available during `helm template` or `helm install --dry-run` operations because these commands are intentionally cluster-agnostic and should remain deterministic without cluster context.
181+
`.DeployedChart` is always available as a template object but is always nil during `helm template` and dry-run operations (`helm install --dry-run`, `helm upgrade --dry-run`) because these commands are intentionally cluster-agnostic and should remain deterministic without cluster context.
182+
183+
The object is present (but nil) to ensure templates that reference `.DeployedChart` don't fail with undefined variable errors during templating and dry-run operations.
171184

172185
However, we recognize that chart authors may want to test templates that use `.DeployedChart`. To support this use case:
173186

@@ -201,13 +214,23 @@ The following outlines the syntax and semantics of the proposed changes.
201214

202215
### New Template Object: `.DeployedChart`
203216

204-
A new top-level template object `.DeployedChart` will be available during `helm upgrade` and `helm rollback` operations.
217+
A new top-level template object `.DeployedChart` will be available in all template contexts. The object is populated with chart metadata during `helm upgrade` and `helm rollback` operations when a deployed release exists. In all other scenarios, the object is nil.
218+
219+
**Always available:** The `.DeployedChart` object is present in the template context for all Helm operations to ensure consistent template behavior and prevent undefined variable errors.
205220

206-
**Availability:**
207-
- **Available**: `helm upgrade`, `helm rollback`
208-
- **Not available (nil)**: `helm install`, `helm template`, `helm install --dry-run`, or when `--disable-deployed-chart` flag is used
221+
**Populated with data:**
222+
- `helm upgrade` (when upgrading an existing release)
223+
- `helm rollback` (when rolling back to a previous revision)
209224

210-
**Populated from:** The metadata of the chart version currently deployed in the cluster, retrieved from Helm's release record.
225+
**Always nil:**
226+
- `helm install` - No deployed release exists
227+
- `helm upgrade` (first install) - No deployed release exists
228+
- `helm template` - No cluster context
229+
- `helm install --dry-run` - No cluster context
230+
- `helm upgrade --dry-run` - No cluster context during dry-run
231+
- When `--disable-deployed-chart` flag is used
232+
233+
**Populated from:** When not nil, the metadata of the chart version currently deployed in the cluster, retrieved from Helm's release record.
211234

212235
### Metadata Fields
213236

@@ -314,15 +337,18 @@ When this flag is set, `.DeployedChart` will be nil regardless of whether a depl
314337

315338
### Behavior During Different Operations
316339

317-
| Operation | `.DeployedChart` Value |
318-
|-----------|----------------------|
319-
| `helm install` | Always `nil` (no deployed release) |
320-
| `helm upgrade` (first install) | `nil` (no deployed release) |
321-
| `helm upgrade` (actual upgrade) | Populated with deployed chart metadata |
322-
| `helm upgrade --disable-deployed-chart` | `nil` (explicitly disabled) |
323-
| `helm rollback` | Populated with currently deployed chart metadata |
324-
| `helm template` | Always `nil` (no cluster context) |
325-
| `helm install --dry-run` | Always `nil` (no cluster context) |
340+
| Operation | `.DeployedChart` Availability | `.DeployedChart` Value |
341+
|-----------|------------------------------|----------------------|
342+
| `helm install` | Always available | Always `nil` (no deployed release) |
343+
| `helm upgrade` (first install) | Always available | `nil` (no deployed release) |
344+
| `helm upgrade` (actual upgrade) | Always available | Populated with deployed chart metadata |
345+
| `helm upgrade --disable-deployed-chart` | Always available | `nil` (explicitly disabled) |
346+
| `helm upgrade --dry-run` | Always available | Always `nil` (no cluster context) |
347+
| `helm rollback` | Always available | Populated with currently deployed chart metadata |
348+
| `helm template` | Always available | Always `nil` (no cluster context) |
349+
| `helm install --dry-run` | Always available | Always `nil` (no cluster context) |
350+
351+
**Note:** The object is always present to prevent template errors when referencing `.DeployedChart`, even when it contains no data.
326352

327353
## Backwards Compatibility
328354

@@ -395,8 +421,14 @@ Show chart authors how to replace existing workarounds:
395421
apiVersion: batch/v1
396422
kind: Job
397423
metadata:
398-
name: migrate-v1-to-v2
399-
# ...
424+
name: {{ include "mychart.fullname" . }}-migration
425+
spec:
426+
template:
427+
spec:
428+
containers:
429+
- name: migrate
430+
image: myapp/migrator:{{ .Chart.AppVersion }}
431+
command: ["migrate", "v1-to-v2"]
400432
{{- end }}
401433
{{- end }}
402434
```
@@ -525,62 +557,22 @@ The following ideas were considered during the design of this HIP but were ultim
525557

526558
### Making Available During `helm install`
527559

528-
**Idea:** Make `.DeployedChart` available during fresh installs (would always be nil).
560+
**Idea:** Make `.DeployedChart` unavailable (not present in template context) during fresh installs.
529561

530562
**Rejection Reason:**
531-
- Provides no value (would always be nil anyway)
532-
- Adds unnecessary complexity to install code path
533-
- Could cause confusion ("why is it nil during my install?")
534-
- Templates that check `{{ if .DeployedChart }}` work correctly without special handling
563+
- Would cause template errors when templates reference `.DeployedChart` during install
564+
- Inconsistent behavior - templates would need to handle both "object doesn't exist" and "object is nil" cases
565+
- Makes testing harder - templates would fail during `helm template` with undefined variable errors
566+
- Having the object always present but nil is more idiomatic and user-friendly
567+
- Templates written with `{{ if .DeployedChart }}` work correctly in all scenarios
535568

536569
### Making Available During `helm template`
537570

538-
**Idea:** Allow `.DeployedChart` to be populated during `helm template` by querying the cluster.
571+
**Idea:** Make `.DeployedChart` unavailable (not present in template context) during `helm template`.
539572

540573
**Rejection Reason:**
541-
- Violates the design principle that `helm template` should be cluster-agnostic
542-
- Would make template rendering non-deterministic
543-
- Could cause security issues if templating in one environment with data from another
544-
- A future mock/plugin system is a better solution for testing
545-
546-
### Different Naming Conventions
547-
548-
**Ideas considered:**
549-
- `.PreviousChart` (ambiguous for rollbacks)
550-
- `.InstalledChart` (confusing with current install)
551-
- `.CurrentChart` (ambiguous which is "current")
552-
- `.Release.Deployed.Chart` (unnecessarily nested)
553-
- `.OldChart` (informal and ambiguous)
554-
555-
**Rejection Reason:** `.DeployedChart` is the clearest and most consistent with Helm terminology.
556-
557-
### Exposing Only Version Strings
558-
559-
**Idea:** Only expose `.DeployedVersion` and `.DeployedAppVersion` as simple strings instead of the full chart object.
560-
561-
**Rejection Reason:**
562-
- Inconsistent with `.Chart` object structure
563-
- Prevents access to other useful metadata (type, deprecated status, annotations)
564-
- Would need to be expanded later anyway if more fields are needed
565-
- Simpler to reuse existing Chart metadata structure
566-
567-
### Environment Variable or Config File
568-
569-
**Idea:** Control the feature via environment variable or Helm configuration file instead of CLI flag.
570-
571-
**Rejection Reason:**
572-
- Less explicit than a CLI flag
573-
- Harder to see in scripts and documentation
574-
- Doesn't follow Helm's pattern of operation-specific flags
575-
- Could cause confusion if set globally but not desired for specific operations
576-
577-
## Open Issues
578-
579-
None at this time. This HIP is ready for community review and feedback.
580-
581-
## References
582-
583-
- [Helm Built-in Objects Documentation](https://helm.sh/docs/chart_template_guide/builtin_objects/)
584-
- [Helm Template Functions and Pipelines](https://helm.sh/docs/chart_template_guide/functions_and_pipelines/)
585-
- [Go Template Documentation](https://pkg.go.dev/text/template)
586-
- [Semantic Versioning 2.0.0](https://semver.org/)
574+
- Would cause template errors when templates reference `.DeployedChart`
575+
- Violates the design principle that `helm template` should work for all valid templates
576+
- Makes development harder - chart authors couldn't validate template syntax
577+
- Having the object present but nil allows templates to render successfully
578+
- A future mock/plugin system is a better solution for providing test data

0 commit comments

Comments
 (0)