From 6a6a6ea4e39daa283866244309d84c299a8d7b08 Mon Sep 17 00:00:00 2001 From: Almir Cunha Date: Tue, 2 Jul 2024 14:37:40 -0300 Subject: [PATCH 1/2] Add runner name to context --- operator/internal/controller/actionsrunner/wire/wire.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/operator/internal/controller/actionsrunner/wire/wire.go b/operator/internal/controller/actionsrunner/wire/wire.go index 6ea32f4..71b9760 100644 --- a/operator/internal/controller/actionsrunner/wire/wire.go +++ b/operator/internal/controller/actionsrunner/wire/wire.go @@ -35,6 +35,12 @@ import ( "github.com/inloco/kube-actions/operator/metrics" ) +type contextKey string + +const ( + runnerContextKey = contextKey("runner") +) + type Wire struct { operatorNotifier chan<- event.GenericEvent @@ -213,6 +219,7 @@ func (w *Wire) Listen() { } ctx := context.Background() + ctx = context.WithValue(ctx, runnerContextKey, w.GetRunnerName()) logger := log.FromContext(ctx, "runner", w.GetRunnerName()) w.loopClose = make(chan struct{}) From 6cafaf940257888895d2a97dfe28102f0154df32 Mon Sep 17 00:00:00 2001 From: Almir Cunha Date: Tue, 2 Jul 2024 14:45:08 -0300 Subject: [PATCH 2/2] Add the logger into context instead of adding the runner as context value --- operator/internal/controller/actionsrunner/wire/wire.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator/internal/controller/actionsrunner/wire/wire.go b/operator/internal/controller/actionsrunner/wire/wire.go index 71b9760..6688ea5 100644 --- a/operator/internal/controller/actionsrunner/wire/wire.go +++ b/operator/internal/controller/actionsrunner/wire/wire.go @@ -219,8 +219,8 @@ func (w *Wire) Listen() { } ctx := context.Background() - ctx = context.WithValue(ctx, runnerContextKey, w.GetRunnerName()) logger := log.FromContext(ctx, "runner", w.GetRunnerName()) + ctx = log.IntoContext(ctx, logger) w.loopClose = make(chan struct{}) logger.Info("Wire opened")