Skip to content

Commit

Permalink
fix bug causing multiple appName fields appended to logger
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsgstrabo committed Dec 18, 2024
1 parent 290c284 commit 8817912
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions charts/radix-cluster-cleanup/Chart.yaml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions radix-cluster-cleanup/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions radix-cluster-cleanup/cmd/stopRrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
}

Expand Down

0 comments on commit 8817912

Please sign in to comment.