Reputation: 401
I have written a k8s controller with kubebuilder which reconciles my CustomResource object (MyResource).
During update, controller-runtime gives me an error 'not found' even though my resource exists on the cluster.
func (r *MyResourceReconciler) updateStatus(ctx context.Context, myResource *myResourcev1.MyResource, neoStatus *myResourcev1.MyResourceStatus) error {
if !reflect.DeepEqual(&myResource.Status, neoStatus) {
myResource.Status = *neoStatus
err := r.Status().Update(ctx, myResource)
return err
}
return nil
}
Can someone please help me troubleshoot this error? I'm stuck because I can do a GET on the resource using kubectl on the cluster & yet controller-runtime says 'not found'.
Upvotes: 1
Views: 1658
Reputation: 181
If you are facing the issue when use fake.ClientBuilder
in you test, you need to add .WithStatusSubresource(obj)
to the fake.Client
.
Upvotes: 3
Reputation: 394
I had exactly the same issue while another type works perfectly. Finally I found the root cause.
You need to have this mark above your struct to enable status subresources.
//+kubebuilder:subresource:status
https://book-v1.book.kubebuilder.io/basics/status_subresource.html
Upvotes: 3
Reputation: 401
I was able to resolve this issue myself using:
r.Update(ctx, myResource)
instead of r.Status().Update(ctx, myResource)
Upvotes: 4