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
Adds tests exhibiting possible bug in NamespaceTransformer #4683
Conversation
@naanselmo: This PR has multiple commits, and the default merge method is: merge. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Welcome @naanselmo! |
Hi @naanselmo. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: naanselmo The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Thank you for the tests--this is very helpful. I dug into the problem case on this branch, and here's what I learned.
SolutionsThe ambiguity needs to be resolved so that Kustomize can do the right thing, and there are at least two possible approaches to do this. One is to tell the NamespaceTransformer to target the subjects in at least one of the bases so that they aren't ambiguous by the time NameReferenceTransformer sees them. This is very verbose (#4404 would help), but it works. Here's the transformer config (goes in a file referenced by the apiVersion: builtin
kind: NamespaceTransformer
metadata:
namespace: b
name: include-binding-subjects
fieldSpecs:
- path: metadata/namespace
create: true
- path: metadata/name
kind: Namespace
create: true
- path: subjects/namespace # not included by default
kind: RoleBinding
create: true
- path: subjects/namespace # not included by default
kind: ClusterRoleBinding
create: true
- path: spec/service/namespace
group: apiregistration.k8s.io
kind: APIService
create: true
- path: spec/conversion/webhook/clientConfig/service/namespace
group: apiextensions.k8s.io
kind: CustomResourceDefinition We can't make this change to the built-in defaults because it is valid/common for subjects to refer to objects in other namespaces, which we shouldn't touch. But in your case, it is what you want. The second is to disambiguate the SAs (and the references to them) directly in the bases. Changing the name does this, as you've discovered. Including a distinct namespace (any value will do, since they're being overridden) in the bases will also work. Possible changes to Kustomize
|
This PR creates a pair of tests, one with expected results and one with unexpected results (both tests pass), to exhibit a possible bug.
The tests create the following structure:
The root
kustomization.yaml
only has resources set to the two subdirectories (a
and thenb
), and thekustomization.yaml
on each of those subdirectories sets its namespace toa
orb
(same as its subdir), and includes eithera.yaml
orb.yaml
as a resource.The content of
a.yaml
andb.yaml
is identical, only having different names (one uses-a
suffix, the other-b
), and is as follows:And in this case produces the following expected result:
However, with a small change to each file, renaming
sa-a
andsa-b
tosa
(including in the ClusterRoleBinding), the output unexpectedly becomes:With the unexpected result being that
crb-b
's subject's namespace becamea
, while I would've expected it to remainb
as that would match the namespace of the ServiceAccount defined within its structure.If the order is changed in the root
kustomization.yaml
so that the resourceb
comes before the resourcea
, then the opposite will happen, andcrb-a
will have theb
namespace in its subject, which to me seems even more unexpected.If this is indeed unexpected, then I'm guessing it comes from how the NamespaceTransformer applies its changes to a ClusterRoleBinding considering that a CRB has no namespace, possibly in:
kustomize/api/filters/namespace/namespace.go
Lines 109 to 145 in 7e0fd02