mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-21 06:21:43 +00:00
add namespace to id when create resmap from files
This commit is contained in:
@@ -45,6 +45,11 @@ metadata:
|
||||
---
|
||||
# some comment
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: dply2
|
||||
namespace: test
|
||||
---
|
||||
`
|
||||
|
||||
@@ -68,12 +73,21 @@ metadata:
|
||||
"name": "dply2",
|
||||
},
|
||||
}),
|
||||
resid.NewResIdWithPrefixNamespace(deploy, "dply2", "", "test"): rf.FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "dply2",
|
||||
"namespace": "test",
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
m, _ := rmF.FromFiles(
|
||||
l, []string{"/home/seans/project/deployment.yaml"})
|
||||
if len(m) != 2 {
|
||||
t.Fatalf("%#v should contain 2 appResource, but got %d", m, len(m))
|
||||
if len(m) != 3 {
|
||||
t.Fatalf("%#v should contain 3 appResource, but got %d", m, len(m))
|
||||
}
|
||||
|
||||
if err := expected.ErrorIfNotEqual(m); err != nil {
|
||||
|
||||
@@ -39,6 +39,7 @@ apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: winnie
|
||||
namespace: hundred-acre-wood
|
||||
---
|
||||
# some comment
|
||||
---
|
||||
|
||||
@@ -58,7 +58,8 @@ func (r *Resource) IsGenerated() bool {
|
||||
|
||||
// Id returns the ResId for the resource.
|
||||
func (r *Resource) Id() resid.ResId {
|
||||
return resid.NewResId(r.GetGvk(), r.GetName())
|
||||
namespace, _ := r.GetFieldValue("metadata.namespace")
|
||||
return resid.NewResIdWithPrefixNamespace(r.GetGvk(), r.GetName(), "", namespace)
|
||||
}
|
||||
|
||||
// Merge performs merge with other resource.
|
||||
|
||||
@@ -20,6 +20,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct"
|
||||
"sigs.k8s.io/kustomize/pkg/gvk"
|
||||
"sigs.k8s.io/kustomize/pkg/resid"
|
||||
)
|
||||
|
||||
var factory = NewFactory(
|
||||
@@ -30,11 +32,12 @@ var testConfigMap = factory.FromMap(
|
||||
"apiVersion": "v1",
|
||||
"kind": "ConfigMap",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "winnie",
|
||||
"name": "winnie",
|
||||
"namespace": "hundred-acre-wood",
|
||||
},
|
||||
})
|
||||
|
||||
const testConfigMapString = `unspecified:{"apiVersion":"v1","kind":"ConfigMap","metadata":{"name":"winnie"}}`
|
||||
const testConfigMapString = `unspecified:{"apiVersion":"v1","kind":"ConfigMap","metadata":{"name":"winnie","namespace":"hundred-acre-wood"}}`
|
||||
|
||||
var testDeployment = factory.FromMap(
|
||||
map[string]interface{}{
|
||||
@@ -67,3 +70,24 @@ func TestResourceString(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceId(t *testing.T) {
|
||||
tests := []struct {
|
||||
in *Resource
|
||||
id resid.ResId
|
||||
}{
|
||||
{
|
||||
in: testConfigMap,
|
||||
id: resid.NewResIdWithPrefixNamespace(gvk.Gvk{Version: "v1", Kind: "ConfigMap"}, "winnie", "", "hundred-acre-wood"),
|
||||
},
|
||||
{
|
||||
in: testDeployment,
|
||||
id: resid.NewResId(gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}, "pooh"),
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
if test.in.Id() != test.id {
|
||||
t.Fatalf("Expected %v, but got %v\n", test.id, test.in.Id())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user