Skip to content

Commit f6aa0ac

Browse files
dveedenxhebox
andauthored
Switch from yaml.v2 to yaml.v3 (#2558)
* Switch from yaml.v2 to yaml.v3 * Use KnownFields * Use KnowFields for a few more places that previously had UnmarshalStrict * Fix issues found by make check * Formatting differences in yaml * update * fix CI Signed-off-by: xhe <[email protected]> --------- Signed-off-by: xhe <[email protected]> Co-authored-by: xhe <[email protected]>
1 parent e446891 commit f6aa0ac

File tree

17 files changed

+48
-38
lines changed

17 files changed

+48
-38
lines changed

components/dm/ansible/import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"github.com/pingcap/tiup/pkg/utils"
3434
"github.com/relex/aini"
3535
"gopkg.in/ini.v1"
36-
"gopkg.in/yaml.v2"
36+
"gopkg.in/yaml.v3"
3737
)
3838

3939
// ref https://docs.ansible.com/ansible/latest/reference_appendices/config.html#the-configuration-file

components/dm/command/import.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/pingcap/tiup/pkg/tui"
2828
tiuputils "github.com/pingcap/tiup/pkg/utils"
2929
"github.com/spf13/cobra"
30-
"gopkg.in/yaml.v2"
30+
"gopkg.in/yaml.v3"
3131
)
3232

3333
func newImportCmd() *cobra.Command {

components/dm/spec/topology_dm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
"github.com/pingcap/tiup/pkg/cluster/spec"
2121
"github.com/stretchr/testify/require"
22-
"gopkg.in/yaml.v2"
22+
"gopkg.in/yaml.v3"
2323
)
2424

2525
func TestDefaultDataDir(t *testing.T) {

go.mod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ go 1.24
44

55
toolchain go1.24.1
66

7-
replace gopkg.in/yaml.v2 => github.com/july2993/yaml v0.0.0-20200423062752-adcfa5abe2ed
8-
97
require (
108
github.com/AstroProfundis/sysinfo v0.0.0-20240112160158-ed54df16e9ce
119
github.com/BurntSushi/toml v1.5.0
@@ -62,7 +60,6 @@ require (
6260
google.golang.org/grpc v1.67.3
6361
google.golang.org/protobuf v1.36.1
6462
gopkg.in/ini.v1 v1.67.0
65-
gopkg.in/yaml.v2 v2.4.0
6663
gopkg.in/yaml.v3 v3.0.1
6764
software.sslmate.com/src/go-pkcs12 v0.2.0
6865
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,6 @@ github.com/joomcode/errorx v1.1.0 h1:dizuSG6yHzlvXOOGHW00gwsmM4Sb9x/yWEfdtPztqcs
311311
github.com/joomcode/errorx v1.1.0/go.mod h1:eQzdtdlNyN7etw6YCS4W4+lu442waxZYw5yvz0ULrRo=
312312
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
313313
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
314-
github.com/july2993/yaml v0.0.0-20200423062752-adcfa5abe2ed h1:4dMu41sJad3+E9AMc2hCimGhll184HfPKdu05R6YJtc=
315-
github.com/july2993/yaml v0.0.0-20200423062752-adcfa5abe2ed/go.mod h1:7FtNkxNa9xDptPhcc7mWT/Ov++hkuMU/NKtgkPZPUwo=
316314
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
317315
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
318316
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
@@ -685,6 +683,8 @@ gopkg.in/jcmturner/gokrb5.v6 v6.1.1 h1:n0KFjpbuM5pFMN38/Ay+Br3l91netGSVqHPHEXeWU
685683
gopkg.in/jcmturner/gokrb5.v6 v6.1.1/go.mod h1:NFjHNLrHQiruory+EmqDXCGv6CrjkeYeA+bR9mIfNFk=
686684
gopkg.in/jcmturner/rpc.v1 v1.1.0 h1:QHIUxTX1ISuAv9dD2wJ9HWQVuWDX/Zc0PfeC2tjc4rU=
687685
gopkg.in/jcmturner/rpc.v1 v1.1.0/go.mod h1:YIdkC4XfD6GXbzje11McwsDuOlZQSb9W4vfLvuNnlv8=
686+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
687+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
688688
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
689689
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
690690
gopkg.in/yaml.v3 v3.0.0-20220512140231-539c8e751b99/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pkg/cluster/ansible/inventory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/pingcap/tiup/pkg/tidbver"
2828
"github.com/relex/aini"
2929
"gopkg.in/ini.v1"
30-
"gopkg.in/yaml.v2"
30+
"gopkg.in/yaml.v3"
3131
)
3232

3333
var (

pkg/cluster/manager/edit_config.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/pingcap/tiup/pkg/meta"
2828
"github.com/pingcap/tiup/pkg/tui"
2929
"github.com/pingcap/tiup/pkg/utils"
30-
"gopkg.in/yaml.v2"
30+
"gopkg.in/yaml.v3"
3131
)
3232

3333
// EditConfigOptions contains the options for config edition.
@@ -113,7 +113,9 @@ func (m *Manager) editTopo(origTopo spec.Topology, data []byte, opt EditConfigOp
113113
}
114114

115115
newTopo := m.specManager.NewMetadata().GetTopology()
116-
err = yaml.UnmarshalStrict(newData, newTopo)
116+
decoder := yaml.NewDecoder(bytes.NewReader(newData))
117+
decoder.KnownFields(true)
118+
err = decoder.Decode(newTopo)
117119
if err != nil {
118120
fmt.Print(color.RedString("New topology could not be saved: "))
119121
m.logger.Infof("Failed to parse topology file: %v", err)

pkg/cluster/manager/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/pingcap/tiup/pkg/cluster/spec"
2020
"github.com/stretchr/testify/assert"
2121
"github.com/stretchr/testify/require"
22-
"gopkg.in/yaml.v2"
22+
"gopkg.in/yaml.v3"
2323
)
2424

2525
func TestVersionCompare(t *testing.T) {

pkg/cluster/manager/show_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
perrs "github.com/pingcap/errors"
2121
"github.com/pingcap/tiup/pkg/cluster/clusterutil"
2222
"github.com/pingcap/tiup/pkg/meta"
23-
"gopkg.in/yaml.v2"
23+
"gopkg.in/yaml.v3"
2424
)
2525

2626
// ShowConfig shows the cluster's config.

pkg/cluster/spec/parse_topology.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package spec
1515

1616
import (
17+
"bytes"
1718
"os"
1819
"path"
1920
"reflect"
@@ -23,7 +24,7 @@ import (
2324
"github.com/pingcap/tiup/pkg/tui"
2425
"github.com/pingcap/tiup/pkg/utils"
2526
"go.uber.org/zap"
26-
"gopkg.in/yaml.v2"
27+
"gopkg.in/yaml.v3"
2728
)
2829

2930
var (
@@ -86,7 +87,9 @@ func ParseTopologyYaml(file string, out Topology, ignoreGlobal ...bool) error {
8687
yamlFile, _ = yaml.Marshal(newTopo)
8788
}
8889

89-
if err = yaml.UnmarshalStrict(yamlFile, out); err != nil {
90+
decoder := yaml.NewDecoder(bytes.NewReader(yamlFile))
91+
decoder.KnownFields(true)
92+
if err = decoder.Decode(out); err != nil {
9093
return ErrTopologyParseFailed.
9194
Wrap(err, "Failed to parse topology file %s", file).
9295
WithProperty(tui.SuggestionFromTemplate(`

0 commit comments

Comments
 (0)