mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-18 06:56:49 +02:00
Merge pull request #396 from helmfile/bump_yaml_v3
bump: upgrade gopkg.in/yaml.v2 to gopkg.in/yaml.v3
This commit is contained in:
+1
-1
@@ -4660,7 +4660,7 @@ releases:
|
||||
}
|
||||
expectedValues := []interface{}{
|
||||
map[interface{}]interface{}{"val1": "zipkin"},
|
||||
map[interface{}]interface{}{"val2": "val2"}}
|
||||
map[string]interface{}{"val2": "val2"}}
|
||||
expectedSetValues := []state.SetValue{
|
||||
{Name: "name-zipkin", Value: "val-zipkin"},
|
||||
{Name: "name", Value: "val"}}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"gopkg.in/yaml.v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/helmfile/helmfile/pkg/maputil"
|
||||
"github.com/helmfile/helmfile/pkg/state"
|
||||
)
|
||||
|
||||
@@ -21,7 +22,7 @@ type LoadOpts struct {
|
||||
}
|
||||
|
||||
func (o LoadOpts) DeepCopy() LoadOpts {
|
||||
bytes, err := yaml.Marshal(o)
|
||||
bytes, err := maputil.YamlMarshal(o)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/helmfile/helmfile/pkg/helmexec"
|
||||
"github.com/helmfile/helmfile/pkg/remote"
|
||||
|
||||
@@ -2,7 +2,7 @@ package environment
|
||||
|
||||
import (
|
||||
"github.com/imdario/mergo"
|
||||
"gopkg.in/yaml.v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/helmfile/helmfile/pkg/maputil"
|
||||
)
|
||||
@@ -16,7 +16,7 @@ type Environment struct {
|
||||
var EmptyEnvironment Environment
|
||||
|
||||
func (e Environment) DeepCopy() Environment {
|
||||
valuesBytes, err := yaml.Marshal(e.Values)
|
||||
valuesBytes, err := maputil.YamlMarshal(e.Values)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -29,7 +29,7 @@ func (e Environment) DeepCopy() Environment {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defaultsBytes, err := yaml.Marshal(e.Defaults)
|
||||
defaultsBytes, err := maputil.YamlMarshal(e.Defaults)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package maputil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func YamlMarshal(v interface{}) ([]byte, error) {
|
||||
var b bytes.Buffer
|
||||
yamlEncoder := yaml.NewEncoder(&b)
|
||||
yamlEncoder.SetIndent(2)
|
||||
err := yamlEncoder.Encode(v)
|
||||
defer func() {
|
||||
_ = yamlEncoder.Close()
|
||||
}()
|
||||
return b.Bytes(), err
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package maputil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestYamlMarshal(t *testing.T) {
|
||||
tests := []struct {
|
||||
Name string `yaml:"name"`
|
||||
Info []struct {
|
||||
Age int `yaml:"age"`
|
||||
Address string `yaml:"address"`
|
||||
} `yaml:"info"`
|
||||
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
Name: "John",
|
||||
Info: []struct {
|
||||
Age int `yaml:"age"`
|
||||
Address string `yaml:"address"`
|
||||
}{{Age: 20, Address: "New York"}},
|
||||
expected: "name: John\ninfo:\n - age: 20\n address: New York\n",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
actual, err := YamlMarshal(tt)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tt.expected, string(actual))
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/hashicorp/go-getter/helper/url"
|
||||
"go.uber.org/multierr"
|
||||
"go.uber.org/zap"
|
||||
"gopkg.in/yaml.v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/helmfile/helmfile/pkg/envvar"
|
||||
"github.com/helmfile/helmfile/pkg/filesystem"
|
||||
|
||||
@@ -11,10 +11,11 @@ import (
|
||||
goversion "github.com/hashicorp/go-version"
|
||||
"github.com/r3labs/diff"
|
||||
"go.uber.org/zap"
|
||||
"gopkg.in/yaml.v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/helmfile/helmfile/pkg/app/version"
|
||||
"github.com/helmfile/helmfile/pkg/helmexec"
|
||||
"github.com/helmfile/helmfile/pkg/maputil"
|
||||
)
|
||||
|
||||
type ChartMeta struct {
|
||||
@@ -299,7 +300,7 @@ func (m *chartDependencyManager) updateHelm3(shell helmexec.DependencyUpdater, w
|
||||
chartMetaContent := fmt.Sprintf("name: %s\nversion: 1.0.0\napiVersion: v2\n", m.Name)
|
||||
|
||||
// Generate `requirements.yaml` of the temporary local chart from the helmfile state
|
||||
reqsContent, err := yaml.Marshal(unresolved.ToChartRequirements())
|
||||
reqsContent, err := maputil.YamlMarshal(unresolved.ToChartRequirements())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -317,7 +318,7 @@ func (m *chartDependencyManager) updateHelm2(shell helmexec.DependencyUpdater, w
|
||||
}
|
||||
|
||||
// Generate `requirements.yaml` of the temporary local chart from the helmfile state
|
||||
reqsContent, err := yaml.Marshal(unresolved.ToChartRequirements())
|
||||
reqsContent, err := maputil.YamlMarshal(unresolved.ToChartRequirements())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -383,7 +384,7 @@ func (m *chartDependencyManager) doUpdate(chartLockFile string, unresolved *Unre
|
||||
|
||||
lockedReqs.Version = version.Version
|
||||
|
||||
updatedLockFileContent, err = yaml.Marshal(lockedReqs)
|
||||
updatedLockFileContent, err = maputil.YamlMarshal(lockedReqs)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/variantdev/vals"
|
||||
"go.uber.org/zap"
|
||||
"gopkg.in/yaml.v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/helmfile/helmfile/pkg/environment"
|
||||
"github.com/helmfile/helmfile/pkg/filesystem"
|
||||
@@ -86,7 +86,7 @@ func (c *StateCreator) Parse(content []byte, baseDir, file string) (*HelmState,
|
||||
|
||||
decoder := yaml.NewDecoder(bytes.NewReader(content))
|
||||
|
||||
decoder.SetStrict(c.Strict)
|
||||
decoder.KnownFields(c.Strict)
|
||||
|
||||
i := 0
|
||||
for {
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/imdario/mergo"
|
||||
"go.uber.org/zap"
|
||||
"gopkg.in/yaml.v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/helmfile/helmfile/pkg/environment"
|
||||
"github.com/helmfile/helmfile/pkg/filesystem"
|
||||
@@ -79,7 +79,7 @@ func (ld *EnvironmentValuesLoader) LoadEnvironmentValues(missingFileHandler *str
|
||||
ld.logger.Debugf("envvals_loader: loaded %s:%v", strOrMap, m)
|
||||
}
|
||||
}
|
||||
case map[interface{}]interface{}:
|
||||
case map[interface{}]interface{}, map[string]interface{}:
|
||||
maps = append(maps, strOrMap)
|
||||
default:
|
||||
return nil, fmt.Errorf("unexpected type of value: value=%v, type=%T", strOrMap, strOrMap)
|
||||
|
||||
@@ -3,8 +3,9 @@ package state
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/helmfile/helmfile/pkg/maputil"
|
||||
"github.com/helmfile/helmfile/pkg/tmpl"
|
||||
)
|
||||
|
||||
@@ -97,8 +98,8 @@ func (r ReleaseSpec) ExecuteTemplateExpressions(renderer *tmpl.FileRenderer) (*R
|
||||
if len(result.ValuesTemplate) > 0 {
|
||||
for i, t := range result.ValuesTemplate {
|
||||
switch ts := t.(type) {
|
||||
case map[interface{}]interface{}:
|
||||
serialized, err := yaml.Marshal(ts)
|
||||
case map[interface{}]interface{}, map[string]interface{}:
|
||||
serialized, err := maputil.YamlMarshal(ts)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed executing template expressions in release \"%s\".values[%d] = \"%v\": %v", r.Name, i, ts, err)
|
||||
}
|
||||
@@ -201,7 +202,7 @@ func (r ReleaseSpec) ExecuteTemplateExpressions(renderer *tmpl.FileRenderer) (*R
|
||||
}
|
||||
|
||||
func (r ReleaseSpec) Clone() (*ReleaseSpec, error) {
|
||||
serialized, err := yaml.Marshal(r)
|
||||
serialized, err := maputil.YamlMarshal(r)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed cloning release \"%s\": %v", r.Name, err)
|
||||
}
|
||||
|
||||
+6
-5
@@ -22,12 +22,13 @@ import (
|
||||
"github.com/variantdev/chartify"
|
||||
"github.com/variantdev/vals"
|
||||
"go.uber.org/zap"
|
||||
"gopkg.in/yaml.v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/helmfile/helmfile/pkg/environment"
|
||||
"github.com/helmfile/helmfile/pkg/event"
|
||||
"github.com/helmfile/helmfile/pkg/filesystem"
|
||||
"github.com/helmfile/helmfile/pkg/helmexec"
|
||||
"github.com/helmfile/helmfile/pkg/maputil"
|
||||
"github.com/helmfile/helmfile/pkg/remote"
|
||||
"github.com/helmfile/helmfile/pkg/tmpl"
|
||||
)
|
||||
@@ -2663,7 +2664,7 @@ func (st *HelmState) RenderReleaseValuesFileToBytes(release *ReleaseSpec, path s
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return yaml.Marshal(parsedYaml)
|
||||
return maputil.YamlMarshal(parsedYaml)
|
||||
}
|
||||
|
||||
return rawBytes, nil
|
||||
@@ -2830,7 +2831,7 @@ func (st *HelmState) generateSecretValuesFiles(helm helmexec.Interface, release
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
bs, err := yaml.Marshal(value)
|
||||
bs, err := maputil.YamlMarshal(value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -3071,7 +3072,7 @@ func (hf *SubHelmfileSpec) UnmarshalYAML(unmarshal func(interface{}) error) erro
|
||||
switch i := tmp.(type) {
|
||||
case string: // single path definition without sub items, legacy sub helmfile definition
|
||||
hf.Path = i
|
||||
case map[interface{}]interface{}: // helmfile path with sub section
|
||||
case map[interface{}]interface{}, map[string]interface{}: // helmfile path with sub section
|
||||
var subHelmfileSpecTmp struct {
|
||||
Path string `yaml:"path"`
|
||||
Selectors []string `yaml:"selectors"`
|
||||
@@ -3232,7 +3233,7 @@ func (st *HelmState) GenerateOutputFilePath(release *ReleaseSpec, outputFileTemp
|
||||
}
|
||||
|
||||
func (st *HelmState) ToYaml() (string, error) {
|
||||
if result, err := yaml.Marshal(st); err != nil {
|
||||
if result, err := maputil.YamlMarshal(st); err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
return string(result), nil
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/helmfile/helmfile/pkg/tmpl"
|
||||
)
|
||||
|
||||
@@ -13,11 +13,12 @@ import (
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"github.com/helmfile/helmfile/pkg/envvar"
|
||||
"github.com/helmfile/helmfile/pkg/helmexec"
|
||||
"github.com/helmfile/helmfile/pkg/maputil"
|
||||
)
|
||||
|
||||
type Values = map[string]interface{}
|
||||
@@ -278,7 +279,7 @@ func (c *Context) Tpl(text string, data interface{}) (string, error) {
|
||||
}
|
||||
|
||||
func ToYaml(v interface{}) (string, error) {
|
||||
data, err := yaml.Marshal(v)
|
||||
data, err := maputil.YamlMarshal(v)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ func TestReadFile_PassAbsPath(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestToYaml_UnsupportedNestedMapKey(t *testing.T) {
|
||||
expected := ``
|
||||
expected := "foo:\n bar: BAR\n"
|
||||
// nolint: unconvert
|
||||
vals := Values(map[string]interface{}{
|
||||
"foo": map[interface{}]interface{}{
|
||||
@@ -186,8 +186,8 @@ func TestToYaml_UnsupportedNestedMapKey(t *testing.T) {
|
||||
},
|
||||
})
|
||||
actual, err := ToYaml(vals)
|
||||
require.Error(t, err, "error marshaling into JSON: json: unsupported type: map[interface {}]interface {}")
|
||||
require.Equal(t, expected, actual)
|
||||
require.NoError(t, err, "expected nil, but got: %v, when type: map[interface {}]interface {}", err)
|
||||
}
|
||||
|
||||
func TestToYaml(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user