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:
@@ -202,22 +202,41 @@ func NewCmdBuildPrune(
|
||||
|
||||
func writeIndividualFiles(
|
||||
fSys fs.FileSystem, folderPath string, m resmap.ResMap) error {
|
||||
for _, res := range m.Resources() {
|
||||
filename := filepath.Join(
|
||||
folderPath,
|
||||
fmt.Sprintf(
|
||||
|
||||
byNamespace := m.GroupedByNamespace()
|
||||
nsNeeded := len(byNamespace) > 1
|
||||
for namespace, nresources := range byNamespace {
|
||||
for _, res := range nresources {
|
||||
basename := fmt.Sprintf(
|
||||
"%s_%s.yaml",
|
||||
strings.ToLower(res.GetGvk().String()),
|
||||
strings.ToLower(res.GetName()),
|
||||
),
|
||||
)
|
||||
out, err := yaml.Marshal(res.Map())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = fSys.WriteFile(filename, out)
|
||||
if err != nil {
|
||||
return err
|
||||
)
|
||||
|
||||
// Preserve backward compatibility with kustomize 2.1.0.
|
||||
// No need to cluter filename with namespace if all the objects
|
||||
// are in the same namespace.
|
||||
if (nsNeeded) && (namespace != "cluster-wide") {
|
||||
basename = fmt.Sprintf(
|
||||
"%s_%s",
|
||||
strings.ToLower(namespace),
|
||||
strings.ToLower(basename),
|
||||
)
|
||||
}
|
||||
|
||||
filename := filepath.Join(
|
||||
folderPath,
|
||||
basename,
|
||||
)
|
||||
|
||||
out, err := yaml.Marshal(res.Map())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = fSys.WriteFile(filename, out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user