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
nameReference breaks when adding outer Kustomization (multiple identical base imports) #4880
Comments
We found a solution by using replacements iso nameReference, so effectively changing:
into:
having (for instance):
|
I find it curious that individually it replaces Just overlay/a
Just overlay/b
overlay
|
This reminds me a lot of a bug I fixed earlier this year in #4700. This theory is corroborated by the fact that the following workaround is effective: use a different placeholder value in each base. E.g. if I switch the placeholder to "other-placeholder" in Would you be willing to submit a test demonstrating this situation as a starting point for fixing it? #4683 is a good example of how to do this. A PR with a fix would also be welcomed, of course. 😄 /triage accepted |
@KnVerey I'm not sure what you mean with submitting a testcase? Since i already isolated the issue and provided all the files? If it needs to be in a specific format let me know i can do this. Secondly; a different "placeholder" isn't going to work since the use-case is to import the same base; for us we try to deploy a Prometheus instance multiple times... Furthermore your hypothesis sounds plausible to me; any reason why nameReference isn't throwing an exception? Because i rather face an error than silently unexpected results. Paul |
OK, so I ended up investigating this to see what is happening and below is what I discovered. There are two possible behaviors that occur when you have multiple overlays that each rename a namespace having same placeholder:
I just opened a PR adding some unit test cases covering the above behaviors I think we want Behavior 2 in both cases, as it would show an error and exit with 1 instead of seeming like it worked when it did not. I looked at what this would take to fix, and it looks like the problem occurs in kustomize/api/internal/builtins/SuffixTransformer.go Lines 23 to 27 in a86723c
I think we need to somehow make nameref aware of which GVKs are skiped by the PrefixTransformer and SuffixTransformer, so that it doesn't eliminate them. I'm not sure at this point the best way to do this. The easiest way would be to hard-code this list in nameref (since it is unexported anyway and can't change). But there is a TODO comment about making the skip list configurable and hard-coding the list in nameref would seem to make that TODO more difficult to accomplish. Alternatively, if we wanted to, I think it would be possible to implement the capability to replace the same placeholder in two different overlays without failing, but it would take more effort and I'm not sure if it would be worth it or not. To do this, I think we would need to add another build annotation so that kustomize can know the "context" of where the resource came from (ie. overlay1 or overlay2). Then we could sieve based on the context matching in |
This issue has not been updated in over 1 year, and should be re-triaged. You can:
For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/ /remove-triage accepted |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues. This bot triages un-triaged issues according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
I need to include a base manifest multiple times and since (obviously) their names will clash i like to use a Kustomization to make the names / namespace unique I do this using a nameSuffix + namespace and then use a nameReference to fix all references to the namespace name. This technique works just fine when i apply it on only 1 included overlay but as soon as a include another then i get no errors but the nameReferences no longer work.
Reproduce in following minimized setup:
./base/prometheus/kustomization.yaml
./base/prometheus/prometheus.yaml
./overlay/a/kustomization.yaml
./overlay/a/namespace-reference.yaml
./overlay/a/namespace.yaml
./overlay/b/kustomization.yaml
./overlay/b/namespace-reference.yaml
./overlay/b/namespace.yaml
./overlay/kustomization.yaml
Expected output
Actual output
As can be seen the nameSuffix and namespace specifiers both behave as expected but the nameReference no longer updates the "placeholders".
Kustomize version
{Version:kustomize/v4.5.7 GitCommit:56d82a8378dfc8dc3b3b1085e5a6e67b82966bd7 BuildDate:2022-08-02T16:35:54Z GoOs:linux GoArch:amd64}
Platform
Linux
The text was updated successfully, but these errors were encountered: