mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 09:02:53 +00:00
skip adding namespace when the object is empty
This commit is contained in:
@@ -70,12 +70,16 @@ func (o *namespaceTransformer) Transform(m resmap.ResMap) error {
|
|||||||
if !id.Gvk().IsSelected(&path.Gvk) {
|
if !id.Gvk().IsSelected(&path.Gvk) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// make sure the object is non empty
|
||||||
err := mutateField(objMap, path.PathSlice(), path.CreateIfNotPresent, func(_ interface{}) (interface{}, error) {
|
if len(objMap) > 0 {
|
||||||
return o.namespace, nil
|
err := mutateField(
|
||||||
})
|
objMap, path.PathSlice(), path.CreateIfNotPresent,
|
||||||
if err != nil {
|
func(_ interface{}) (interface{}, error) {
|
||||||
return err
|
return o.namespace, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
newid := id.CopyWithNewNamespace(o.namespace)
|
newid := id.CopyWithNewNamespace(o.namespace)
|
||||||
m[newid] = mf[id]
|
m[newid] = mf[id]
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ func TestNamespaceRun(t *testing.T) {
|
|||||||
"namespace": "foo",
|
"namespace": "foo",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
resid.NewResId(cmap, "cm3"): rf.FromMap(
|
||||||
|
map[string]interface{}{},
|
||||||
|
),
|
||||||
resid.NewResId(ns, "ns1"): rf.FromMap(
|
resid.NewResId(ns, "ns1"): rf.FromMap(
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
@@ -134,6 +137,9 @@ func TestNamespaceRun(t *testing.T) {
|
|||||||
"namespace": "test",
|
"namespace": "test",
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
resid.NewResIdWithPrefixNamespace(cmap, "cm3", "", "test"): rf.FromMap(
|
||||||
|
map[string]interface{}{},
|
||||||
|
),
|
||||||
resid.NewResIdWithPrefixNamespace(sa, "default", "", "test"): rf.FromMap(
|
resid.NewResIdWithPrefixNamespace(sa, "default", "", "test"): rf.FromMap(
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"apiVersion": "v1",
|
"apiVersion": "v1",
|
||||||
|
|||||||
Reference in New Issue
Block a user