From eec764bcd200a74ae6a736821b356fb7d1d8b347 Mon Sep 17 00:00:00 2001 From: Andrew Bays Date: Tue, 6 Aug 2024 12:56:14 +0000 Subject: [PATCH] Log 'not found' error instead of returning it alongside RequeueAfter (cherry picked from commit 3824fa1dcd11b80bcbbd973c29edc792eacd3783) --- modules/common/configmap/configmap.go | 4 +++- modules/common/secret/secret.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/common/configmap/configmap.go b/modules/common/configmap/configmap.go index d4cc0aa4..c52a97c4 100644 --- a/modules/common/configmap/configmap.go +++ b/modules/common/configmap/configmap.go @@ -29,6 +29,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + "sigs.k8s.io/controller-runtime/pkg/log" corev1 "k8s.io/api/core/v1" k8s_errors "k8s.io/apimachinery/pkg/api/errors" @@ -283,9 +284,10 @@ func VerifyConfigMap( err := reader.Get(ctx, configMapName, configMap) if err != nil { if k8s_errors.IsNotFound(err) { + log.FromContext(ctx).Info("ConfigMap not found", "configMapName", configMapName) return "", ctrl.Result{RequeueAfter: requeueTimeout}, - fmt.Errorf("ConfigMap %s not found", configMapName) + nil } return "", ctrl.Result{}, fmt.Errorf("Get ConfigMap %s failed: %w", configMapName, err) } diff --git a/modules/common/secret/secret.go b/modules/common/secret/secret.go index 3c09010c..4f31f05a 100644 --- a/modules/common/secret/secret.go +++ b/modules/common/secret/secret.go @@ -34,6 +34,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + "sigs.k8s.io/controller-runtime/pkg/log" ) // Hash function creates a hash of a Secret's Data and StringData fields and @@ -420,9 +421,10 @@ func VerifySecret( err := reader.Get(ctx, secretName, secret) if err != nil { if k8s_errors.IsNotFound(err) { + log.FromContext(ctx).Info("Secret not found", "secretName", secretName) return "", ctrl.Result{RequeueAfter: requeueTimeout}, - fmt.Errorf("Secret %s not found", secretName) + nil } return "", ctrl.Result{}, fmt.Errorf("Get secret %s failed: %w", secretName, err) }