Skip to content

Commit b9204e0

Browse files
committed
fix: release meta was throwing a spurious warning.
improve it, add more testing
1 parent afbf958 commit b9204e0

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

pkgs/nixchart/nixchart.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,16 @@ func prepareChartValues(chart map[string]any) map[string]any {
7878
v = map[string]any{}
7979
}
8080
}
81+
for _, key := range []string{"namespace", "release"} {
82+
if v[key] != nil {
83+
log.Printf("warning: `%s` in values is reserved and will be overwritten\n", key)
84+
}
85+
}
8186
delete(chart, "values") // Remove values from chart to avoid duplication in the rendered chart
8287
v["release"] = chart
88+
if ns, ok := chart["namespace"].(string); ok && ns != "" {
89+
v["namespace"] = ns // Add namespace to values if it exists
90+
}
8391
return v
8492
}
8593

@@ -117,17 +125,6 @@ var evalChart = func(chart map[string]any, hfbase string) (string, error) {
117125
}()
118126

119127
v := prepareChartValues(chart)
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-
}
124-
}
125-
if ns, ok := chart["namespace"].(string); ok && ns != "" {
126-
v["namespace"] = ns // Add namespace to values if it exists
127-
}
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-
}
131128
// Serialize the values
132129
values, err := json.Marshal(v)
133130
if err != nil {

pkgs/nixchart/nixchart_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,29 @@ func TestPrepareChartValues(t *testing.T) {
7676
t.Errorf("Expected merged values, got: %#v", vals)
7777
}
7878

79-
// Test with missing or nil values
79+
// Test with no values
8080
chartNil := map[string]any{}
8181
vals = prepareChartValues(chartNil)
8282
if len(vals) != 1 {
8383
t.Errorf("Expected only release meta, got: %#v", vals)
8484
}
85+
86+
// Test that namespace and release metadata is copied into values.
87+
chartMap = map[string]any{
88+
"namespace": "test-ns",
89+
"installed": true,
90+
"values": map[string]any{
91+
"a": 1,
92+
"b": "two",
93+
"namespace": "should-be-overwritten",
94+
},
95+
}
96+
vals = prepareChartValues(chartMap)
97+
if vals["namespace"] != "test-ns" || vals["release"] == nil {
98+
t.Errorf("Expected copied values, got: %#v", vals)
99+
}
100+
releaseMap, ok := vals["release"].(map[string]any)
101+
if !ok || releaseMap["values"] != nil {
102+
t.Errorf("Expected release metadata without values, got: %#v", releaseMap)
103+
}
85104
}

0 commit comments

Comments
 (0)