File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change @@ -56,9 +56,11 @@ func (ns Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
5656
5757// Run runs the filter on a single node rather than a slice
5858func (ns Filter ) run (node * yaml.RNode ) (* yaml.RNode , error ) {
59- // Special handling for metadata.namespace -- :(
59+ // Special handling for metadata.namespace and metadata.name -- :(
6060 // never let SetEntry handle metadata.namespace--it will incorrectly include cluster-scoped resources
61- ns .FsSlice = ns .removeMetaNamespaceFieldSpecs (ns .FsSlice )
61+ // only update metadata.name if api version is expected one--so-as it leaves other resources of kind namespace alone
62+ apiVersion := node .GetApiVersion ()
63+ ns .FsSlice = ns .removeUnneededMetaFieldSpecs (apiVersion , ns .FsSlice )
6264 gvk := resid .GvkFromNode (node )
6365 if err := ns .metaNamespaceHack (node , gvk ); err != nil {
6466 return nil , err
@@ -186,12 +188,15 @@ func (ns Filter) removeRoleBindingSubjectFieldSpecs(fs types.FsSlice) types.FsSl
186188 return val
187189}
188190
189- func (ns Filter ) removeMetaNamespaceFieldSpecs ( fs types.FsSlice ) types.FsSlice {
191+ func (ns Filter ) removeUnneededMetaFieldSpecs ( apiVersion string , fs types.FsSlice ) types.FsSlice {
190192 var val types.FsSlice
191193 for i := range fs {
192194 if fs [i ].Path == types .MetadataNamespacePath {
193195 continue
194196 }
197+ if apiVersion != types .MetadataNamespaceApiVersion && fs [i ].Path == types .MetadataNamePath {
198+ continue
199+ }
195200 val = append (val , fs [i ])
196201 }
197202 return val
Original file line number Diff line number Diff line change @@ -14,11 +14,13 @@ import (
1414)
1515
1616const (
17- KustomizationVersion = "kustomize.config.k8s.io/v1beta1"
18- KustomizationKind = "Kustomization"
19- ComponentVersion = "kustomize.config.k8s.io/v1alpha1"
20- ComponentKind = "Component"
21- MetadataNamespacePath = "metadata/namespace"
17+ KustomizationVersion = "kustomize.config.k8s.io/v1beta1"
18+ KustomizationKind = "Kustomization"
19+ ComponentVersion = "kustomize.config.k8s.io/v1alpha1"
20+ ComponentKind = "Component"
21+ MetadataNamespacePath = "metadata/namespace"
22+ MetadataNamespaceApiVersion = "v1"
23+ MetadataNamePath = "metadata/name"
2224
2325 OriginAnnotations = "originAnnotations"
2426 TransformerAnnotations = "transformerAnnotations"
You can’t perform that action at this time.
0 commit comments