mirror of
https://github.com/helm/helm.git
synced 2026-04-20 21:56:55 -04:00
Merge pull request #13534 from althmoha/dev-v3-12987
fix (helm) : toToml` renders int as float [ backport to v3 ]
This commit is contained in:
commit
e2c7986f30
8 changed files with 53 additions and 2 deletions
|
|
@ -161,6 +161,11 @@ func TestTemplateCmd(t *testing.T) {
|
|||
cmd: fmt.Sprintf("template '%s' -f %s/extra_values.yaml", chartPath, chartPath),
|
||||
golden: "output/template-subchart-cm-set-file.txt",
|
||||
},
|
||||
{
|
||||
name: "check toToml function rendering",
|
||||
cmd: fmt.Sprintf("template '%s'", "testdata/testcharts/issue-totoml"),
|
||||
golden: "output/issue-totoml.txt",
|
||||
},
|
||||
}
|
||||
runTestCmd(t, tests)
|
||||
}
|
||||
|
|
|
|||
8
cmd/helm/testdata/output/issue-totoml.txt
vendored
Normal file
8
cmd/helm/testdata/output/issue-totoml.txt
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
# Source: issue-totoml/templates/configmap.yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: issue-totoml
|
||||
data: |
|
||||
key = 13
|
||||
3
cmd/helm/testdata/testcharts/issue-totoml/Chart.yaml
vendored
Normal file
3
cmd/helm/testdata/testcharts/issue-totoml/Chart.yaml
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
apiVersion: v2
|
||||
name: issue-totoml
|
||||
version: 0.1.0
|
||||
6
cmd/helm/testdata/testcharts/issue-totoml/templates/configmap.yaml
vendored
Normal file
6
cmd/helm/testdata/testcharts/issue-totoml/templates/configmap.yaml
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: issue-totoml
|
||||
data: |
|
||||
{{ .Values.global | toToml }}
|
||||
2
cmd/helm/testdata/testcharts/issue-totoml/values.yaml
vendored
Normal file
2
cmd/helm/testdata/testcharts/issue-totoml/values.yaml
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
global:
|
||||
key: 13
|
||||
|
|
@ -18,6 +18,7 @@ package loader
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -104,7 +105,10 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
|
|||
}
|
||||
case f.Name == "values.yaml":
|
||||
c.Values = make(map[string]interface{})
|
||||
if err := yaml.Unmarshal(f.Data, &c.Values); err != nil {
|
||||
if err := yaml.Unmarshal(f.Data, &c.Values, func(d *json.Decoder) *json.Decoder {
|
||||
d.UseNumber()
|
||||
return d
|
||||
}); err != nil {
|
||||
return c, errors.Wrap(err, "cannot load values.yaml")
|
||||
}
|
||||
case f.Name == "values.schema.json":
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ limitations under the License.
|
|||
package chartutil
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
|
@ -237,6 +238,20 @@ func TestProcessDependencyImportValues(t *testing.T) {
|
|||
if b := strconv.FormatBool(pv); b != vv {
|
||||
t.Errorf("failed to match imported bool value %v with expected %v for key %q", b, vv, kk)
|
||||
}
|
||||
case json.Number:
|
||||
if fv, err := pv.Float64(); err == nil {
|
||||
if sfv := strconv.FormatFloat(fv, 'f', -1, 64); sfv != vv {
|
||||
t.Errorf("failed to match imported float value %v with expected %v for key %q", sfv, vv, kk)
|
||||
}
|
||||
}
|
||||
if iv, err := pv.Int64(); err == nil {
|
||||
if siv := strconv.FormatInt(iv, 10); siv != vv {
|
||||
t.Errorf("failed to match imported int value %v with expected %v for key %q", siv, vv, kk)
|
||||
}
|
||||
}
|
||||
if pv.String() != vv {
|
||||
t.Errorf("failed to match imported string value %q with expected %q for key %q", pv, vv, kk)
|
||||
}
|
||||
default:
|
||||
if pv != vv {
|
||||
t.Errorf("failed to match imported string value %q with expected %q for key %q", pv, vv, kk)
|
||||
|
|
@ -309,6 +324,10 @@ func TestProcessDependencyImportValuesMultiLevelPrecedence(t *testing.T) {
|
|||
if s := strconv.FormatFloat(pv, 'f', -1, 64); s != vv {
|
||||
t.Errorf("failed to match imported float value %v with expected %v", s, vv)
|
||||
}
|
||||
case json.Number:
|
||||
if pv.String() != vv {
|
||||
t.Errorf("failed to match imported string value %q with expected %q", pv, vv)
|
||||
}
|
||||
default:
|
||||
if pv != vv {
|
||||
t.Errorf("failed to match imported string value %q with expected %q", pv, vv)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package chartutil
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
|
@ -105,7 +106,10 @@ func tableLookup(v Values, simple string) (Values, error) {
|
|||
|
||||
// ReadValues will parse YAML byte data into a Values.
|
||||
func ReadValues(data []byte) (vals Values, err error) {
|
||||
err = yaml.Unmarshal(data, &vals)
|
||||
err = yaml.Unmarshal(data, &vals, func(d *json.Decoder) *json.Decoder {
|
||||
d.UseNumber()
|
||||
return d
|
||||
})
|
||||
if len(vals) == 0 {
|
||||
vals = Values{}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue