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:
Jerome Brette
2019-06-20 12:33:27 -05:00
parent 762d3143eb
commit 2bba0a6aa3
5 changed files with 216 additions and 20 deletions

View File

@@ -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