mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 09:02:53 +00:00
Support for ConfigMap generator with identical names in different namespaces.
- Attempt to account, at build time, for subsequent kubectl apply behavior. (empty or no namespace means default). - Account for the fact that not all objects have a namespace. - Add new Equal method to ResId address merge name conflict - Add GroupByName to resources by namespaces to resolve filenames conflict - Added corresponding unit tests. - Change the fail test for issue #1155
This commit is contained in:
@@ -93,6 +93,13 @@ type ResMap interface {
|
||||
// Same as GetByOriginalId.
|
||||
GetById(resid.ResId) (*resource.Resource, error)
|
||||
|
||||
// GroupedByNamespace provides map of discardable slice
|
||||
// of resource pointer
|
||||
// The not namespaceable resources are added to the "cluster-wide" key.
|
||||
// The resources in the default namespace are added to the "default" key.
|
||||
// The rest of the resources are grouped in their respectiv namespace.
|
||||
GroupedByNamespace() map[string][]*resource.Resource
|
||||
|
||||
// AllIds returns all CurrentIds.
|
||||
AllIds() []resid.ResId
|
||||
|
||||
@@ -343,6 +350,29 @@ func (m *resWrangler) GetById(id resid.ResId) (*resource.Resource, error) {
|
||||
return m.GetByCurrentId(id)
|
||||
}
|
||||
|
||||
// GroupedByNamespace implements ResMap.GroupByNamespace
|
||||
func (m *resWrangler) GroupedByNamespace() map[string][]*resource.Resource {
|
||||
byNamespace := make(map[string][]*resource.Resource)
|
||||
for _, res := range m.rList {
|
||||
namespace := "cluster-wide"
|
||||
|
||||
if res.OrgId().IsNamespaceable() {
|
||||
namespace = res.OrgId().Namespace
|
||||
if res.OrgId().IsInDefaultNs() {
|
||||
namespace = "default"
|
||||
}
|
||||
}
|
||||
|
||||
if _, found := byNamespace[namespace]; !found {
|
||||
byNamespace[namespace] = make([]*resource.Resource, 0)
|
||||
}
|
||||
|
||||
byNamespace[namespace] = append(byNamespace[namespace], res)
|
||||
}
|
||||
|
||||
return byNamespace
|
||||
}
|
||||
|
||||
// AsYaml implements ResMap.
|
||||
func (m *resWrangler) AsYaml() ([]byte, error) {
|
||||
firstObj := true
|
||||
@@ -504,7 +534,7 @@ func (m *resWrangler) appendReplaceOrMerge(
|
||||
res *resource.Resource) error {
|
||||
id := res.CurId()
|
||||
// Maybe also try by current id if nothing matches?
|
||||
matches := m.GetMatchingResourcesByOriginalId(id.GvknEquals)
|
||||
matches := m.GetMatchingResourcesByOriginalId(id.Equals)
|
||||
switch len(matches) {
|
||||
case 0:
|
||||
switch res.Behavior() {
|
||||
|
||||
Reference in New Issue
Block a user