vshn / espejo

OpenShift and Kubernetes Object Syncer
BSD 3-Clause "New" or "Revised" License
11 stars 2 forks source link

Patch CRD with embedded resources on our own #95

Closed ccremer closed 3 years ago

ccremer commented 3 years ago

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 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