From 2743547b40cb5bd88e1433012937c5213df626be Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Thu, 29 Jan 2026 12:28:42 +0800 Subject: [PATCH] Reduce logging level of DumpSecret to v(4) (#1357) It generates a lot of noises otherwise Signed-off-by: Jian Qiu --- pkg/common/options/options_test.go | 6 ++---- .../spoke/registration/secret_controller.go | 15 +++++++-------- .../spoke/registration/secret_controller_test.go | 5 +---- pkg/registration/spoke/spokeagent.go | 4 ++-- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/pkg/common/options/options_test.go b/pkg/common/options/options_test.go index c7e445ee1..106c9e5a6 100644 --- a/pkg/common/options/options_test.go +++ b/pkg/common/options/options_test.go @@ -14,8 +14,6 @@ import ( kubefake "k8s.io/client-go/kubernetes/fake" clocktesting "k8s.io/utils/clock/testing" - "open-cluster-management.io/sdk-go/pkg/basecontroller/events" - testinghelpers "open-cluster-management.io/ocm/pkg/registration/helpers/testing" "open-cluster-management.io/ocm/pkg/registration/register" "open-cluster-management.io/ocm/pkg/registration/spoke/registration" @@ -90,8 +88,8 @@ func TestComplete(t *testing.T) { options.HubKubeconfigDir = dir err = registration.DumpSecret( - kubeClient.CoreV1(), componentNamespace, "hub-kubeconfig-secret", - options.HubKubeconfigDir, context.TODO(), events.NewContextualLoggingEventRecorder(t.Name())) + context.TODO(), kubeClient.CoreV1(), componentNamespace, "hub-kubeconfig-secret", + options.HubKubeconfigDir) if err != nil { t.Error(err) } diff --git a/pkg/registration/spoke/registration/secret_controller.go b/pkg/registration/spoke/registration/secret_controller.go index 0a047a788..b9e213971 100644 --- a/pkg/registration/spoke/registration/secret_controller.go +++ b/pkg/registration/spoke/registration/secret_controller.go @@ -16,7 +16,6 @@ import ( corev1client "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/klog/v2" - "open-cluster-management.io/sdk-go/pkg/basecontroller/events" "open-cluster-management.io/sdk-go/pkg/basecontroller/factory" "open-cluster-management.io/ocm/pkg/common/queue" @@ -62,21 +61,21 @@ func NewHubKubeconfigSecretController( ToController("HubKubeconfigSecretController") } -func (s *hubKubeconfigSecretController) sync(ctx context.Context, syncCtx factory.SyncContext, _ string) error { +func (s *hubKubeconfigSecretController) sync(ctx context.Context, _ factory.SyncContext, _ string) error { logger := klog.FromContext(ctx) logger.V(4).Info("Reconciling Hub KubeConfig secret", "hubKubeconfigSecretName", s.hubKubeconfigSecretName) - return DumpSecret(s.spokeCoreClient, s.hubKubeconfigSecretNamespace, s.hubKubeconfigSecretName, s.hubKubeconfigDir, ctx, syncCtx.Recorder()) + return DumpSecret(ctx, s.spokeCoreClient, s.hubKubeconfigSecretNamespace, s.hubKubeconfigSecretName, s.hubKubeconfigDir) } // DumpSecret dumps the data in the given seccret into a directory in file system. // The output directory will be created if not exists. // TO DO: remove the file once the corresponding key is removed from secret. func DumpSecret( - coreV1Client corev1client.CoreV1Interface, - secretNamespace, secretName, outputDir string, ctx context.Context, - recorder events.Recorder) error { + coreV1Client corev1client.CoreV1Interface, + secretNamespace, secretName, outputDir string) error { secret, err := coreV1Client.Secrets(secretNamespace).Get(ctx, secretName, metav1.GetOptions{}) + logger := klog.FromContext(ctx).WithValues("secretNamespace", secretNamespace, "secretName", secretName) if errors.IsNotFound(err) { return nil } @@ -98,7 +97,7 @@ func DumpSecret( if err := os.WriteFile(filename, data, 0600); err != nil { return fmt.Errorf("unable to write file %q: %w", filename, err) } - recorder.Event(ctx, "FileCreated", fmt.Sprintf("File %q is created from secret %s/%s", filename, secretNamespace, secretName)) + logger.V(4).Info("Files is created from secret", "filename", filename) case err != nil: return fmt.Errorf("unable to read file %q: %w", filename, err) case bytes.Equal(lastData, data): @@ -109,7 +108,7 @@ func DumpSecret( if err := os.WriteFile(path.Clean(filename), data, 0600); err != nil { return fmt.Errorf("unable to write file %q: %w", filename, err) } - recorder.Event(ctx, "FileUpdated", fmt.Sprintf("File %q is updated from secret %s/%s", filename, secretNamespace, secretName)) + logger.V(4).Info("Files is updated from secret", "filename", filename) } } return nil diff --git a/pkg/registration/spoke/registration/secret_controller_test.go b/pkg/registration/spoke/registration/secret_controller_test.go index 1a678b7a4..3c4b8f199 100644 --- a/pkg/registration/spoke/registration/secret_controller_test.go +++ b/pkg/registration/spoke/registration/secret_controller_test.go @@ -12,8 +12,6 @@ import ( "k8s.io/apimachinery/pkg/util/rand" kubefake "k8s.io/client-go/kubernetes/fake" - "open-cluster-management.io/sdk-go/pkg/basecontroller/events" - testinghelpers "open-cluster-management.io/ocm/pkg/registration/helpers/testing" "open-cluster-management.io/ocm/pkg/registration/register" "open-cluster-management.io/ocm/pkg/registration/register/csr" @@ -118,8 +116,7 @@ func TestDumpSecret(t *testing.T) { } err = DumpSecret( - kubeClient.CoreV1(), testNamespace, testSecretName, hubKubeconfigDir, context.TODO(), - events.NewContextualLoggingEventRecorder(t.Name())) + context.TODO(), kubeClient.CoreV1(), testNamespace, testSecretName, hubKubeconfigDir) if err != nil { t.Errorf("unexpected err: %v", err) } diff --git a/pkg/registration/spoke/spokeagent.go b/pkg/registration/spoke/spokeagent.go index f88e4c702..447e3cfbe 100644 --- a/pkg/registration/spoke/spokeagent.go +++ b/pkg/registration/spoke/spokeagent.go @@ -177,8 +177,8 @@ func (o *SpokeAgentConfig) RunSpokeAgentWithSpokeInformers(ctx context.Context, // dump data in hub kubeconfig secret into file system if it exists err = registration.DumpSecret( - managementKubeClient.CoreV1(), o.agentOptions.ComponentNamespace, o.registrationOption.HubKubeconfigSecret, - o.agentOptions.HubKubeconfigDir, ctx, recorder) + ctx, managementKubeClient.CoreV1(), o.agentOptions.ComponentNamespace, o.registrationOption.HubKubeconfigSecret, + o.agentOptions.HubKubeconfigDir) if err != nil { return err }