-
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
handle generateName as a replacement of name in ObjectMeta v1 #4838
Conversation
|
Welcome @julian7! |
Hi @julian7. 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes #641
Does this PR really provide a complete fix for #641? I can see that it will stop GetValidatedMetadata
and GetMeta
from throwing errors when a name is missing and it finds a generateName instead, but there are few other issues.
For instance, how does generateName
interact with the namePrefix and nameSuffix transformers? What happens when two different resources have the same value for generateName
? This fix also only touches kyaml; there are many layers in the api
module that expects the name
field to be populated and does tracking of the resource based on that.
On the surface, I think the changes in this PR are fine, and probably even quite useful for any third party users of kyaml. But it feels a bit incomplete. It would be helpful to have more examples for kyaml functions that use GetValidatedMetadata
and GetMeta
to demonstrate where and how this would be used, e.g. in any filters or other external methods. A PR with tests (or even just a comment with a few examples) demonstrating the utility of including GenerateName
just in kyaml would be useful, and could potentially be a great first step to fixing #641.
Kustomize, however, is much more than kyaml. For us to say we've "fixed #641", we need a few e2e tests in api/krusty
demonstrating that it works correctly in a variety of situations. Getting those tests to pass will likely involve some large changes in the api module, in particular I would expect it to at least involve significant changes to the NameReferenceTransformer
among other things. There is ongoing discussion on the best implementation approach in #641, so I would recommend discussing your approach there before working on that PR.
kyaml/yaml/rnode.go
Outdated
@@ -1071,7 +1075,7 @@ func (rn *RNode) GetValidatedMetadata() (ResourceMeta, error) { | |||
// A list doesn't require a name. | |||
return m, nil | |||
} | |||
if m.NameMeta.Name == "" { | |||
if m.NameMeta.Name == "" && m.NameMeta.GenerateName == "" { | |||
return m, fmt.Errorf("missing metadata.name in object %v", m) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we need to change the error message if we do support this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was more afraid of changing the error message, giving too much hint about generateName :) I'll have a look on it though.
@@ -406,6 +406,28 @@ func TestRNodeGetValidatedMetadata(t *testing.T) { | |||
errMsg: "missing metadata.name", | |||
}, | |||
}, | |||
"generateNameConfigMap": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides GetMeta
and GetValidatedMetadata
specifically, does this change impact any other functions or methods in kyaml? If so, we should have a few tests in those areas to demonstrate any behavioral changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't, in fact, I don't see too much value of generateName
outside of its field.
In ❯ cat configmap.yml
apiVersion: v1
kind: ConfigMap
metadata:
generateName: configmap-
data:
hello: hallo
❯ k apply -f configmap.yml
error: from configmap-: cannot use generate name with apply
❯ k create -f configmap.yml
configmap/configmap-wgtnm created
❯ k create -f configmap.yml
configmap/configmap-gxwp9 created
❯ k create -f configmap.yml
configmap/configmap-pdnjf created
❯ k create -f configmap.yml
configmap/configmap-xkndv created There's very little I think kustomize can do with this concept. I don't see too much benefit of even In my opinion, this
Since the final name of the resource will be determined by the server, I don't see a way to make any references to it, therefore transformers like |
Kustomize is client-side only. At the very least, for #641, we need to have e2e tests in |
I know what |
I don't know. I mean, my gut feeling is that we should better off not applying |
@julian7: 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. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: julian7 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 |
@natasha41575 @mengqiy @phanimarupaka could you please have a look? |
I think before we can accept this PR, we need to agree on several details. Again, some more things that come to mind:
I plan to bring this PR up with the other kustomize maintainers but if you have thoughts on these points feel free to share here. @KnVerey can you think of anything else we need to make sure we think about? Edited to add: I talked with the other maintainers and I think we need to see tests that show the use of |
f.Referrer.GetGenerateName()); err != nil { | ||
if err = checkEqual( | ||
"Name", meta.Name, f.Referrer.GetName()); err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why you needed to make this change? What behavior does it affect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yikes. It seemed to be a good idea at the time. All tests run just fine if you leave this change out. Originally, we had to protect GetName if there was no name, and no generateName. However, RNode's GetName
does the check better, to generate a suffix checksum only if GetGenerateName exists.
This needs a force push, this would look awful in git history.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I was wrong (while switching back to checkEqual-ing Name only):
--- FAIL: TestGenerateName (0.00s)
harness.go:100: node-referrerOriginal 'Name' mismatch '' != 'job-[0a07560513]'
--- FAIL: TestBase (0.00s)
harness.go:100: node-referrerOriginal 'Name' mismatch '' != 'job-[320078361f]'
--- FAIL: TestMidLevelA (0.01s)
harness.go:100: node-referrerOriginal 'Name' mismatch '' != 'job-[d66b9a897d]'
--- FAIL: TestMidLevelB (0.01s)
harness.go:100: node-referrerOriginal 'Name' mismatch '' != 'job-[36d25ef670]'
--- FAIL: TestMultibasesNoConflict (0.01s)
harness.go:100: node-referrerOriginal 'Name' mismatch '' != 'job-[36d25ef670]'
I remember now just a bit better: if metadata.name
is empty, but metadata.generateName
is not, rnode.GetName()
is returning a name artificially generated (for identification purposes). In cases like this, we should better check metadata.generateName
instead.
I enclosed calling rnode.GetName()
with rnode.GetGenerateName()
, which is rather simple, to save some computation time by not doing a checksum on the rendered resource for this if
statement.
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs 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 PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
Sorry is there any update¿? |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /close |
@k8s-triage-robot: Closed this PR. In response to this:
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. |
The sad truth is that the more I think about this, the less it makes sense. Apply with prune and force does a much better job. |
Fixes #641
As per Kubernetes API, ObjectMeta v1 has a "generateName" field which is used by the server as a prefix to make the object's final name from. This field is consumed only when "name" field is not provided. See: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#idempotency
This change makes kyaml understand "generateName", and honoring this field if "name" is not specified.