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?
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.
Most helpful comment
Is there a workaround? The fix does not appear to be available in
kubectlyet.