Skip to content

Commit 85ef95f

Browse files
committed
feat: expose release metadata in val.release
This allows val.release.name for instance in your nixcharts. Will warn if release is used in values
1 parent 378c001 commit 85ef95f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pkgs/nixchart/nixchart.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ func prepareChartValues(chart map[string]any) map[string]any {
7878
v = map[string]any{}
7979
}
8080
}
81+
delete(chart, "values") // Remove values from chart to avoid duplication in the rendered chart
82+
v["release"] = chart
8183
return v
8284
}
8385

@@ -115,13 +117,17 @@ var evalChart = func(chart map[string]any, hfbase string) (string, error) {
115117
}()
116118

117119
v := prepareChartValues(chart)
118-
if v["namespace"] != nil {
119-
log.Println("Warning: Do not set 'namespace' in values, use 'namespace' in the chart instead.")
120+
for _, key := range []string{"namespace", "release"} {
121+
if v[key] != nil {
122+
log.Printf("warning: `%s` in values is reserved and will be overwritten\n", key)
123+
}
120124
}
121125
if ns, ok := chart["namespace"].(string); ok && ns != "" {
122126
v["namespace"] = ns // Add namespace to values if it exists
123127
}
124-
delete(chart, "values") // Remove values from chart to avoid duplication in the rendered chart
128+
if release, ok := chart["release"].(string); ok && release != "" {
129+
log.Println("warning: `release` value is reserved and will be overwritten with chart definition")
130+
}
125131
// Serialize the values
126132
values, err := json.Marshal(v)
127133
if err != nil {

pkgs/nixchart/nixchart_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestPrepareChartValues(t *testing.T) {
7979
// Test with missing or nil values
8080
chartNil := map[string]any{}
8181
vals = prepareChartValues(chartNil)
82-
if len(vals) != 0 {
83-
t.Errorf("Expected empty map, got: %#v", vals)
82+
if len(vals) != 1 {
83+
t.Errorf("Expected only release meta, got: %#v", vals)
8484
}
8585
}

0 commit comments

Comments
 (0)