ansh0014 commented on issue #6981:
URL: https://github.com/apache/camel-k/issues/6981#issuecomment-7152634298

   Hi @squakez, I looked into this and here is my initial analysis and proposed 
design:
   
   ### Root Cause
   1. At startup, `integration_controller.go` checks 
`IsAPIResourceInstalled(...)` for optional resources (`CamelMonitor`, Knative 
`Service`, etc.) and registers watches on the `controller-runtime` cache.
   2. When one of those CRDs is deleted at runtime, `client-go`'s `Reflector` 
fails `ListAndWatch` with `NotFound` / `meta.NoKindMatchError`. Since 
`cache.Options.DefaultWatchErrorHandler` is unset, `client-go`'s 
`DefaultWatchErrorHandler` falls through to 
`utilruntime.HandleErrorWithContext`, logging `"level":"error"` on every 
backoff retry.
   3. For `CamelMonitor` specifically, `monitorAction` also caches 
`camelMonitorAvailable` at startup, so `addCamelMonitorCondition` 
(`pkg/controller/integration/camel_monitor.go`) only handles 
`k8serrors.IsNotFound(err)` and would return `meta.NoKindMatchError` as a 
reconciliation error once the CRD is gone.
   
   ### Proposed Design
   1. **Custom `DefaultWatchErrorHandler` in `cache.Options` 
(`pkg/cmd/operator/operator.go`):**
      - Handle `apierrors.IsNotFound(err)` / `meta.IsNoMatchError(err)` 
gracefully (log once at info/debug instead of calling 
`utilruntime.HandleErrorWithContext`), while keeping default error handling for 
all other errors.
      - Alternative: we could also call `cache.RemoveInformer` to stop the 
reflector completely, though keeping the reflector in backoff allows automatic 
recovery if the CRD is reinstalled later without needing CRD watch RBAC.
   2. **Reconciler guard (`pkg/controller/integration/camel_monitor.go`):**
      - Handle `meta.IsNoMatchError(err)` alongside `k8serrors.IsNotFound(err)` 
in `addCamelMonitorCondition` so it removes the `CamelMonitorAvailable` 
condition instead of failing reconciliation.
   
   WDYT about this approach (especially keeping the backoff with a custom 
`DefaultWatchErrorHandler` vs removing the informer)?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to