-
Notifications
You must be signed in to change notification settings - Fork 423
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
Objectmeta of embedded object goes missing during CRD conversion #448
Comments
/kind bug any idea if this is happening during the conversion webhook? Can you post a reproducer? |
I had added logs to the ConvertTo(dstRaw conversion.Hub) and ConvertFrom(srcRaw conversion.Hub) functions in the file api/v<>/<>_conversion.go to display the contents of the ObjectMeta from the CRD and the embedded PodTemplateSpec. The ObjectMeta.Name etc from the CRD level had the expected contents but the contents from the embedded podtemplatespec were nulled. Are there other places that may be useful to log ? I was wondering if the api-server itself could have chosen to not send the metadata of the embedded spec to the webhook. Have not looked yet at what all layers are in play between the api-server and the ConvertTo/From functions. I am wondering if I am missing some knob. I was following the kubebuilder book on the conversion. The CRD structure is on the lines of ; The embedded podtemplate spec contents are visible in the last-applied-configuration annotation of the CRD so the info did make it to the api-server. I will try to post a repro. Thanks ! |
I created a simple repro for this issue. @DirectXMan12 please see https://github.com/champak/repro-kbuilder-version-issue . If the sample yaml at https://github.com/champak/repro-kbuilder-version-issue/blob/master/config/samples/left_v1alpha1_repro.yaml is applied, the logs at the webhook converter look like
The name of the CRD "repro-sample" show up. The name of the Pod does not. The logs are from api/v1/repro_conversion.go. The versions are going between v1alpha1 and v1. I followed the kubebuilder scaffolds and book. If logs elsewhere would tell us more send a ptr. Thanks for looking ! |
And a get on the CRD looks like
The pod metadata is missing. Similar behavior for embedding other native types like PVCs or services. Perhaps I am missing some setting but found nothing yet. |
@DirectXMan12 let me know if I try to get any other details etc. that may help. I hope the example provides enough info. One thing I had noted is that the meta-data was missing even before we hit the convert functions. For the v1alpha1 CR version we hit the reconcile loop before going to the convert callbacks and the bits are already missing. That made me wonder if it is the apiserver that may have pruned the info due to some setting. The operator initialization log had
|
@DirectXMan12 please let me know if you need any other info to take a look into this issue. Thanks ! |
@DirectXMan12 Thanks for taking a look ! If there is any hack that would allow crd conversion to work w/o needing preserveUnknownFields: false let me know and I can try it out. I could not tell if the changes from #385, #395 will get pulled into controller-gen main. I did not follow what functional need makes preserveUnknownFields: false mandatory. I can see it is desirable since dealing with conversion of unstructured data is ill-defined. But in many cases we merely want the unstructured blob to flow over to the new CRD version without changes. Would be nice to have a means for that. |
kubernetes itself requires |
@DirectXMan12 thanks for explaining ; in that case it sounds like something on the lines of #395 would be needed. I did not see updates on the issue since Jan ; is a different approach under consideration ? Think it would be essential to preserve at least a few common fields from ObjectMeta like name, namespace to be able to make embeddable native resources work well in a versioned CRD. Base types like replicasets embed podspecs and can handle version changes. Would be awesome to be able to do that with CRDs as well. |
@DirectXMan12 is there any possibility of a fix or workaround for this issue in the near future ? Thanks. |
@DirectXMan12 I see the review for #395 is still open. Any chance it will be available soon ? Else are there other options for getting around this issue ? Thanks |
@DirectXMan12 @droot are the changes on #395 planned for any upcoming release ? There does not seem to be a reasonable workaround. Using a custom version of ObjectMeta is not an option for anything that is already out there. Was hoping there would be a fix or the changes on #395 will get merged. |
@DirectXMan12 Thanks for getting back. I shall give it a shot. Were you saying we need a crd option for controller-gen on the lines of trivialVersions or maxDescLen to turn this on ? |
Yeah, exactly. Note that @sttts has a counter-proposal, so might be worth reconciling that (pun intended ;-) ) |
@DirectXMan12 I added a simple option for using #395 (see above). Pl take a look when you can and let me know what it needs. I could not find a decent way to test with a private version of controller-gen. The go get mechanism in the kubebuilder makefile want to install a published version. If you send a ptr on how to test it out shall run thru it. Thanks. |
@DirectXMan12 just polling on this issue... |
|
Thanks @DirectXMan12 I had been looking for a way to build a local version and use it with kubebuilder. I had built it like you suggested and then put in my path to prevent the kubebuilder Makefile from pulling the published version down. That worked OK but had wondered if there is better way etc. |
I had the same issue!!! It had been extremely puzzling until I realized there is something to do with controller-gen. Thank you for raising it and developers for fixing it! |
@champak did you found a solution? |
It's still not clear to me what is causing the embedded |
Unknown metadata fields are pruned https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#field-pruning If you change from v1beta CRDs to v1 CRDs the metadata field is pruned and the operator believes that every podSpec is incorrect. Related to kubernetes-sigs/controller-tools#448
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
Fixed by #557 no ? |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-contributor-experience at kubernetes/community. |
The Kubernetes project currently lacks enough active 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. /close |
@k8s-triage-robot: Closing this issue. 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. |
Yes, it's fixed now. Use the controller-gen crd option |
Hi guys, I tried with "crd:generateEmbeddedObjectMeta=true" and generated manifests and go code again but it still isn't working my makefile targets: generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. ` |
Found the issue, I was using Makefile generated by Kubebuilder, after adding this flag "crd:generateEmbeddedObjectMeta=true" to "manifests" target, somehow the location of generated crd yaml was changed and I kept applying the older ones. |
Using the "crd:generateEmbeddedObjectMeta=true" flag fixes the issue but it is generating two versions of the manifests:
|
- Add WorkloadType and WorkloadObject fields to PodInfo. - Export workload.GetWorkloadMetaFromPod() function so that the operator can call it to set WorkloadType and WorkloadObject fields. - Update equal() function to take these fields into account. I opted for defining a new WorkloadObjectMeta type instead of using metav1.ObjectMeta to avoid generating unnecessary "unknown field" log messages. See [1] for additional context. [1]: kubernetes-sigs/controller-tools#448 Signed-off-by: Michi Mutsuzaki <michi@isovalent.com>
- Add WorkloadType and WorkloadObject fields to PodInfo. - Export workload.GetWorkloadMetaFromPod() function so that the operator can call it to set WorkloadType and WorkloadObject fields. - Update equal() function to take these fields into account. I opted for defining a new WorkloadObjectMeta type instead of using metav1.ObjectMeta to avoid generating unnecessary "unknown field" log messages. See [1] for additional context. [1]: kubernetes-sigs/controller-tools#448 Signed-off-by: Michi Mutsuzaki <michi@isovalent.com>
I was also getting similar results until I understood how the command works. At first, I was wrongly adding the That solved my issues without generating any extra files at unexpected folders |
- Add WorkloadType and WorkloadObject fields to PodInfo. - Export workload.GetWorkloadMetaFromPod() function so that the operator can call it to set WorkloadType and WorkloadObject fields. - Update equal() function to take these fields into account. I opted for defining a new WorkloadObjectMeta type instead of using metav1.ObjectMeta to avoid generating unnecessary "unknown field" log messages. See [1] for additional context. [1]: kubernetes-sigs/controller-tools#448 Signed-off-by: Michi Mutsuzaki <michi@isovalent.com>
Hi! I fixed my makefile, but 'controller-gen' generates the role.yaml in crd/bases/ . What i should do ?
|
Hi folks,
I ran into an odd issue with CRD conversion using controller-tools v0.2.4/kubebuilder 2.2.0/apiserver 17.1 This CRD has embedded native specs like the PodTemplateSpec in its spec. I found that in the conversion functions the ObjectMeta of the embedded PodTemplateSpec is nulled out. Other attributes look OK. There is nothing in the validation callback. I had needed to add preserveUnknownFields: false to the CRD to be able to deploy the yaml; not sure if that has some sideffect
The ObjectMeta for the CRD itself shows up fine. It is the embedded spec's ObjectMeta that seemed to be affected. Does this sound like any known issue ? One that looked somewhat related from a search was #279 with comments from @DirectXMan12 but was not quite the same problem.
Thanks for any insight !
The text was updated successfully, but these errors were encountered: