bump: upgrade gopkg.in/yaml.v2 to gopkg.in/yaml.v3

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero 2022-09-28 07:58:19 +08:00
parent 2a7669f8fa
commit 14ba7cd156
19 changed files with 106 additions and 52 deletions

5
go.mod
View File

@ -7,7 +7,6 @@ require (
github.com/Masterminds/sprig/v3 v3.2.2
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a
github.com/davecgh/go-spew v1.1.1
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-test/deep v1.0.8
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.5.9
@ -31,7 +30,7 @@ require (
go.uber.org/zap v1.23.0
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools v2.2.0+incompatible
helm.sh/helm/v3 v3.10.0
k8s.io/apimachinery v0.25.2
@ -130,7 +129,6 @@ require (
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
gopkg.in/urfave/cli.v1 v1.20.0 // indirect
gopkg.in/yaml.v3 v3.0.1
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
@ -191,6 +189,7 @@ require (
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/api v0.25.0 // indirect
k8s.io/cli-runtime v0.25.0 // indirect
k8s.io/client-go v0.25.0 // indirect

2
go.sum
View File

@ -267,8 +267,6 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/fujiwara/tfstate-lookup v0.4.4 h1:HxVsq62Tk9W1RcbPPq7/c1s0Qd4bBFkccciFxMXZpLI=
github.com/fujiwara/tfstate-lookup v0.4.4/go.mod h1:WaSNeC69vL1r+l4YDFTyJJDR2BrYofJmiHZtEBAt82M=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew=
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I=
github.com/go-asn1-ber/asn1-ber v1.3.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0=
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=

View File

@ -4654,7 +4654,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"}}

View File

@ -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)
}

View File

@ -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"

View File

@ -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)
}

18
pkg/maputil/yamlutil.go Normal file
View File

@ -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
}

View File

@ -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))
}
}

View File

@ -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"

View File

@ -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

View File

@ -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 {

View File

@ -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)

View File

@ -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)
}

View File

@ -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"
)
@ -2659,7 +2660,7 @@ func (st *HelmState) RenderReleaseValuesFileToBytes(release *ReleaseSpec, path s
return nil, err
}
return yaml.Marshal(parsedYaml)
return maputil.YamlMarshal(parsedYaml)
}
return rawBytes, nil
@ -2826,7 +2827,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
}
@ -3067,7 +3068,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"`
@ -3228,7 +3229,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

View File

@ -4,7 +4,7 @@ import (
"fmt"
"reflect"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
"github.com/helmfile/helmfile/pkg/tmpl"
)

View File

@ -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
}

View File

@ -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) {

View File

@ -6,16 +6,16 @@ helmBinary: helm
environments:
default: {}
repositories:
- name: aservo
- name: aservo
url: https://aservo.github.io/charts
releases:
- chart: aservo/util
- chart: aservo/util
version: 0.0.1
name: default-shared-resources
namespace: default
labels:
service: shared-resources
- chart: aservo/util
- chart: aservo/util
version: 0.0.1
needs:
- default-shared-resources

View File

@ -10,7 +10,7 @@ import (
"github.com/kylelemons/godebug/pretty"
"github.com/logrusorgru/aurora"
"github.com/mattn/go-isatty"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"
)
var version = "latest"