From 42a7ea6d337a2fecc9162676407aa94e6a2b1f1e Mon Sep 17 00:00:00 2001 From: rohitsardesai83 Date: Sun, 28 Apr 2019 12:06:37 +0530 Subject: [PATCH] etcd: Replace ghodss/yaml with sigs.k8s.io/yaml To remove the dependency on ghodss/yaml. Replaced this dependency with sigs.k8s.io/yaml. This wil help to remove the ghodss/yaml dependency from main kubernetes repository. xref: https://github.com/kubernetes/kubernetes/issues/77024 --- bill-of-materials.json | 18 ++++----- bill-of-materials.override.json | 4 +- clientv3/yaml/config.go | 2 +- clientv3/yaml/config_test.go | 2 +- embed/config.go | 2 +- embed/config_test.go | 2 +- etcdmain/config.go | 2 +- etcdmain/config_test.go | 2 +- go.mod | 2 +- go.sum | 4 +- .../ghodss => sigs.k8s.io}/yaml/LICENSE | 0 .../ghodss => sigs.k8s.io}/yaml/fields.go | 1 + .../ghodss => sigs.k8s.io}/yaml/yaml.go | 39 ++++++++----------- .../ghodss => sigs.k8s.io}/yaml/yaml_go110.go | 0 14 files changed, 37 insertions(+), 43 deletions(-) rename vendor/{github.com/ghodss => sigs.k8s.io}/yaml/LICENSE (100%) rename vendor/{github.com/ghodss => sigs.k8s.io}/yaml/fields.go (99%) rename vendor/{github.com/ghodss => sigs.k8s.io}/yaml/yaml.go (88%) rename vendor/{github.com/ghodss => sigs.k8s.io}/yaml/yaml_go110.go (100%) diff --git a/bill-of-materials.json b/bill-of-materials.json index 3f8d91091d3..da2d27fde49 100644 --- a/bill-of-materials.json +++ b/bill-of-materials.json @@ -62,15 +62,6 @@ } ] }, - { - "project": "github.com/ghodss/yaml", - "licenses": [ - { - "type": "MIT License and BSD 3-clause \"New\" or \"Revised\" License", - "confidence": 1 - } - ] - }, { "project": "github.com/gogo/protobuf", "licenses": [ @@ -452,5 +443,14 @@ "confidence": 0.8975609756097561 } ] + }, + { + "project": "sigs.k8s.io/yaml", + "licenses": [ + { + "type": "BSD 3-clause \"New\" or \"Revised\" License", + "confidence": 1 + } + ] } ] diff --git a/bill-of-materials.override.json b/bill-of-materials.override.json index d766cad2bce..15afc56409d 100644 --- a/bill-of-materials.override.json +++ b/bill-of-materials.override.json @@ -1,9 +1,9 @@ [ { - "project": "github.com/ghodss/yaml", + "project": "sigs.k8s.io/yaml", "licenses": [ { - "type": "MIT License and BSD 3-clause \"New\" or \"Revised\" License" + "type": "BSD 3-clause \"New\" or \"Revised\" License" } ] }, diff --git a/clientv3/yaml/config.go b/clientv3/yaml/config.go index bdf038482b9..17390f9cbda 100644 --- a/clientv3/yaml/config.go +++ b/clientv3/yaml/config.go @@ -20,7 +20,7 @@ import ( "crypto/x509" "io/ioutil" - "github.com/ghodss/yaml" + "sigs.k8s.io/yaml" "go.etcd.io/etcd/v3/clientv3" "go.etcd.io/etcd/v3/pkg/tlsutil" diff --git a/clientv3/yaml/config_test.go b/clientv3/yaml/config_test.go index bcf28b43457..7a8f71280ac 100644 --- a/clientv3/yaml/config_test.go +++ b/clientv3/yaml/config_test.go @@ -21,7 +21,7 @@ import ( "reflect" "testing" - "github.com/ghodss/yaml" + "sigs.k8s.io/yaml" ) var ( diff --git a/embed/config.go b/embed/config.go index d026ebb1ec9..7af64a39f98 100644 --- a/embed/config.go +++ b/embed/config.go @@ -36,12 +36,12 @@ import ( "go.etcd.io/etcd/v3/pkg/transport" "go.etcd.io/etcd/v3/pkg/types" - "github.com/ghodss/yaml" bolt "go.etcd.io/bbolt" "go.uber.org/zap" "go.uber.org/zap/zapcore" "golang.org/x/crypto/bcrypt" "google.golang.org/grpc" + "sigs.k8s.io/yaml" ) const ( diff --git a/embed/config_test.go b/embed/config_test.go index 62c61cd3a02..6482486467c 100644 --- a/embed/config_test.go +++ b/embed/config_test.go @@ -24,7 +24,7 @@ import ( "go.etcd.io/etcd/v3/pkg/transport" - "github.com/ghodss/yaml" + "sigs.k8s.io/yaml" ) func TestConfigFileOtherFields(t *testing.T) { diff --git a/etcdmain/config.go b/etcdmain/config.go index 974475c1273..e70f7df1b9c 100644 --- a/etcdmain/config.go +++ b/etcdmain/config.go @@ -31,8 +31,8 @@ import ( "go.etcd.io/etcd/v3/pkg/types" "go.etcd.io/etcd/v3/version" - "github.com/ghodss/yaml" "go.uber.org/zap" + "sigs.k8s.io/yaml" ) var ( diff --git a/etcdmain/config_test.go b/etcdmain/config_test.go index 91ed7dfd824..bfe28c3c47c 100644 --- a/etcdmain/config_test.go +++ b/etcdmain/config_test.go @@ -23,8 +23,8 @@ import ( "strings" "testing" - "github.com/ghodss/yaml" "go.etcd.io/etcd/v3/embed" + "sigs.k8s.io/yaml" ) func TestConfigParsingMemberFlags(t *testing.T) { diff --git a/go.mod b/go.mod index 0e8a8b7e6fc..dce9a583d83 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4 github.com/fatih/color v1.7.0 // indirect - github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 github.com/gogo/protobuf v1.0.0 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903 @@ -60,4 +59,5 @@ require ( gopkg.in/cheggaaa/pb.v1 v1.0.25 gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect gopkg.in/yaml.v2 v2.2.2 + sigs.k8s.io/yaml v1.1.0 ) diff --git a/go.sum b/go.sum index 270c485cf62..312d050418a 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,6 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -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/gogo/protobuf v1.0.0 h1:2jyBKDKU/8v3v2xVR2PtiWQviFUyiaGk2rpfyFT8rTM= github.com/gogo/protobuf v1.0.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= @@ -135,3 +133,5 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= +sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/vendor/github.com/ghodss/yaml/LICENSE b/vendor/sigs.k8s.io/yaml/LICENSE similarity index 100% rename from vendor/github.com/ghodss/yaml/LICENSE rename to vendor/sigs.k8s.io/yaml/LICENSE diff --git a/vendor/github.com/ghodss/yaml/fields.go b/vendor/sigs.k8s.io/yaml/fields.go similarity index 99% rename from vendor/github.com/ghodss/yaml/fields.go rename to vendor/sigs.k8s.io/yaml/fields.go index 58600740266..235b7f2cf61 100644 --- a/vendor/github.com/ghodss/yaml/fields.go +++ b/vendor/sigs.k8s.io/yaml/fields.go @@ -1,6 +1,7 @@ // Copyright 2013 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. + package yaml import ( diff --git a/vendor/github.com/ghodss/yaml/yaml.go b/vendor/sigs.k8s.io/yaml/yaml.go similarity index 88% rename from vendor/github.com/ghodss/yaml/yaml.go rename to vendor/sigs.k8s.io/yaml/yaml.go index dfd264d6c5e..024596112ac 100644 --- a/vendor/github.com/ghodss/yaml/yaml.go +++ b/vendor/sigs.k8s.io/yaml/yaml.go @@ -1,14 +1,4 @@ -// Package yaml provides a wrapper around go-yaml designed to enable a better -// way of handling YAML when marshaling to and from structs. -// -// In short, this package first converts YAML to JSON using go-yaml and then -// uses json.Marshal and json.Unmarshal to convert to or from the struct. This -// means that it effectively reuses the JSON struct tags as well as the custom -// JSON methods MarshalJSON and UnmarshalJSON unlike go-yaml. -// -// See also http://ghodss.com/2014/the-right-way-to-handle-yaml-in-golang -// -package yaml // import "github.com/ghodss/yaml" +package yaml import ( "bytes" @@ -21,7 +11,7 @@ import ( "gopkg.in/yaml.v2" ) -// Marshals the object into JSON then converts JSON to YAML and returns the +// Marshal marshals the object into JSON then converts JSON to YAML and returns the // YAML. func Marshal(o interface{}) ([]byte, error) { j, err := json.Marshal(o) @@ -43,19 +33,24 @@ type JSONOpt func(*json.Decoder) *json.Decoder // Unmarshal converts YAML to JSON then uses JSON to unmarshal into an object, // optionally configuring the behavior of the JSON unmarshal. func Unmarshal(y []byte, o interface{}, opts ...JSONOpt) error { - return unmarshal(yaml.Unmarshal, y, o, opts) + return yamlUnmarshal(y, o, false, opts...) } -// UnmarshalStrict is like Unmarshal except that any mapping keys that are -// duplicates will result in an error. -// To also be strict about unknown fields, add the DisallowUnknownFields option. +// UnmarshalStrict strictly converts YAML to JSON then uses JSON to unmarshal +// into an object, optionally configuring the behavior of the JSON unmarshal. func UnmarshalStrict(y []byte, o interface{}, opts ...JSONOpt) error { - return unmarshal(yaml.UnmarshalStrict, y, o, opts) + return yamlUnmarshal(y, o, true, append(opts, DisallowUnknownFields)...) } -func unmarshal(f func(in []byte, out interface{}) (err error), y []byte, o interface{}, opts []JSONOpt) error { +// yamlUnmarshal unmarshals the given YAML byte stream into the given interface, +// optionally performing the unmarshalling strictly +func yamlUnmarshal(y []byte, o interface{}, strict bool, opts ...JSONOpt) error { vo := reflect.ValueOf(o) - j, err := yamlToJSON(y, &vo, f) + unmarshalFn := yaml.Unmarshal + if strict { + unmarshalFn = yaml.UnmarshalStrict + } + j, err := yamlToJSON(y, &vo, unmarshalFn) if err != nil { return fmt.Errorf("error converting YAML to JSON: %v", err) } @@ -83,7 +78,7 @@ func jsonUnmarshal(r io.Reader, o interface{}, opts ...JSONOpt) error { return nil } -// Convert JSON to YAML. +// JSONToYAML Converts JSON to YAML. func JSONToYAML(j []byte) ([]byte, error) { // Convert the JSON to an object. var jsonObj interface{} @@ -134,7 +129,7 @@ func yamlToJSON(y []byte, jsonTarget *reflect.Value, yamlUnmarshal func([]byte, // YAML objects are not completely compatible with JSON objects (e.g. you // can have non-string keys in YAML). So, convert the YAML-compatible object // to a JSON-compatible object, failing with an error if irrecoverable - // incompatibilities happen along the way. + // incompatibilties happen along the way. jsonObj, err := convertToJSONableObject(yamlObj, jsonTarget) if err != nil { return nil, err @@ -321,6 +316,4 @@ func convertToJSONableObject(yamlObj interface{}, jsonTarget *reflect.Value) (in } return yamlObj, nil } - - return nil, nil } diff --git a/vendor/github.com/ghodss/yaml/yaml_go110.go b/vendor/sigs.k8s.io/yaml/yaml_go110.go similarity index 100% rename from vendor/github.com/ghodss/yaml/yaml_go110.go rename to vendor/sigs.k8s.io/yaml/yaml_go110.go