Skip to content

Commit b48d8f5

Browse files
committed
docs: updated hip from notes during helm dev meeting
Signed-off-by: Andrew Shoell <[email protected]>
1 parent 4c65745 commit b48d8f5

File tree

1 file changed

+65
-37
lines changed

1 file changed

+65
-37
lines changed

hips/hip-0027.md

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
hip: 0027
33
title: "Expose Previously Installed Chart Metadata During Template Rendering"
4-
authors: [ "Andrew Shoell <[email protected]>" ]
4+
authors: ["Andrew Shoell <[email protected]>"]
55
created: "2025-11-12"
66
type: "feature"
77
status: "draft"
88
---
99

1010
## Abstract
1111

12-
This HIP proposes exposing metadata from the currently deployed chart version during template rendering. Currently, Helm templates have access to `.Chart` for the chart being installed but no equivalent access to the currently deployed release. This forces chart authors to use complex workarounds like post-renderers, pre-upgrade hooks, or manual values conventions to implement version-aware upgrade logic.
12+
This HIP proposes exposing metadata from currently deployed chart versions during template rendering. Currently, Helm templates have access to `.Chart` for the chart being installed but no equivalent access to deployed releases. This forces chart authors to use complex workarounds like post-renderers, pre-upgrade hooks, or manual values conventions to implement version-aware upgrade logic.
1313

14-
The proposal introduces a new `.DeployedChart` object available in all template contexts, populated with the deployed chart's metadata during `helm upgrade` and `helm rollback` operations. When no deployed release exists, `.DeployedChart` is nil, allowing safe checks with `{{ if .DeployedChart }}`. An optional `--disable-deployed-chart` flag provides opt-out capability.
14+
The proposal introduces `.DeployedChart` (singular, latest deployed) and `.DeployedCharts` (array, multiple versions) objects available in all template contexts, populated during `helm upgrade` and `helm rollback` operations. The `--deployed-depth` flag controls how many deployed versions to retrieve (default: 1), with `--deployed-depth 0` disabling the feature.
1515

1616
## Motivation
1717

@@ -38,34 +38,36 @@ Post-rendering solutions violate Helm's design philosophy that template renderin
3838

3939
## Rationale
4040

41-
### Naming: `.DeployedChart`
41+
### Naming: `.DeployedChart` and `.DeployedCharts`
42+
43+
`.DeployedChart` (singular) provides ergonomic access to the most recent deployed version. `.DeployedCharts` (array) provides access to historical deployed versions in reverse chronological order (index 0 is most recent). `.DeployedChart` is syntactic sugar for `.DeployedCharts[0]`.
4244

4345
Alternatives considered and rejected:
46+
4447
- `.PreviousChart` - Ambiguous during rollbacks
4548
- `.InstalledChart` - Confusing with current installation
4649
- `.CurrentChart` - Ambiguous which is "current"
4750
- `.Release.Deployed.Chart` - Unnecessarily nested
4851

49-
`.DeployedChart` unambiguously means "what is currently running in the cluster" and maintains consistency with Helm terminology.
52+
### Always Available as Template Objects
5053

51-
### Always Available as Template Object
52-
53-
`.DeployedChart` is always present (though possibly nil) to ensure consistent template behavior, prevent undefined variable errors, and enable testing with `helm template`.
54+
`.DeployedChart` (nil or chart metadata) and `.DeployedCharts` (empty array or populated) are always present to ensure consistent template behavior, prevent undefined variable errors, and enable testing with `helm template`.
5455

5556
### Populated Only During Upgrades/Rollbacks
5657

57-
`.DeployedChart` contains chart metadata only during `helm upgrade` and `helm rollback` when a deployed release exists. It's nil for:
58+
`.DeployedChart`/`.DeployedCharts` contain chart metadata only during `helm upgrade` and `helm rollback` when deployed releases exist. During rollback, they reflect the currently deployed version (being rolled back _from_). They're nil/empty for:
59+
5860
- `helm install` - No deployed release
5961
- `helm template` / dry-runs - No cluster context
60-
- When `--disable-deployed-chart` is used
62+
- When `--deployed-depth 0` is used
6163

6264
### Chart Metadata Only
6365

6466
This proposal exposes only Chart.yaml metadata (same structure as `.Chart`), not values, manifests, or release metadata. This maintains security (values may contain secrets), performance (manifests can be large), and simplicity while solving 90% of use cases. Future HIPs could extend this if needed.
6567

