From 881791202dfe4196d5e627a6304a57dcd40ae50e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Gustav=20Str=C3=A5b=C3=B8?= <65334626+nilsgstrabo@users.noreply.github.com> Date: Wed, 18 Dec 2024 10:54:57 +0100 Subject: [PATCH] fix bug causing multiple appName fields appended to logger --- charts/radix-cluster-cleanup/Chart.yaml | 4 ++-- radix-cluster-cleanup/cmd/root.go | 5 ++--- radix-cluster-cleanup/cmd/stopRrs.go | 7 ++++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/charts/radix-cluster-cleanup/Chart.yaml b/charts/radix-cluster-cleanup/Chart.yaml index 0f8772c..869bdcb 100644 --- a/charts/radix-cluster-cleanup/Chart.yaml +++ b/charts/radix-cluster-cleanup/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v1 description: A Helm chart for Kubernetes name: radix-cluster-cleanup -version: 1.0.17 -appVersion: 1.0.17 +version: 1.0.18 +appVersion: 1.0.18 diff --git a/radix-cluster-cleanup/cmd/root.go b/radix-cluster-cleanup/cmd/root.go index 923e1df..46a356c 100644 --- a/radix-cluster-cleanup/cmd/root.go +++ b/radix-cluster-cleanup/cmd/root.go @@ -187,15 +187,14 @@ func runFunctionPeriodically(ctx context.Context, someFunc func(ctx context.Cont } func getTooInactiveRrs(ctx context.Context, kubeClient *kube.Kube, inactivityLimit time.Duration, action string) ([]v1.RadixRegistration, error) { - logger := log.Ctx(ctx) rrs, err := kubeClient.ListRegistrations(ctx) if err != nil { return nil, err } var rrsForDeletion []v1.RadixRegistration for _, rr := range rrs { - logger := logger.With().Str("appName", rr.Name).Logger() - ctx = logger.WithContext(ctx) + logger := log.Ctx(ctx).With().Str("appName", rr.Name).Logger() + ctx := logger.WithContext(ctx) if isWhitelisted(rr) { logger.Debug().Msg("RadixRegistration is whitelisted, skipping") diff --git a/radix-cluster-cleanup/cmd/stopRrs.go b/radix-cluster-cleanup/cmd/stopRrs.go index f158b81..1b138ae 100644 --- a/radix-cluster-cleanup/cmd/stopRrs.go +++ b/radix-cluster-cleanup/cmd/stopRrs.go @@ -62,8 +62,9 @@ func stopRrs(ctx context.Context) error { if err != nil { return err } + for _, rr := range tooInactiveRrs { - ctx = log.Ctx(ctx).With().Str("appName", rr.Name).Logger().WithContext(ctx) + ctx := log.Ctx(ctx).With().Str("appName", rr.Name).Logger().WithContext(ctx) err := stopRr(ctx, kubeClient, rr) if err != nil { return err @@ -84,7 +85,7 @@ func stopRr(ctx context.Context, kubeClient *kube.Kube, rr v1.RadixRegistration) } for _, rd := range slice.FindAll(rdsForRr, rdIsActive) { - ctx = log.Ctx(ctx).With().Str("deployment", rd.Name).Logger().WithContext(ctx) + ctx := log.Ctx(ctx).With().Str("deployment", rd.Name).Logger().WithContext(ctx) if err := scaleRdComponentsToZeroReplicas(ctx, kubeClient, rd); err != nil { return err } @@ -101,10 +102,10 @@ func scaleRdComponentsToZeroReplicas(ctx context.Context, kubeClient *kube.Kube, componentNames = append(componentNames, rd.Spec.Components[i].Name) } _, err := kubeClient.RadixClient().RadixV1().RadixDeployments(rd.Namespace).Update(ctx, &rd, metav1.UpdateOptions{}) - logger.Info().Msgf("scaled components %s to 0 replicas", strings.Join(componentNames, ", ")) if err != nil { return err } + logger.Info().Msgf("scaled components %s to 0 replicas", strings.Join(componentNames, ", ")) return nil }