-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kustomize fails to find object in base modified with nameSuffix #1082
Comments
I was looking for solution for similar scenario, i.e. build multiple persistent volume manifests from the same template base. IIRC, you should refer the untransformed name in patches, i.e. For the multiple objects error, it seems the same base (the same path) can not be used twice. But you may play a trick by creating symlink into the replicas, e.g. in Even we get the patches work, there will be further trouble in variable substitution, since it can not be transformed. My general feeling is that kustomize lacks a feature of making replica of bases. Maybe some new syntax needs to be introduced to support this. It is a quite common scenario to us. |
Yes, I can see kustomize attempting to use untransformed name in the patch. However, referencing the untransformed name in the base is counter intuitive. I expect the patch to be able to reference the object name emitted in the final rendered result of the base. Otherwise it could be a rabbit hole of chasing down the correct original name.
I agree with this lack of functionality. Essentially we have a template which we want to create multiple instances of, but cannot find a clean way to do this without copying and pasting the entire object and renaming it. |
I tried to go a different route and use json 6902 for the rename instead of nameSuffix, but I seem to be hitting another error. Filed #1083. |
Not exactly. Since currently the same base can be only referred once, it turns out more clear to refer the original name instead of patched one. It would be another story if base replica is supported. IIUC, the first step in kustomize is building resource map by merging all bases together. Then resolve all the references, apply the patches, transform the names, substitute the variables (not sure about the exact order). To support base replicas, we kind of need to build bases before merging them, maybe with a new syntax like
The overlays will be built and frozen before merging into the aggregated kustomize stack. |
The reason I feel this is counter-intuitive to refer to the original name, is because it requires understanding of everything that may or may not have happened in the base. That base might have referenced another base, and go several levels of indirection. Hunting down the original resource name seems fragile. In our situation, we even might be leveraging a remote base which is out of our control. I think the understanding most people have about bases, is that you are applying patches on top of whatever was emitted by that base, after all transformations have been performed. Is my understanding incorrect? |
This is the an intuitive thinking as I did before 😄 but may not be the truth 😞 I haven't dig that far yet. Maybe @Liujingfang1 or @monopole can give a better answer. |
I think this issue may be related to, if not the same as: #316 |
When we designed how the patch should work, we didn't include the nameprefix or namesuffix for the target name. That means if you add nameprfix/namesuffix in the patch file, it couldn't find the target. The reason for choosing this behavior is that users don't need to compute or run @jessesuen @yujunz Based on the examples you provided, it is reasonable that Kustomize is expected to find the correct target. Maybe we can do it as the following
We say that the target object is found only when there is a unique match. |
Yes, it can.
This is the problem I am trying to solve. It seems a two-pass build might be the right way to do it. With @jessesuen 's example
Is there something like pre-build hook we can leverage in kustomize? @Liujingfang1 |
I'd rather avoid a two-pass build. I like the approach of matching to both base name and to name prefix/suffix. Is this something that is on the roadmap? |
I can open different ticket if scope of fix would vary, but seeing similar unintuitive behavior even if I use a json patch in a base to patch a Deployment name. In an inheritance scenario like the one below, find it logically incorrect to have to refer to a Deployment resource by its base name in a strategic merge patch at a child environment overlay level, when I already patched its name in a parent base. Kustomize will output the output I want but even after understanding current functionality, having to document and explain the patching logic to others is not a pleasant experience. Example Inheritance
The suggestions in #727 don't seem to actually work in my scenario. I originally tried to use As mentioned already, working with remote bases starts getting rather dicey as you'll need to know the names of root resources that you may or may not manage. This also prevents scenarios like having 1 json patch that is shared among resources (where use of yaml anchors would be super useful). Again, can definitely open new ticket if need be, modifying resource names with |
@Liujingfang1 could this name matching apply more generally to actual name (modified with a patch on a parent base)? |
@botwhytho If you could open a ticket, that would be awesome. I'm running into some serious headaches when I have a namePrefix or nameSuffix before the overlay. Having kustomize match on the base name, and if not found, match on name{Suffix|Prefix} would fix my issue. The scenario is I have a remote (git) base that contains a base ElasticSearch setup, and I pull this in to a base folder with a namePrefix (to ensure a unique service name). The overlay then does things like configure hostname. |
This makes kustomize unsuitable for my use case - reusing base layers to describe similar app configuration. |
I am hitting the same issue here and it's becoming borderline unusable. I have the following scenario:
My base defines the deployment, web/worker update the command/arguments and add a suffix to the name. In prod/qa, i define the namespace and I would like to define the replica count. Unfortunately, it is not possible this way. When using |
This has been fixed by #1154. Please check out version 3.0.0-pre. |
Calling this fixed by #1183, which is in v2.1.0. Added a test to cover in #1278 How this should work exactly is open for debate, but the behavior is
a feature allowing a patch to have multiple targets is coming soon. |
Consider the following directory structure:
When attempting to build the aggregate, it fails with error:
I made this available here:
https://github.com/jessesuen/k8s-deployments/tree/master/kustomize-suffix-failed-find-obj
I expect patching to work on objects in the base, even after name transformation using
namePrefix
ornameSuffix
. However, it does not find the object transformed with nameSuffix. Interestingly, if I modifypatch-a.yaml
to reference the name of the resource without the suffix, it gets the following error:This is reproducible with both v2.0.3 and tip of master from today (f9c631e).
The text was updated successfully, but these errors were encountered: