我目前正在使用 Golang 和 Operator SDK 编写一个 Kubernetes Operator。
为了知道资源的创建是否超时,我检查了CreationTimestamp
当前资源的属性。成功后Update
我想更新该CreationTimestamp
资源的,但是当我这样做时,什么都没有发生并且CreationTimestamp
保持不变......
我的Reconcile
循环看起来像这样:
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()
//...
}
或者有没有其他方法可以跟踪上次协调资源的时间?