mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-10 08:20:59 +00:00
Merge pull request #5133 from timja/issue-5072-non-core-api-version-namespace
Only override name of core api version
This commit is contained in:
@@ -56,9 +56,11 @@ func (ns Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||
|
||||
// Run runs the filter on a single node rather than a slice
|
||||
func (ns Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
|
||||
// Special handling for metadata.namespace -- :(
|
||||
// Special handling for metadata.namespace and metadata.name -- :(
|
||||
// never let SetEntry handle metadata.namespace--it will incorrectly include cluster-scoped resources
|
||||
ns.FsSlice = ns.removeMetaNamespaceFieldSpecs(ns.FsSlice)
|
||||
// only update metadata.name if api version is expected one--so-as it leaves other resources of kind namespace alone
|
||||
apiVersion := node.GetApiVersion()
|
||||
ns.FsSlice = ns.removeUnneededMetaFieldSpecs(apiVersion, ns.FsSlice)
|
||||
gvk := resid.GvkFromNode(node)
|
||||
if err := ns.metaNamespaceHack(node, gvk); err != nil {
|
||||
return nil, err
|
||||
@@ -186,12 +188,15 @@ func (ns Filter) removeRoleBindingSubjectFieldSpecs(fs types.FsSlice) types.FsSl
|
||||
return val
|
||||
}
|
||||
|
||||
func (ns Filter) removeMetaNamespaceFieldSpecs(fs types.FsSlice) types.FsSlice {
|
||||
func (ns Filter) removeUnneededMetaFieldSpecs(apiVersion string, fs types.FsSlice) types.FsSlice {
|
||||
var val types.FsSlice
|
||||
for i := range fs {
|
||||
if fs[i].Path == types.MetadataNamespacePath {
|
||||
continue
|
||||
}
|
||||
if apiVersion != types.MetadataNamespaceApiVersion && fs[i].Path == types.MetadataNamePath {
|
||||
continue
|
||||
}
|
||||
val = append(val, fs[i])
|
||||
}
|
||||
return val
|
||||
|
||||
@@ -801,3 +801,31 @@ metadata:
|
||||
namespace: iter8-monitoring
|
||||
`)
|
||||
}
|
||||
|
||||
// Demonstrates that metadata.name is only overridden for a kind: Namespace with apiVersion: v1
|
||||
// Test for issue #5072
|
||||
func TestNameNotOveriddenForNonCoreApiVersionOnANamespaceKind(t *testing.T) {
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
|
||||
th.WriteF("azure-servicebus.yaml", `
|
||||
apiVersion: servicebus.azure.com/v1beta20210101preview
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: core-sb-99
|
||||
namespace: without-podinfo
|
||||
`)
|
||||
th.WriteK(".", `
|
||||
namespace: podinfo
|
||||
resources:
|
||||
- azure-servicebus.yaml
|
||||
`)
|
||||
|
||||
m := th.Run(".", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, `
|
||||
apiVersion: servicebus.azure.com/v1beta20210101preview
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: core-sb-99
|
||||
namespace: podinfo
|
||||
`)
|
||||
}
|
||||
|
||||
@@ -14,11 +14,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
KustomizationVersion = "kustomize.config.k8s.io/v1beta1"
|
||||
KustomizationKind = "Kustomization"
|
||||
ComponentVersion = "kustomize.config.k8s.io/v1alpha1"
|
||||
ComponentKind = "Component"
|
||||
MetadataNamespacePath = "metadata/namespace"
|
||||
KustomizationVersion = "kustomize.config.k8s.io/v1beta1"
|
||||
KustomizationKind = "Kustomization"
|
||||
ComponentVersion = "kustomize.config.k8s.io/v1alpha1"
|
||||
ComponentKind = "Component"
|
||||
MetadataNamespacePath = "metadata/namespace"
|
||||
MetadataNamespaceApiVersion = "v1"
|
||||
MetadataNamePath = "metadata/name"
|
||||
|
||||
OriginAnnotations = "originAnnotations"
|
||||
TransformerAnnotations = "transformerAnnotations"
|
||||
|
||||
Reference in New Issue
Block a user