Merge pull request #30885 from helm/revert-13534-dev-v3-12987

Revert "fix (helm) : toToml` renders int as float [ backport to v3 ]"
pull/30899/head
Robert Sirchia 4 months ago committed by Reinhard Nägele
commit c3664f276f

@ -51,6 +51,7 @@ type repoAddOptions struct {
passCredentialsAll bool passCredentialsAll bool
forceUpdate bool forceUpdate bool
allowDeprecatedRepos bool allowDeprecatedRepos bool
timeout time.Duration
certFile string certFile string
keyFile string keyFile string
@ -99,6 +100,7 @@ func newRepoAddCmd(out io.Writer) *cobra.Command {
f.BoolVar(&o.insecureSkipTLSverify, "insecure-skip-tls-verify", false, "skip tls certificate checks for the repository") f.BoolVar(&o.insecureSkipTLSverify, "insecure-skip-tls-verify", false, "skip tls certificate checks for the repository")
f.BoolVar(&o.allowDeprecatedRepos, "allow-deprecated-repos", false, "by default, this command will not allow adding official repos that have been permanently deleted. This disables that behavior") f.BoolVar(&o.allowDeprecatedRepos, "allow-deprecated-repos", false, "by default, this command will not allow adding official repos that have been permanently deleted. This disables that behavior")
f.BoolVar(&o.passCredentialsAll, "pass-credentials", false, "pass credentials to all domains") f.BoolVar(&o.passCredentialsAll, "pass-credentials", false, "pass credentials to all domains")
f.DurationVar(&o.timeout, "timeout", getter.DefaultHTTPTimeout*time.Second, "time to wait for the index file download to complete")
return cmd return cmd
} }
@ -203,7 +205,7 @@ func (o *repoAddOptions) run(out io.Writer) error {
return nil return nil
} }
r, err := repo.NewChartRepository(&c, getter.All(settings)) r, err := repo.NewChartRepository(&c, getter.All(settings, getter.WithTimeout(o.timeout)))
if err != nil { if err != nil {
return err return err
} }

