Hi,
The upshot is that you can denote on the CRD yaml that a particular path within your CRD is a sub resource. Common examples of this are the status and scale sub resources.
When a sub resource is defined, it means that you must use a separate sub resource client to interact with that resource, as you’ve observed already.
It prevents updates to the spec and status at the same time, as typically, these would only be updated by separate consumers (eg user updates spec, controller updates status), this creates a nice separation and prevents possible mistakes (eg an end user wiping out the status inadvertently).
I suspect what has happened in your case is that you’ve enabled the status sub resource on your new version, where it wasn’t enabled on the old version.
When you use the controller runtime client, it restores whatever the response is from the API into the object you pass into it. This is why you are seeing obj.Status zeroed after create, it matches what is on the API Server. This is intended behaviour as far as I’m aware.
If you need to make sure the status is set correctly after create, my advice would be to take a copy of the status before create, then restore it, then apply the status update.
Eg.
originalStatus := obj.Status.DeepCopy()
client.Create(ctx, obj)
obj.Status = originalStatus
client.Statut().Update(ctx, obj)
Regards,
Joel
--
Joel Speed
He/Him
Principal Software Engineer
Red Hat