update dependencies (#6267)

Signed-off-by: hongming <coder.scala@gmail.com>
This commit is contained in:
hongming
2024-11-06 10:27:06 +08:00
committed by GitHub
parent faf255a084
commit cfebd96a1f
4263 changed files with 341374 additions and 132036 deletions

View File

@@ -7,7 +7,7 @@ import (
"bytes"
"io"
"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
yaml "sigs.k8s.io/yaml/goyaml.v3"
)
const (

View File

@@ -7,9 +7,9 @@ import (
"reflect"
"strings"
y1_1 "gopkg.in/yaml.v2"
"k8s.io/kube-openapi/pkg/validation/spec"
y1_2 "sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
y1_1 "sigs.k8s.io/yaml/goyaml.v2"
y1_2 "sigs.k8s.io/yaml/goyaml.v3"
)
// typeToTag maps OpenAPI schema types to yaml 1.2 tags
@@ -47,7 +47,7 @@ func FormatNonStringStyle(node *Node, schema spec.Schema) {
}
// if the node tag is null, make sure we don't add any non-null tags
// https://github.com/GoogleContainerTools/kpt/issues/2321
// https://github.com/kptdev/kpt/issues/2321
if node.Tag == NodeTagNull {
// must NOT quote null values
node.Style = 0

View File

@@ -11,7 +11,7 @@ import (
"github.com/davecgh/go-spew/spew"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
yaml "sigs.k8s.io/yaml/goyaml.v3"
)
// Append creates an ElementAppender
@@ -690,6 +690,10 @@ type FieldSetter struct {
// when setting it. Otherwise, if an existing node is found, the style is
// retained.
OverrideStyle bool `yaml:"overrideStyle,omitempty"`
// AppendKeyStyle defines the style of the key when no existing node is
// found, and a new node is appended.
AppendKeyStyle Style `yaml:"appendKeyStyle,omitempty"`
}
func (s FieldSetter) Filter(rn *RNode) (*RNode, error) {
@@ -720,8 +724,14 @@ func (s FieldSetter) Filter(rn *RNode) (*RNode, error) {
return rn, nil
}
// Clear the field if it is empty, or explicitly null
if s.Value == nil || s.Value.IsTaggedNull() {
// Clearing nil fields:
// 1. Clear any fields with no value
// 2. Clear any "null" YAML fields unless we explicitly want to keep them
// This is to balance
// 1. Persisting 'null' values passed by the user (see issue #4628)
// 2. Avoiding producing noisy documents that add any field defaulting to
// 'nil' even if they weren't present in the source document
if s.Value == nil || (s.Value.IsTaggedNull() && !s.Value.ShouldKeep) {
return rn.Pipe(Clear(s.Name))
}
@@ -747,6 +757,7 @@ func (s FieldSetter) Filter(rn *RNode) (*RNode, error) {
&yaml.Node{
Kind: yaml.ScalarNode,
Value: s.Name,
Style: s.AppendKeyStyle,
HeadComment: s.Comments.HeadComment,
LineComment: s.Comments.LineComment,
FootComment: s.Comments.FootComment,

View File

@@ -5,7 +5,7 @@ package yaml
import (
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
yaml "sigs.k8s.io/yaml/goyaml.v3"
)
// AnnotationClearer removes an annotation at metadata.annotations.

View File

@@ -10,7 +10,7 @@ import (
"strings"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
yaml "sigs.k8s.io/yaml/goyaml.v3"
)
// PathMatcher returns all RNodes matching the path wrapped in a SequenceNode.

View File

@@ -45,9 +45,9 @@ func MergeStrings(srcStr, destStr string, infer bool, mergeOptions yaml.MergeOpt
}
type Merger struct {
// for forwards compatibility when new functions are added to the interface
}
// for forwards compatibility when new functions are added to the interface
var _ walk.Visitor = Merger{}
func (m Merger) VisitMap(nodes walk.Sources, s *openapi.ResourceSchema) (*yaml.RNode, error) {
@@ -66,8 +66,7 @@ func (m Merger) VisitMap(nodes walk.Sources, s *openapi.ResourceSchema) (*yaml.R
// If Origin is missing, preserve explicitly set null in Dest ("null", "~", etc)
if nodes.Origin().IsNil() && !nodes.Dest().IsNil() && len(nodes.Dest().YNode().Value) > 0 {
// Return a new node so that it won't have a "!!null" tag and therefore won't be cleared.
return yaml.NewScalarRNode(nodes.Dest().YNode().Value), nil
return yaml.MakePersistentNullNode(nodes.Dest().YNode().Value), nil
}
return nodes.Origin(), nil

View File

@@ -13,10 +13,10 @@ import (
"strings"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
"sigs.k8s.io/kustomize/kyaml/sliceutil"
"sigs.k8s.io/kustomize/kyaml/utils"
"sigs.k8s.io/kustomize/kyaml/yaml/internal/k8sgen/pkg/labels"
yaml "sigs.k8s.io/yaml/goyaml.v3"
)
// MakeNullNode returns an RNode that represents an empty document.
@@ -24,6 +24,20 @@ func MakeNullNode() *RNode {
return NewRNode(&Node{Tag: NodeTagNull})
}
// MakePersistentNullNode returns an RNode that should be persisted,
// even when merging
func MakePersistentNullNode(value string) *RNode {
n := NewRNode(
&Node{
Tag: NodeTagNull,
Value: value,
Kind: yaml.ScalarNode,
},
)
n.ShouldKeep = true
return n
}
// IsMissingOrNull is true if the RNode is nil or explicitly tagged null.
// TODO: make this a method on RNode.
func IsMissingOrNull(node *RNode) bool {
@@ -214,6 +228,9 @@ type RNode struct {
// object root: object root
value *yaml.Node
// Whether we should keep this node, even if otherwise we would clear it
ShouldKeep bool
Match []string
}

View File

@@ -8,8 +8,8 @@ import (
"strings"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml"
"sigs.k8s.io/kustomize/kyaml/sets"
yaml "sigs.k8s.io/yaml/goyaml.v3"
)
// CopyYNode returns a distinct copy of its argument.

View File

@@ -58,7 +58,7 @@ func (l Walker) walkMap() (*yaml.RNode, error) {
if l.Schema != nil {
s = l.Schema.Field(key)
}
fv, commentSch := l.fieldValue(key)
fv, commentSch, keyStyles := l.fieldValue(key)
if commentSch != nil {
s = commentSch
}
@@ -90,7 +90,13 @@ func (l Walker) walkMap() (*yaml.RNode, error) {
}
// this handles empty and non-empty values
_, err = dest.Pipe(yaml.FieldSetter{Name: key, Comments: comments, Value: val})
fieldSetter := yaml.FieldSetter{
Name: key,
Comments: comments,
AppendKeyStyle: keyStyles[val],
Value: val,
}
_, err = dest.Pipe(fieldSetter)
if err != nil {
return nil, err
}
@@ -153,10 +159,12 @@ func (l Walker) fieldNames() []string {
return result
}
// fieldValue returns a slice containing each source's value for fieldName
func (l Walker) fieldValue(fieldName string) ([]*yaml.RNode, *openapi.ResourceSchema) {
// fieldValue returns a slice containing each source's value for fieldName, the
// schema, and a map of each source's value to the style for the source's key.
func (l Walker) fieldValue(fieldName string) ([]*yaml.RNode, *openapi.ResourceSchema, map[*yaml.RNode]yaml.Style) {
var fields []*yaml.RNode
var sch *openapi.ResourceSchema
keyStyles := make(map[*yaml.RNode]yaml.Style, len(l.Sources))
for i := range l.Sources {
if l.Sources[i] == nil {
fields = append(fields, nil)
@@ -165,9 +173,12 @@ func (l Walker) fieldValue(fieldName string) ([]*yaml.RNode, *openapi.ResourceSc
field := l.Sources[i].Field(fieldName)
f, s := l.valueIfPresent(field)
fields = append(fields, f)
if field != nil && field.Key != nil && field.Key.YNode() != nil {
keyStyles[f] = field.Key.YNode().Style
}
if sch == nil && !s.IsMissingOrNull() {
sch = s
}
}
return fields, sch
return fields, sch, keyStyles
}