mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Merge branch 'master' into enable_gocritic
This commit is contained in:
@@ -12,6 +12,13 @@ import (
|
||||
. "sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
const (
|
||||
NodeSampleData = `n: o
|
||||
a: b
|
||||
c: d
|
||||
`
|
||||
)
|
||||
|
||||
func TestResourceNode_SetValue(t *testing.T) {
|
||||
instance := *NewScalarRNode("foo")
|
||||
copy := instance
|
||||
@@ -32,11 +39,7 @@ func TestResourceNode_SetValue(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAppend(t *testing.T) {
|
||||
s := `n: o
|
||||
a: b
|
||||
c: d
|
||||
`
|
||||
node, err := Parse(s)
|
||||
node, err := Parse(NodeSampleData)
|
||||
assert.NoError(t, err)
|
||||
rn, err := node.Pipe(Append(NewScalarRNode("").YNode()))
|
||||
if assert.Error(t, err) {
|
||||
@@ -44,7 +47,7 @@ c: d
|
||||
}
|
||||
assert.Nil(t, rn)
|
||||
|
||||
s = `- a
|
||||
s := `- a
|
||||
- b
|
||||
`
|
||||
node, err = Parse(s)
|
||||
@@ -55,36 +58,28 @@ c: d
|
||||
}
|
||||
|
||||
func TestClearField_Fn(t *testing.T) {
|
||||
s := `n: o
|
||||
a: b
|
||||
c: d
|
||||
`
|
||||
node, err := Parse(s)
|
||||
node, err := Parse(NodeSampleData)
|
||||
assert.NoError(t, err)
|
||||
rn, err := node.Pipe(FieldClearer{Name: "a"})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "n: o\nc: d\n", assertNoErrorString(t)(node.String()))
|
||||
assert.Equal(t, "b\n", assertNoErrorString(t)(rn.String()))
|
||||
|
||||
s = `n: o
|
||||
a: b
|
||||
c: d
|
||||
`
|
||||
node, err = Parse(s)
|
||||
node, err = Parse(NodeSampleData)
|
||||
assert.NoError(t, err)
|
||||
rn, err = node.Pipe(FieldClearer{Name: "n"})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "a: b\nc: d\n", assertNoErrorString(t)(node.String()))
|
||||
assert.Equal(t, "o\n", assertNoErrorString(t)(rn.String()))
|
||||
|
||||
node, err = Parse(s)
|
||||
node, err = Parse(NodeSampleData)
|
||||
assert.NoError(t, err)
|
||||
rn, err = node.Pipe(FieldClearer{Name: "c"})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "n: o\na: b\n", assertNoErrorString(t)(node.String()))
|
||||
assert.Equal(t, "d\n", assertNoErrorString(t)(rn.String()))
|
||||
|
||||
s = `n: o
|
||||
s := `n: o
|
||||
a: b
|
||||
`
|
||||
node, err = Parse(s)
|
||||
|
||||
@@ -97,6 +97,10 @@ func (m Merger) VisitList(nodes walk.Sources, kind walk.ListKind) (*yaml.RNode,
|
||||
func (m Merger) SetComments(sources walk.Sources) error {
|
||||
source := sources.Origin()
|
||||
dest := sources.Dest()
|
||||
if dest == nil || dest.YNode() == nil || source == nil || source.YNode() == nil {
|
||||
// avoid panic
|
||||
return nil
|
||||
}
|
||||
if source != nil && source.YNode().FootComment != "" {
|
||||
dest.YNode().FootComment = source.YNode().FootComment
|
||||
}
|
||||
|
||||
@@ -241,6 +241,46 @@ type ObjectMeta struct {
|
||||
Annotations map[string]string `yaml:"annotations,omitempty"`
|
||||
}
|
||||
|
||||
// GetIdentifier returns a ResourceIdentifier that includes
|
||||
// the information needed to uniquely identify a resource in a cluster.
|
||||
func (m *ResourceMeta) GetIdentifier() ResourceIdentifier {
|
||||
return ResourceIdentifier{
|
||||
Name: m.Name,
|
||||
Namespace: m.Namespace,
|
||||
APIVersion: m.APIVersion,
|
||||
Kind: m.Kind,
|
||||
}
|
||||
}
|
||||
|
||||
// ResourceIdentifier contains the information needed to uniquely
|
||||
// identify a resource in a cluster.
|
||||
type ResourceIdentifier struct {
|
||||
// Name is the name of the resource as set in metadata.name
|
||||
Name string `yaml:"name,omitempty"`
|
||||
// Namespace is the namespace of the resource as set in metadata.namespace
|
||||
Namespace string `yaml:"namespace,omitempty"`
|
||||
// ApiVersion is the apiVersion of the resource
|
||||
APIVersion string `yaml:"apiVersion,omitempty"`
|
||||
// Kind is the kind of the resource
|
||||
Kind string `yaml:"kind,omitempty"`
|
||||
}
|
||||
|
||||
func (r *ResourceIdentifier) GetName() string {
|
||||
return r.Name
|
||||
}
|
||||
|
||||
func (r *ResourceIdentifier) GetNamespace() string {
|
||||
return r.Namespace
|
||||
}
|
||||
|
||||
func (r *ResourceIdentifier) GetAPIVersion() string {
|
||||
return r.APIVersion
|
||||
}
|
||||
|
||||
func (r *ResourceIdentifier) GetKind() string {
|
||||
return r.Kind
|
||||
}
|
||||
|
||||
var ErrMissingMetadata = fmt.Errorf("missing Resource metadata")
|
||||
|
||||
// GetMeta returns the ResourceMeta for a RNode
|
||||
|
||||
Reference in New Issue
Block a user