Skip to content

Commit

Permalink
refactor: standardize get CR in Reconcile
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>
  • Loading branch information
TylerGillson committed Nov 16, 2023
1 parent 7146c9a commit 9fbfff0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 7 additions & 2 deletions internal/controller/validationresult_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
apierrs "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -60,15 +61,19 @@ func (r *ValidationResultReconciler) Reconcile(ctx context.Context, req ctrl.Req
vc := &v1alpha1.ValidatorConfig{}
vcKey := types.NamespacedName{Namespace: r.Namespace, Name: constants.ValidatorConfig}
if err := r.Get(ctx, vcKey, vc); err != nil {
r.Log.Error(err, "failed to fetch ValidatorConfig", "key", vcKey)
if !apierrs.IsNotFound(err) {
r.Log.Error(err, "failed to fetch ValidatorConfig", "key", req)
}
return ctrl.Result{}, client.IgnoreNotFound(err)
}

vr = &v1alpha1.ValidationResult{}
vrKey = req.NamespacedName

if err := r.Get(ctx, req.NamespacedName, vr); err != nil {
r.Log.Error(err, "failed to fetch ValidationResult", "key", req)
if !apierrs.IsNotFound(err) {
r.Log.Error(err, "failed to fetch ValidationResult", "key", req)
}
return ctrl.Result{}, client.IgnoreNotFound(err)
}

Expand Down
4 changes: 3 additions & 1 deletion internal/controller/validatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func (r *ValidatorConfigReconciler) Reconcile(ctx context.Context, req ctrl.Requ

vc := &v1alpha1.ValidatorConfig{}
if err := r.Get(ctx, req.NamespacedName, vc); err != nil {
r.Log.Error(err, "failed to fetch ValidatorConfig", "key", req)
if !apierrs.IsNotFound(err) {
r.Log.Error(err, "failed to fetch ValidatorConfig", "key", req)
}
return ctrl.Result{}, client.IgnoreNotFound(err)
}

Expand Down

0 comments on commit 9fbfff0

Please sign in to comment.