I am currently writing a Kubernetes Operator using Golang and the Operator SDK.
In order to know if the creation of a resource has timed out I check the CreationTimestamp property of my current resource. After a successful Update I want to update the CreationTimestamp of that resource, but when I do that, nothing happens and the CreationTimestamp stays the same...
My Reconcile loop looks something like this:
func (r *MyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
myObject := &v1alpha1.My{}
err := r.Get(ctx, req.NamespacedName, myObject)
if err != nil {
// do something
}
//if marked to be deleted
//do something
//...
//if marked to be updated
myObject.SetCreationTimestamp(v1.Now())
err = r.Update(ctx, configMap) //updates all fields that I changed except for CreationTimestamp...
if err != nil {
println("ERR:", err.Error()) //doesnt get thrown
}
println(myObject.CreationTimestamp) //still the old timestamp instead of v1.Now()
//...
}
Or is there any other way to track when the resource was reconciled the last time?