newrelic / newrelic-kubernetes-operator

Operator to create New Relic configuration in Kubernetes
Apache License 2.0
43 stars 21 forks source link

chore: surface errors, requeue, refactor #118

Closed trutx closed 3 years ago

trutx commented 4 years ago

The initial idea in this PR was to surface the underlying errors that happen when r.Client.Get()ing an object from the API which is not found. So i.e. if we try to get a non-existing Secret we'll now get the actual error instead of a misleading api key is blank error.

Additionally, all Reconcile() functions now return ctrl.Request{}, err when a r.Client.Get() error occurs, thus making use of the retry mechanism which is built-in into the controller.

However, some of the strict pre-commit hooks started not passing because of a cyclomatic complexity of 21 in some Reconcile() functions, so I ultimately refactored a bunch of them. I basically moved the resource creation/update part out of Reconcile() and into a new writeNewRelicAlertCondition() function.

CLAassistant commented 4 years ago

CLA assistant check
All committers have signed the CLA.

thande commented 3 years ago

Looks good, confirmed is working as expected

level":"error","ts":1602783834.0332706,"logger":"controller-runtime.controller","msg":"Reconciler error","controller":"alertspolicy","request":"default/my-policy","error":"Secret \"nr-api-key\" not found","stacktrace":"github.com/go-logr/zapr...