@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"io" "io"
"sync" "sync"
"time"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -46,6 +47,7 @@ type repoUpdateOptions struct {
repoCache string repoCache string
names []string names []string
failOnRepoUpdateFail bool failOnRepoUpdateFail bool
timeout time.Duration
} }
func newRepoUpdateCmd(out io.Writer) *cobra.Command { func newRepoUpdateCmd(out io.Writer) *cobra.Command {
@ -73,6 +75,7 @@ func newRepoUpdateCmd(out io.Writer) *cobra.Command {
// Adding this flag for Helm 3 as stop gap functionality for https://github.com/helm/helm/issues/10016. // Adding this flag for Helm 3 as stop gap functionality for https://github.com/helm/helm/issues/10016.
// This should be deprecated in Helm 4 by update to the behaviour of `helm repo update` command. // This should be deprecated in Helm 4 by update to the behaviour of `helm repo update` command.
f.BoolVar(&o.failOnRepoUpdateFail, "fail-on-repo-update-fail", false, "update fails if any of the repository updates fail") f.BoolVar(&o.failOnRepoUpdateFail, "fail-on-repo-update-fail", false, "update fails if any of the repository updates fail")
f.DurationVar(&o.timeout, "timeout", getter.DefaultHTTPTimeout*time.Second, "time to wait for the index file download to complete")
return cmd return cmd
} }
@ -100,7 +103,7 @@ func (o *repoUpdateOptions) run(out io.Writer) error {
for _, cfg := range f.Repositories { for _, cfg := range f.Repositories {
if updateAllRepos || isRepoRequested(cfg.Name, o.names) { if updateAllRepos || isRepoRequested(cfg.Name, o.names) {
r, err := repo.NewChartRepository(cfg, getter.All(settings)) r, err := repo.NewChartRepository(cfg, getter.All(settings, getter.WithTimeout(o.timeout)))
if err != nil { if err != nil {
return err return err
} }

@ -161,11 +161,6 @@ func TestTemplateCmd(t *testing.T) {
cmd: fmt.Sprintf("template '%s' -f %s/extra_values.yaml", chartPath, chartPath), cmd: fmt.Sprintf("template '%s' -f %s/extra_values.yaml", chartPath, chartPath),
golden: "output/template-subchart-cm-set-file.txt", 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) runTestCmd(t, tests)
} }

@ -1,8 +0,0 @@
---
# Source: issue-totoml/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: issue-totoml
data: |
key = 13

@ -1,3 +0,0 @@
apiVersion: v2
name: issue-totoml
version: 0.1.0

@ -1,6 +0,0 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: issue-totoml
data: |
{{ .Values.global | toToml }}

@ -18,7 +18,6 @@ package loader
import ( import (
"bytes" "bytes"
"encoding/json"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@ -105,10 +104,7 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
} }
case f.Name == "values.yaml": case f.Name == "values.yaml":
c.Values = make(map[string]interface{}) c.Values = make(map[string]interface{})
if err := yaml.Unmarshal(f.Data, &c.Values, func(d *json.Decoder) *json.Decoder { if err := yaml.Unmarshal(f.Data, &c.Values); err != nil {
d.UseNumber()
return d
}); err != nil {
return c, errors.Wrap(err, "cannot load values.yaml") return c, errors.Wrap(err, "cannot load values.yaml")
} }
case f.Name == "values.schema.json": case f.Name == "values.schema.json":

@ -15,7 +15,6 @@ limitations under the License.
package chartutil package chartutil
import ( import (
"encoding/json"
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
@ -238,20 +237,6 @@ func TestProcessDependencyImportValues(t *testing.T) {
if b := strconv.FormatBool(pv); b != vv { 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) 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: default:
if pv != vv { if pv != vv {
t.Errorf("failed to match imported string value %q with expected %q for key %q", pv, vv, kk) t.Errorf("failed to match imported string value %q with expected %q for key %q", pv, vv, kk)
@ -324,10 +309,6 @@ func TestProcessDependencyImportValuesMultiLevelPrecedence(t *testing.T) {
if s := strconv.FormatFloat(pv, 'f', -1, 64); s != vv { if s := strconv.FormatFloat(pv, 'f', -1, 64); s != vv {
t.Errorf("failed to match imported float value %v with expected %v", 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: default:
if pv != vv { if pv != vv {
t.Errorf("failed to match imported string value %q with expected %q", pv, vv) t.Errorf("failed to match imported string value %q with expected %q", pv, vv)

@ -17,7 +17,6 @@ limitations under the License.
package chartutil package chartutil
import ( import (
"encoding/json"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -106,10 +105,7 @@ func tableLookup(v Values, simple string) (Values, error) {
// ReadValues will parse YAML byte data into a Values. // ReadValues will parse YAML byte data into a Values.
func ReadValues(data []byte) (vals Values, err error) { func ReadValues(data []byte) (vals Values, err error) {
err = yaml.Unmarshal(data, &vals, func(d *json.Decoder) *json.Decoder { err = yaml.Unmarshal(data, &vals)
d.UseNumber()
return d
})
if len(vals) == 0 { if len(vals) == 0 {
vals = Values{} vals = Values{}
} }

@ -196,24 +196,32 @@ const (
var defaultOptions = []Option{WithTimeout(time.Second * DefaultHTTPTimeout)} var defaultOptions = []Option{WithTimeout(time.Second * DefaultHTTPTimeout)}
var httpProvider = Provider{ func Getters(extraOpts ...Option) Providers {
Schemes: []string{"http", "https"}, return Providers{
New: func(options ...Option) (Getter, error) { Provider{
options = append(options, defaultOptions...) Schemes: []string{"http", "https"},
return NewHTTPGetter(options...) New: func(options ...Option) (Getter, error) {
}, options = append(options, defaultOptions...)
} options = append(options, extraOpts...)
return NewHTTPGetter(options...)
var ociProvider = Provider{ },
Schemes: []string{registry.OCIScheme}, },
New: NewOCIGetter, Provider{
Schemes: []string{registry.OCIScheme},
New: func(options ...Option) (Getter, error) {
options = append(options, defaultOptions...)
options = append(options, extraOpts...)
return NewOCIGetter(options...)
},
},
}
} }
// All finds all of the registered getters as a list of Provider instances. // All finds all of the registered getters as a list of Provider instances.
// Currently, the built-in getters and the discovered plugins with downloader // Currently, the built-in getters and the discovered plugins with downloader
// notations are collected. // notations are collected.
func All(settings *cli.EnvSettings) Providers { func All(settings *cli.EnvSettings, opts ...Option) Providers {
result := Providers{httpProvider, ociProvider} result := Getters(opts...)
pluginDownloaders, _ := collectPlugins(settings) pluginDownloaders, _ := collectPlugins(settings)
result = append(result, pluginDownloaders...) result = append(result, pluginDownloaders...)
return result return result

@ -17,6 +17,7 @@ package getter
import ( import (
"testing" "testing"
"time"
"helm.sh/helm/v3/pkg/cli" "helm.sh/helm/v3/pkg/cli"
) )
@ -52,6 +53,23 @@ func TestProviders(t *testing.T) {
} }
} }
func TestProvidersWithTimeout(t *testing.T) {
want := time.Hour
getters := Getters(WithTimeout(want))
getter, err := getters.ByScheme("http")
if err != nil {
t.Error(err)
}
client, err := getter.(*HTTPGetter).httpClient()
if err != nil {
t.Error(err)
}
got := client.Timeout
if got != want {
t.Errorf("Expected %q, got %q", want, got)
}
}
func TestAll(t *testing.T) { func TestAll(t *testing.T) {
env := cli.New() env := cli.New()
env.PluginsDirectory = pluginDir env.PluginsDirectory = pluginDir

Loading…
Cancel
Save