mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Merge pull request #4013 from KnVerey/go-yaml-fork
Internal go-yaml/yaml fork
This commit is contained in:
@@ -7,9 +7,18 @@ import (
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
|
||||
)
|
||||
|
||||
const CompactSequenceStyle = "compact"
|
||||
const WideSequenceStyle = "wide"
|
||||
|
||||
const DefaultIndent = 2
|
||||
const DefaultSequenceStyle = CompactSequenceStyle
|
||||
|
||||
var sequenceIndentationStyle = DefaultSequenceStyle
|
||||
var indent = DefaultIndent
|
||||
|
||||
// Expose the yaml.v3 functions so this package can be used as a replacement
|
||||
|
||||
type Decoder = yaml.Decoder
|
||||
@@ -21,7 +30,8 @@ type Node = yaml.Node
|
||||
type Style = yaml.Style
|
||||
type TypeError = yaml.TypeError
|
||||
type Unmarshaler = yaml.Unmarshaler
|
||||
var Marshal = func (in interface{}) ([]byte, error) {
|
||||
|
||||
var Marshal = func(in interface{}) ([]byte, error) {
|
||||
var buf bytes.Buffer
|
||||
err := NewEncoder(&buf).Encode(in)
|
||||
if err != nil {
|
||||
@@ -33,7 +43,10 @@ var Unmarshal = yaml.Unmarshal
|
||||
var NewDecoder = yaml.NewDecoder
|
||||
var NewEncoder = func(w io.Writer) *yaml.Encoder {
|
||||
e := yaml.NewEncoder(w)
|
||||
e.SetIndent(2)
|
||||
e.SetIndent(indent)
|
||||
if sequenceIndentationStyle == CompactSequenceStyle {
|
||||
e.CompactSeqIndent()
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"strings"
|
||||
|
||||
y1_1 "gopkg.in/yaml.v2"
|
||||
y1_2 "gopkg.in/yaml.v3"
|
||||
"k8s.io/kube-openapi/pkg/validation/spec"
|
||||
y1_2 "sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
|
||||
)
|
||||
|
||||
// typeToTag maps OpenAPI schema types to yaml 1.2 tags
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"gopkg.in/yaml.v3"
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
|
||||
)
|
||||
|
||||
// Append creates an ElementAppender
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
|
||||
. "sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
package yaml
|
||||
|
||||
import (
|
||||
"gopkg.in/yaml.v3"
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
|
||||
)
|
||||
|
||||
// AnnotationClearer removes an annotation at metadata.annotations.
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml/internal/k8sgen/pkg/labels"
|
||||
)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/yaml.v3"
|
||||
"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
|
||||
)
|
||||
|
||||
func TestRNodeHasNilEntryInList(t *testing.T) {
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package yaml
|
||||
|
||||
import "gopkg.in/yaml.v3"
|
||||
|
||||
func DoSerializationHacksOnNodes(nodes []*RNode) {
|
||||
for _, node := range nodes {
|
||||
DoSerializationHacks(node.YNode())
|
||||
}
|
||||
}
|
||||
|
||||
// DoSerializationHacks addresses a bug in yaml V3 upstream, it parses the yaml node,
|
||||
// and rearranges the head comments of the children of sequence node.
|
||||
// Refer to https://github.com/go-yaml/yaml/issues/587 for more details
|
||||
func DoSerializationHacks(node *yaml.Node) {
|
||||
switch node.Kind {
|
||||
case DocumentNode:
|
||||
for _, node := range node.Content {
|
||||
DoSerializationHacks(node)
|
||||
}
|
||||
|
||||
case MappingNode:
|
||||
for _, node := range node.Content {
|
||||
DoSerializationHacks(node)
|
||||
}
|
||||
|
||||
case SequenceNode:
|
||||
for _, node := range node.Content {
|
||||
// for each child mapping node, transfer the head comment of it's
|
||||
// first child scalar node to the head comment of itself
|
||||
// This is necessary to address serialization issue
|
||||
// https://github.com/go-yaml/yaml/issues/587 in go-yaml.v3
|
||||
// Remove this hack when the issue has been resolved
|
||||
if len(node.Content) > 0 && node.Content[0].Kind == ScalarNode {
|
||||
// Don't clobber the head comment if it's not empty.
|
||||
if node.HeadComment == "" && node.Content[0].HeadComment != "" {
|
||||
node.HeadComment = node.Content[0].HeadComment
|
||||
}
|
||||
node.Content[0].HeadComment = ""
|
||||
}
|
||||
DoSerializationHacks(node)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"bytes"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
|
||||
"sigs.k8s.io/kustomize/kyaml/sets"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user