From a00f1efbdedfaa6873066d17eab73507812f3011 Mon Sep 17 00:00:00 2001 From: Miles Garnsey Date: Mon, 20 May 2024 14:20:03 +1000 Subject: [PATCH] Actually log when a replicated secret is screwing up. --- controllers/replication/secret_controller.go | 4 ++-- controllers/replication/secret_controller_test.go | 6 ++++-- main.go | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/controllers/replication/secret_controller.go b/controllers/replication/secret_controller.go index 1a5cd17e2..3e6d019a2 100644 --- a/controllers/replication/secret_controller.go +++ b/controllers/replication/secret_controller.go @@ -85,7 +85,7 @@ func (s *SecretSyncController) Reconcile(ctx context.Context, req ctrl.Request) secrets, err := s.fetchAllMatchingSecrets(ctx, selector, rsec.Namespace) if err != nil { - logger.Error(err, "Failed to fetch the replicated secrets to cleanup", "ReplicatedSecret", req.NamespacedName) + logger.Error(err, "Failed to fetch the replicated secrets to cleanup", "ReplicatedSecret", req.NamespacedName, "Namespace", rsec.Namespace) return reconcile.Result{}, err } @@ -186,7 +186,7 @@ func (s *SecretSyncController) Reconcile(ctx context.Context, req ctrl.Request) // Fetch all the secrets that match the ReplicatedSecret's rules secrets, err := s.fetchAllMatchingSecrets(ctx, selector, req.Namespace) if err != nil { - logger.Error(err, "Failed to fetch linked secrets", "ReplicatedSecret", req.NamespacedName) + logger.Error(err, "Failed to fetch linked secrets", "ReplicatedSecret", req.NamespacedName, "namespace", req.Namespace) return reconcile.Result{Requeue: true}, err } // Verify secrets have up-to-date hashes diff --git a/controllers/replication/secret_controller_test.go b/controllers/replication/secret_controller_test.go index c06b0a972..4156a0c1a 100644 --- a/controllers/replication/secret_controller_test.go +++ b/controllers/replication/secret_controller_test.go @@ -46,13 +46,15 @@ func TestSecretController(t *testing.T) { ctx := testutils.TestSetup(t) ctx, cancel := context.WithCancel(ctx) testEnv = &testutils.MultiClusterTestEnv{NumDataPlanes: 2} - err := testEnv.Start(ctx, t, func(mgr manager.Manager, clientCache *clientcache.ClientCache, clusters []cluster.Cluster) error { + logger, err := logr.FromContext(ctx) + require.NoError(t, err) + err = testEnv.Start(ctx, t, func(mgr manager.Manager, clientCache *clientcache.ClientCache, clusters []cluster.Cluster) error { scheme = mgr.GetScheme() logger = mgr.GetLogger() return (&SecretSyncController{ ReconcilerConfig: config.InitConfig(), ClientCache: clientCache, - }).SetupWithManager(mgr, clusters) + }).SetupWithManager(mgr, clusters, logger) }) if err != nil { t.Fatalf("failed to start test environment: %s", err) diff --git a/main.go b/main.go index e74408db4..a79f85842 100644 --- a/main.go +++ b/main.go @@ -214,7 +214,7 @@ func main() { ReconcilerConfig: reconcilerConfig, ClientCache: clientCache, WatchNamespaces: []string{watchNamespace}, - }).SetupWithManager(mgr, additionalClusters); err != nil { + }).SetupWithManager(mgr, additionalClusters, setupLog); err != nil { setupLog.Error(err, "unable to create controller", "controller", "SecretSync") os.Exit(1) }