Skip to content

Commit 8df27aa

Browse files
authored
Upgrade gopkg.in/yaml.v2 to go.yaml.in/yaml/v3 (#2023)
* chore: upgrade gopkg.in/yaml from v2 to v3 Signed-off-by: Chiman Jain <chimanjain15@gmail.com> * refactor: update indent to 2 with yaml.v3 and fix minor test inconsistencies Signed-off-by: Chiman Jain <chimanjain15@gmail.com> * chore: migrate gopkg.in.yaml.v3 dependency to go.yaml.in/yaml/v3 Signed-off-by: Chiman Jain <chimanjain15@gmail.com> * chore: run go mod tidy after rebase Signed-off-by: Chiman Jain <chimanjain15@gmail.com> * fix: address review comments Signed-off-by: Chiman Jain <chimanjain15@gmail.com> --------- Signed-off-by: Chiman Jain <chimanjain15@gmail.com>
1 parent f470500 commit 8df27aa

9 files changed

Lines changed: 27 additions & 18 deletions

File tree

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ require (
3535
go.etcd.io/bbolt v1.5.0
3636
go.podman.io/common v0.68.1
3737
go.podman.io/image/v5 v5.40.0
38+
go.yaml.in/yaml/v3 v3.0.4
3839
golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f
3940
golang.org/x/mod v0.38.0
4041
golang.org/x/sync v0.22.0
@@ -43,7 +44,6 @@ require (
4344
google.golang.org/grpc v1.82.0
4445
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.6.2
4546
google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af
46-
gopkg.in/yaml.v2 v2.4.0
4747
k8s.io/api v0.36.2
4848
k8s.io/apiextensions-apiserver v0.36.2
4949
k8s.io/apimachinery v0.36.2
@@ -201,7 +201,6 @@ require (
201201
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
202202
go.podman.io/storage v1.63.0 // indirect
203203
go.yaml.in/yaml/v2 v2.4.3 // indirect
204-
go.yaml.in/yaml/v3 v3.0.4 // indirect
205204
golang.org/x/crypto v0.53.0 // indirect
206205
golang.org/x/net v0.56.0 // indirect
207206
golang.org/x/oauth2 v0.36.0 // indirect
@@ -214,6 +213,7 @@ require (
214213
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
215214
gopkg.in/inf.v0 v0.9.1 // indirect
216215
gopkg.in/warnings.v0 v0.1.2 // indirect
216+
gopkg.in/yaml.v2 v2.4.0 // indirect
217217
gopkg.in/yaml.v3 v3.0.1 // indirect
218218
k8s.io/apiserver v0.36.2 // indirect
219219
k8s.io/cli-runtime v0.36.1 // indirect

pkg/lib/bundle/chartutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"path/filepath"
2424

2525
"github.com/pkg/errors"
26-
"gopkg.in/yaml.v2"
26+
"go.yaml.in/yaml/v3"
2727
)
2828

2929
// Maintainer describes a Chart maintainer.

pkg/lib/bundle/generate.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package bundle
22

33
import (
4+
"bytes"
45
"fmt"
56
"io"
67
"os"
78
"path/filepath"
89
"strings"
910

1011
log "github.com/sirupsen/logrus"
11-
"gopkg.in/yaml.v2"
12+
"go.yaml.in/yaml/v3"
1213
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1314
utilerrors "k8s.io/apimachinery/pkg/util/errors"
1415
k8syaml "k8s.io/apimachinery/pkg/util/yaml"
@@ -315,12 +316,17 @@ func GenerateAnnotations(mediaType, manifests, metadata, packageName, channels,
315316
annotations.Annotations[ChannelDefaultLabel] = channelDefault
316317
}
317318

318-
afile, err := yaml.Marshal(annotations)
319-
if err != nil {
319+
var buf bytes.Buffer
320+
encoder := yaml.NewEncoder(&buf)
321+
encoder.SetIndent(2)
322+
if err := encoder.Encode(annotations); err != nil {
323+
return nil, err
324+
}
325+
if err := encoder.Close(); err != nil {
320326
return nil, err
321327
}
322328

323-
return afile, nil
329+
return buf.Bytes(), nil
324330
}
325331

326332
// GenerateDockerfile builds Dockerfile with mediatype, manifests &

pkg/lib/bundle/generate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"testing"
88

99
"github.com/stretchr/testify/require"
10-
"gopkg.in/yaml.v2"
10+
"go.yaml.in/yaml/v3"
1111
)
1212

1313
func TestGetMediaType(t *testing.T) {

pkg/lib/bundle/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"os"
55
"path/filepath"
66

7-
"gopkg.in/yaml.v2"
7+
"go.yaml.in/yaml/v3"
88
)
99

1010
const (

pkg/lib/bundle/validate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestValidateBundleDependencies(t *testing.T) {
3030
logger: logger,
3131
}
3232

33-
var table = []struct {
33+
table := []struct {
3434
description string
3535
mediaType string
3636
directory string
@@ -108,7 +108,7 @@ func TestValidateBundleContent(t *testing.T) {
108108
logger: logger,
109109
}
110110

111-
var table = []struct {
111+
table := []struct {
112112
description string
113113
mediaType string
114114
directory string

pkg/lib/indexer/indexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"sync"
1414

1515
"github.com/sirupsen/logrus"
16-
"gopkg.in/yaml.v2"
16+
"go.yaml.in/yaml/v3"
1717
utilerrors "k8s.io/apimachinery/pkg/util/errors"
1818

1919
"github.com/operator-framework/operator-registry/pkg/containertools"

pkg/prettyunmarshaler/prettyunmarshaler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ func TestJsonUnmarshalError(t *testing.T) {
149149
//
150150
// If the data does not cause a syntax error, this function will panic.
151151
func customOffsetSyntaxError(data []byte, offset int64) *json.SyntaxError {
152-
var d *byte = nil
152+
var d byte
153153
var se *json.SyntaxError
154-
err := json.Unmarshal(data, d)
154+
err := json.Unmarshal(data, &d)
155155
if errors.As(err, &se) {
156156
se.Offset = offset
157157
return se

pkg/sqlite/directory_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/otiai10/copy"
1010
"github.com/sirupsen/logrus"
1111
"github.com/stretchr/testify/require"
12-
"gopkg.in/yaml.v2"
12+
"go.yaml.in/yaml/v3"
1313

1414
"github.com/operator-framework/operator-registry/pkg/api"
1515
"github.com/operator-framework/operator-registry/pkg/registry"
@@ -206,13 +206,16 @@ func TestQuerierForDirectory(t *testing.T) {
206206
{"etcd", "stable", "etcdoperator.v0.6.1", ""},
207207
{"etcd", "stable", "etcdoperator.v0.9.0", "etcdoperator.v0.6.1"},
208208
{"etcd", "stable", "etcdoperator.v0.9.2", "etcdoperator.v0.9.1"},
209-
{"etcd", "stable", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"}}, etcdChannelEntriesThatProvide)
209+
{"etcd", "stable", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"},
210+
}, etcdChannelEntriesThatProvide)
210211

211212
etcdLatestChannelEntriesThatProvide, err := store.GetLatestChannelEntriesThatProvide(context.TODO(), "etcd.database.coreos.com", "v1beta2", "EtcdCluster")
212213
require.NoError(t, err)
213-
require.ElementsMatch(t, []*registry.ChannelEntry{{"etcd", "alpha", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"},
214+
require.ElementsMatch(t, []*registry.ChannelEntry{
215+
{"etcd", "alpha", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"},
214216
{"etcd", "beta", "etcdoperator.v0.9.0", "etcdoperator.v0.6.1"},
215-
{"etcd", "stable", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"}}, etcdLatestChannelEntriesThatProvide)
217+
{"etcd", "stable", "etcdoperator.v0.9.2", "etcdoperator.v0.9.0"},
218+
}, etcdLatestChannelEntriesThatProvide)
216219

217220
etcdBundleByProvides, err := store.GetBundleThatProvides(context.TODO(), "etcd.database.coreos.com", "v1beta2", "EtcdCluster")
218221
require.NoError(t, err)

0 commit comments

Comments
 (0)