mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Merge pull request #475 from Liujingfang1/namespace
add namespace to id when create resmap from files
This commit is contained in:
@@ -45,6 +45,11 @@ metadata:
|
|||||||
---
|
---
|
||||||
# some comment
|
# some comment
|
||||||
---
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: dply2
|
||||||
|
namespace: test
|
||||||
---
|
---
|
||||||
`
|
`
|
||||||
|
|
||||||
@@ -68,12 +73,21 @@ metadata:
|
|||||||
"name": "dply2",
|
"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(
|
m, _ := rmF.FromFiles(
|
||||||
l, []string{"/home/seans/project/deployment.yaml"})
|
l, []string{"/home/seans/project/deployment.yaml"})
|
||||||
if len(m) != 2 {
|
if len(m) != 3 {
|
||||||
t.Fatalf("%#v should contain 2 appResource, but got %d", m, len(m))
|
t.Fatalf("%#v should contain 3 appResource, but got %d", m, len(m))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := expected.ErrorIfNotEqual(m); err != nil {
|
if err := expected.ErrorIfNotEqual(m); err != nil {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ apiVersion: v1
|
|||||||
kind: ConfigMap
|
kind: ConfigMap
|
||||||
metadata:
|
metadata:
|
||||||
name: winnie
|
name: winnie
|
||||||
|
namespace: hundred-acre-wood
|
||||||
---
|
---
|
||||||
# some comment
|
# some comment
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ func (r *Resource) IsGenerated() bool {
|
|||||||
|
|
||||||
// Id returns the ResId for the resource.
|
// Id returns the ResId for the resource.
|
||||||
func (r *Resource) Id() resid.ResId {
|
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.
|
// Merge performs merge with other resource.
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct"
|
"sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct"
|
||||||
|
"sigs.k8s.io/kustomize/pkg/gvk"
|
||||||
|
"sigs.k8s.io/kustomize/pkg/resid"
|
||||||
)
|
)
|
||||||
|
|
||||||
var factory = NewFactory(
|
var factory = NewFactory(
|
||||||
@@ -31,10 +33,11 @@ var testConfigMap = factory.FromMap(
|
|||||||
"kind": "ConfigMap",
|
"kind": "ConfigMap",
|
||||||
"metadata": map[string]interface{}{
|
"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(
|
var testDeployment = factory.FromMap(
|
||||||
map[string]interface{}{
|
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