66-
### Opt-Out Flag
68+
### Depth Control Flag
6769

68-
The `--disable-deployed-chart` flag allows organizations to disable the feature for security or determinism requirements. A CLI flag was chosen over environment variables for explicitness and consistency with Helm's patterns.
70+
The `--deployed-depth` flag controls how many deployed chart versions to retrieve (default: 1). Setting `--deployed-depth 0` disables the feature for security or determinism requirements. Higher depths may impact performance and should only be used for specific multi-version migration scenarios.
6971

7072
### Design Decisions
7173

@@ -75,17 +77,20 @@ The `--disable-deployed-chart` flag allows organizations to disable the feature
7577

7678
## Specification
7779

78-
### New Template Object: `.DeployedChart`
80+
### New Template Objects
7981

80-
A top-level template object available in all contexts. Populated with deployed chart metadata during upgrade/rollback; nil otherwise.
82+
**`.DeployedChart`**: Singular object containing the most recent deployed chart metadata (nil if none exists). Syntactic sugar for `.DeployedCharts[0]`.
8183

82-
**Metadata Structure:** Identical to `.Chart`, including `Name`, `Version`, `AppVersion`, and other [Chart.yaml fields](https://helm.sh/docs/topics/charts/#the-chartyaml-file).
84+
**`.DeployedCharts`**: Array of deployed chart metadata objects in reverse chronological order (most recent first). Empty array if no deployed releases exist.
85+
86+
**Metadata Structure:** Each chart object is identical to `.Chart`, including `Name`, `Version`, `AppVersion`, and other [Chart.yaml fields](https://helm.sh/docs/topics/charts/#the-chartyaml-file).
87+
88+
**Usage Examples:**
8389

84-
**Usage Example:**
8590
```yaml
91+
# Simple case: check latest deployed version
8692
{{- if .DeployedChart }}
8793
{{- if and (semverCompare ">=2.0.0" .Chart.Version) (semverCompare "<2.0.0" .DeployedChart.Version) }}
88-
# Migration logic for 1.x -> 2.x upgrade
8994
apiVersion: batch/v1
9095
kind: Job
9196
metadata:
@@ -101,43 +106,61 @@ spec:
101106
command: ["migrate", "v1-to-v2"]
102107
{{- end }}
103108
{{- end }}
109+
110+
# Multi-version migration: handle complex upgrade paths
111+
{{- if gt (len .DeployedCharts) 0 }}
112+
{{- range .DeployedCharts }}
113+
{{- if semverCompare "<1.5.0" .Version }}
114+
# Run migration for versions before 1.5.0
115+
{{- end }}
116+
{{- end }}
117+
{{- end }}
104118
```
105119

106120
### Command-Line Flag
107121

108122
```bash
109-
helm upgrade myrelease mychart --disable-deployed-chart
123+
# Default: retrieve latest deployed chart
124+
helm upgrade myrelease mychart
125+
126+
# Retrieve last 3 deployed versions
127+
helm upgrade myrelease mychart --deployed-depth 3
128+
129+
# Disable feature
130+
helm upgrade myrelease mychart --deployed-depth 0
110131
```
111132

112133
### Behavior Matrix
113134

114-
| Operation | `.DeployedChart` Value |
115-
|-----------|------------------------|
116-
| `helm install` | `nil` (no deployed release) |
117-
| `helm upgrade` (new) | `nil` (no deployed release) |
118-
| `helm upgrade` (existing) | Populated with deployed metadata |
119-
| `helm rollback` | Populated with deployed metadata |
120-
| `helm template` / dry-runs | `nil` (no cluster context) |
121-
| With `--disable-deployed-chart` | `nil` (explicitly disabled) |
135+
| Operation | `.DeployedChart` / `.DeployedCharts` |
136+
| -------------------------- | --------------------------------------------------------------- |
137+
| `helm install` | `nil` / `[]` (no deployed release) |
138+
| `helm upgrade` (new) | `nil` / `[]` (no deployed release) |
139+
| `helm upgrade` (existing) | Populated with deployed metadata (most recent first) |
140+
| `helm rollback` | Populated with currently deployed version (rolling back _from_) |
141+
| `helm template` / dry-runs | `nil` / `[]` (no cluster context) |
142+
| `--deployed-depth 0` | `nil` / `[]` (explicitly disabled) |
143+
| `--deployed-depth N` | Up to N most recent deployed versions |
122144

123145
## Backwards Compatibility
124146

125-
Fully backwards compatible. The `.DeployedChart` object is purely additive—existing charts work unchanged. Go templates handle nil safely; the recommended `{{ if .DeployedChart }}` pattern works in all scenarios.
147+
Fully backwards compatible. The `.DeployedChart` and `.DeployedCharts` objects are purely additive—existing charts work unchanged. Go templates handle nil and empty arrays safely; the recommended `{{ if .DeployedChart }}` pattern works in all scenarios.
126148

127149
## Security Implications
128150

129151
**Not Exposed:** Previous values (may contain secrets) or previous manifest (may contain sensitive data). Only Chart.yaml metadata is exposed.
130152

131-
**Considerations:** Chart authors should not store sensitive data in Chart.yaml. The `--disable-deployed-chart` flag provides opt-out for security-sensitive environments.
153+
**Considerations:** Chart authors should not store sensitive data in Chart.yaml. The `--deployed-depth 0` flag provides opt-out for security-sensitive environments. Higher depth values increase data exposure; use the minimum required.
132154

133155
## How to Teach This
134156

135157
### Documentation Additions
136158

137-
1. **Template Objects Reference:** Add `.DeployedChart` to built-in objects with availability details
138-
2. **Upgrade Guide:** "Implementing Version-Aware Upgrades" covering nil checks, version comparisons, and best practices
139-
3. **Migration Examples:** Show replacement of post-renderers and pre-upgrade hooks with `.DeployedChart`
140-
4. **Chart Linting:** Update `helm lint` to warn on `.DeployedChart` usage without nil checks
159+
1. **Template Objects Reference:** Add `.DeployedChart` and `.DeployedCharts` to built-in objects with availability details
160+
2. **Upgrade Guide:** "Implementing Version-Aware Upgrades" covering nil/empty checks, version comparisons, and best practices
161+
3. **Migration Examples:** Show replacement of post-renderers and pre-upgrade hooks
162+
4. **Performance Note:** Document that `--deployed-depth` should be kept minimal; default of 1 is recommended
163+
5. **Chart Linting:** Update `helm lint` to warn on usage without nil/empty checks
141164

142165
### Key Example Pattern
143166

@@ -150,22 +173,27 @@ Fully backwards compatible. The `.DeployedChart` object is purely additive—exi
150173
## Reference Implementation
151174

152175
A future pull request will:
153-
1. Extend template rendering context to include `.DeployedChart`
154-
2. Populate from release records during upgrade/rollback
155-
3. Add `--disable-deployed-chart` flag
156-
4. Include comprehensive unit and integration tests
176+
177+
1. Extend template rendering context to include `.DeployedChart` and `.DeployedCharts`
178+
2. Populate from release records during upgrade/rollback (reverse chronological order)
179+
3. Add `--deployed-depth` flag (default: 1)
180+
4. Implement `.DeployedChart` as alias to `.DeployedCharts[0]`
181+
5. Include comprehensive unit and integration tests covering depth behavior
157182

158183
## Rejected Ideas
159184

160185
- **Full Release Object:** Security/performance concerns; chart metadata sufficient
161186
- **Only Version Strings:** Inconsistent with `.Chart`; prevents access to other metadata
162187
- **Environment Variable Control:** Less explicit than CLI flag
163188
- **Cluster Query During `helm template`:** Violates cluster-agnostic design principle
164-
- **Mutable `.DeployedChart`:** Violates read-only template model; no clear use case
189+
- **Mutable Objects:** Violates read-only template model; no clear use case
190+
- **Separate `--disable-deployed-chart` Flag:** Unified `--deployed-depth` with 0 value is cleaner
191+
- **Unlimited History:** Performance implications; requiring explicit depth prevents accidental overhead
165192

166193
## References
167194

168195
- [Helm Built-in Objects](https://helm.sh/docs/chart_template_guide/builtin_objects/)
169196
- [Helm Chart.yaml](https://helm.sh/docs/topics/charts/#the-chartyaml-file)
170197
- [Go Templates](https://pkg.go.dev/text/template)
171198
- [Semantic Versioning](https://semver.org/)
199+
- [Example of current workaround](https://github.com/helm/community/pull/421#issuecomment-3662769874)

0 commit comments

Comments
 (0)