I have a CRD and it's operator, when CR updated, operator will modify the status of this CR to updating
from done
. After all operation done, operator will change the status into done
again.
I wrote another go client program to modify this CR and wait until it done. But when I query the status of this CR just after send the request to k8s, the status is still done
(the operator is not fast enough to change it to updating
before this), so the program will consider it already updated, but in fact, it wasn't.
My solution is when updating the CR, set the status to unknown
first, and let operator modify it to updating
. But I think this is not a good way.
Anyone know the best practice of this situation? Thanks a lot!
You could look for the time at which the status was set to 'done', which is hopefully something your custom resource provides in its status conditions/history. If it's earlier than the start of your program, then it certainly isn't the right 'done'.
Native Kubernetes resources such as Pods follow this pattern. See the following link and note the 'lastTransitionTime' field. https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-conditions
This reporting of a change may also happen through the emitting of a Kubernetes event, depending on the custom resource.