1

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'.

pep8
  • 371
  • 3
  • 18
  • @RakeshGupta The update function does not require namespace, I'm passing the object that I've already fetched using a GET call – pep8 Dec 27 '21 at 23:08
  • what about the context - is it using the correct ns? – Rakesh Gupta Dec 27 '21 at 23:13
  • Not modified the context at all, it is directly getting trickled down from the Reconcile() call.. – pep8 Dec 27 '21 at 23:14
  • see if this helps: https://stackoverflow.com/questions/65120965/operator-sdk-controller-failed-to-update-custom-resource-status – Rakesh Gupta Dec 27 '21 at 23:17
  • That's different from my issue -- in my case it says 'Not found', it doesn't give the usual 'object has been modified error' – pep8 Dec 27 '21 at 23:24

2 Answers2

3

I was able to resolve this issue myself using:

r.Update(ctx, myResource) instead of r.Status().Update(ctx, myResource)

pep8
  • 371
  • 3
  • 18
2

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

TJ Liu
  • 354
  • 1
  • 8