Kustomize: name clashes when using the same base twice

Created on 2 May 2019  ยท  5Comments  ยท  Source: kubernetes-sigs/kustomize

Please see https://github.com/bcbrockway/kustomize-name-clash for a working example of this issue.

We have a multi-layered kustomize config similar to the following (actually in practice they're in many different places to keep them modular but this should illustrate the issue we have):

.
โ””โ”€โ”€ dev1
    โ”œโ”€โ”€ dev
    โ”‚ย ย  โ”œโ”€โ”€ elasticstack-log
    โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ elasticstack
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ elasticsearch
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ elasticsearch-statefulSet.yml
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ kustomization.yaml
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ elasticsearch-data
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ add-data-node-settings.yaml
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ elasticsearch-data-service.yml
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ kustomization.yaml
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ elasticsearch-master
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ add-master-node-settings.yaml
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ elasticsearch-master-service.yml
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ kustomization.yaml
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ kustomization.yaml
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ networkPolicy.yml
    โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ README.md
    โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ kustomization.yaml
    โ”‚ย ย  โ”œโ”€โ”€ kustomization.yaml
    โ”‚ย ย  โ””โ”€โ”€ properties
    โ”‚ย ย      โ””โ”€โ”€ environment.properties
    โ”œโ”€โ”€ kustomization.yaml
    โ”œโ”€โ”€ properties
    โ”‚ย ย  โ””โ”€โ”€ cluster.properties
    โ””โ”€โ”€ README.md

We're trying to reduce the amount of double-keying as much as possible by having an elasticsearch StatefulSet in its own base and then deriving master and data nodes from it, but we've run into a naming issue. We want to name the elasticsearch-master and elasticsearch-data resources simply elasticsearch and then have the nameSuffix field append the necessary -master or -data strings onto the end, however when you run a kustomize build dev1 it complains:

Error: Multiple matches for name ~G_v1_Service|monitoring|~P|elasticsearch|-master:-log:
  [~G_v1_Service|monitoring|~P|elasticsearch|-master:-log ~G_v1_Service|monitoring|~P|elasticsearch|-data:-log]

I get a completely different error if I use namePrefix instead of nameSuffix in the elasticsearch-master/kustomization.yaml and elasticsearch-data/kustomization.yaml files:

Error: found 2 resId matches for var {elasticsearch-data-service-name ~G_v1_Service {metadata.name}} (unable to disambiguate)

This, I presume, is because the variable values are pulled _before_ the prefix/suffix is applied.

What are we doing wrong here? Are we missing something? Are there any best practices for this kind of structure?

help wanted kinbug

Most helpful comment

Is there a workaround? The fix does not appear to be available in kubectl yet.

All 5 comments

This is related to vars. When looking for targets to resolve the vars, only one target is expected. With this layout, it found two.
This is bug in Kustomize. It should include prefix and suffix when looking for the target.

I've just hit this issue as well - would be great to get more input on this.

i'v submittd a pr to try to fix it, @Liujingfang1 would you help to review it?

@qiujian16 Thank you for working on this. I'll review the PR.

Is there a workaround? The fix does not appear to be available in kubectl yet.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

laupow picture laupow  ยท  4Comments

lionelvillard picture lionelvillard  ยท  4Comments

surki picture surki  ยท  4Comments

wuestkamp picture wuestkamp  ยท  3Comments

TechnicalMercenary picture TechnicalMercenary  ยท  3Comments