Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(log): add custom error handler for Kubernetes API errors (#1024)
# Description This pull request includes changes to improve error handling and logging in the Kubernetes watcher and to simplify error checking in the endpoint reconciler. The most important changes include adding a custom error handler for the Kubernetes watcher, importing necessary packages, and simplifying error handling logic. Improvements to error handling and logging: * [`pkg/k8s/watcher_linux.go`](diffhunk://#diff-1769e0320129167654a2a0d5f382b63fb459aadf221d3ba04df1f1a56188f6d2R105-R123): Added a custom error handler `retinaK8sErrorHandler` to log specific Kubernetes API server errors and tag them for easier identification. * [`pkg/k8s/watcher_linux.go`](diffhunk://#diff-1769e0320129167654a2a0d5f382b63fb459aadf221d3ba04df1f1a56188f6d2R23-R29): Registered the custom error handler in the `init` function to ensure it is used by the watcher. Code simplification: * [`pkg/controllers/operator/cilium-crds/endpoint/endpoint_controller.go`](diffhunk://#diff-0a6e7a396be9617c3c31afb9cf9f740b75e645a533833d049726db8321d13df9L536-R536): Simplified the error checking logic in `handlePodUpsert` by removing redundant error check. ## Checklist - [X] I have read the [contributing documentation](https://retina.sh/docs/contributing). - [X] I signed and signed-off the commits (`git commit -S -s ...`). See [this documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification) on signing commits. - [X] I have correctly attributed the author(s) of the code. - [X] I have tested the changes locally. - [X] I have followed the project's style guidelines. - [X] I have updated the documentation, if necessary. - [X] I have added tests, if applicable. ## Testing I removed permission for retina agent to read nodes and services. I can see the completer error as as our custom message coming from retina. ``` time="2024-11-26T16:05:33Z" level=error msg="Potentially Network Error coming from K8s API Server failing to watch Services" actualError="pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:232: Failed to watch *v1.Service: failed to list *v1.Service: services is forbidden: User \"system:serviceaccount:kube-system:retina-agent\" cannot list resource \"services\" in API group \"\" at the cluster scope" subsys=k8s-watcher ``` --- Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more information on how to contribute to this project.
- Loading branch information