Adding markers like // +kubebuilder:validation:EmbeddedResource only affects the direct field.
In case of arrays and maps, we need this marker to be on the container type.
We tried it with aliasing 'Unstructured' before, but Go's deserialization from JSON does not recognize embedded resources.
When debugging a reconcile request, I saw that the JSON from the server was correctly filled with the sync items. But somehow deserialization to the aliased SyncItem left the sync item empty. But somehow mapping the server-supplied resource to a SyncConfig works differently when the resource is being watched vs GETted.
I was not able to debug why deserialization sometimes works, sometimes doesn't. Given the wasted time, I propose to patch the CRD on our own. We just have to move the x-kubernetes-embedded-resource: true and x-kubernetes-preserve-unknown-fields: true flags to the right locations. With this patch, I see expected lines in the espejo logs.
I have no idea why e2e-tests passed before. Without this patch, espejo spews errors. It's a real mystery.
Checklist
[x] Keep pull requests small so they can be easily reviewed.
[x] Categorize the PR by setting a good title and adding one of the labels:
bug, enhancement, documentation, change, breaking,
as they show up in the changelog
Summary
Ok, this is a strange one.
Adding markers like
// +kubebuilder:validation:EmbeddedResource
only affects the direct field. In case of arrays and maps, we need this marker to be on the container type. We tried it with aliasing 'Unstructured' before, but Go's deserialization from JSON does not recognize embedded resources.When debugging a reconcile request, I saw that the JSON from the server was correctly filled with the sync items. But somehow deserialization to the aliased
SyncItem
left the sync item empty. But somehow mapping the server-supplied resource to aSyncConfig
works differently when the resource is being watched vs GETted.I was not able to debug why deserialization sometimes works, sometimes doesn't. Given the wasted time, I propose to patch the CRD on our own. We just have to move the
x-kubernetes-embedded-resource: true
andx-kubernetes-preserve-unknown-fields: true
flags to the right locations. With this patch, I see expected lines in the espejo logs.I have no idea why e2e-tests passed before. Without this patch, espejo spews errors. It's a real mystery.
Checklist
bug
,enhancement
,documentation
,change
,breaking
, as they show up in the changelog