Skip to content

Commit 42dcb87

Browse files
author
Paulo Gomes
committed
Add reconcileID to all reconcilers
GitRepository introduced correlation ID to improve transport level logging. This change aligns the other reconcilers to the same approach. Signed-off-by: Paulo Gomes <[email protected]>
1 parent cea9ea9 commit 42dcb87

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

controllers/bucket_controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
corev1 "k8s.io/api/core/v1"
3535
"k8s.io/apimachinery/pkg/runtime"
3636
"k8s.io/apimachinery/pkg/types"
37+
"k8s.io/apimachinery/pkg/util/uuid"
3738
kuberecorder "k8s.io/client-go/tools/record"
3839
ctrl "sigs.k8s.io/controller-runtime"
3940
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -246,7 +247,13 @@ func (r *BucketReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager, opts Buc
246247

247248
func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, retErr error) {
248249
start := time.Now()
249-
log := ctrl.LoggerFrom(ctx)
250+
log := ctrl.LoggerFrom(ctx).
251+
// Sets a reconcile ID to correlate logs from all suboperations.
252+
WithValues("reconcileID", uuid.NewUUID())
253+
254+
// logger will be associated to the new context that is
255+
// returned from ctrl.LoggerInto.
256+
ctx = ctrl.LoggerInto(ctx, log)
250257

251258
// Fetch the Bucket
252259
obj := &sourcev1.Bucket{}

controllers/gitrepository_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ import (
2929

3030
securejoin "github.com/cyphar/filepath-securejoin"
3131
"github.com/fluxcd/pkg/runtime/logger"
32-
"github.com/google/uuid"
3332
corev1 "k8s.io/api/core/v1"
3433
"k8s.io/apimachinery/pkg/runtime"
3534
"k8s.io/apimachinery/pkg/types"
35+
"k8s.io/apimachinery/pkg/util/uuid"
3636
kuberecorder "k8s.io/client-go/tools/record"
3737
ctrl "sigs.k8s.io/controller-runtime"
3838
"sigs.k8s.io/controller-runtime/pkg/builder"
@@ -161,8 +161,8 @@ func (r *GitRepositoryReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager, o
161161
func (r *GitRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, retErr error) {
162162
start := time.Now()
163163
log := ctrl.LoggerFrom(ctx).
164-
// Sets a correlation ID for all transport level logs.
165-
WithValues("cid", uuid.New())
164+
// Sets a reconcile ID to correlate logs from all suboperations.
165+
WithValues("reconcileID", uuid.NewUUID())
166166

167167
// logger will be associated to the new context that is
168168
// returned from ctrl.LoggerInto.

controllers/helmchart_controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3636
"k8s.io/apimachinery/pkg/runtime"
3737
"k8s.io/apimachinery/pkg/types"
38+
"k8s.io/apimachinery/pkg/util/uuid"
3839
kuberecorder "k8s.io/client-go/tools/record"
3940
ctrl "sigs.k8s.io/controller-runtime"
4041
"sigs.k8s.io/controller-runtime/pkg/builder"
@@ -180,7 +181,13 @@ func (r *HelmChartReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager, opts
180181

181182
func (r *HelmChartReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, retErr error) {
182183
start := time.Now()
183-
log := ctrl.LoggerFrom(ctx)
184+
log := ctrl.LoggerFrom(ctx).
185+
// Sets a reconcile ID to correlate logs from all suboperations.
186+
WithValues("reconcileID", uuid.NewUUID())
187+
188+
// logger will be associated to the new context that is
189+
// returned from ctrl.LoggerInto.
190+
ctx = ctrl.LoggerInto(ctx, log)
184191

185192
// Fetch the HelmChart
186193
obj := &sourcev1.HelmChart{}

controllers/helmrepository_controller.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
corev1 "k8s.io/api/core/v1"
3030
"k8s.io/apimachinery/pkg/runtime"
3131
"k8s.io/apimachinery/pkg/types"
32+
"k8s.io/apimachinery/pkg/util/uuid"
3233
kuberecorder "k8s.io/client-go/tools/record"
3334
ctrl "sigs.k8s.io/controller-runtime"
3435
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -142,7 +143,13 @@ func (r *HelmRepositoryReconciler) SetupWithManagerAndOptions(mgr ctrl.Manager,
142143

143144
func (r *HelmRepositoryReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, retErr error) {
144145
start := time.Now()
145-
log := ctrl.LoggerFrom(ctx)
146+
log := ctrl.LoggerFrom(ctx).
147+
// Sets a reconcile ID to correlate logs from all suboperations.
148+
WithValues("reconcileID", uuid.NewUUID())
149+
150+
// logger will be associated to the new context that is
151+
// returned from ctrl.LoggerInto.
152+
ctx = ctrl.LoggerInto(ctx, log)
146153

147154
// Fetch the HelmRepository
148155
obj := &sourcev1.HelmRepository{}

controllers/helmrepository_controller_oci.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/apimachinery/pkg/runtime"
3333
"k8s.io/apimachinery/pkg/types"
3434
kerrors "k8s.io/apimachinery/pkg/util/errors"
35+
"k8s.io/apimachinery/pkg/util/uuid"
3536
kuberecorder "k8s.io/client-go/tools/record"
3637
ctrl "sigs.k8s.io/controller-runtime"
3738
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -107,7 +108,13 @@ func (r *HelmRepositoryOCIReconciler) SetupWithManagerAndOptions(mgr ctrl.Manage
107108

108109
func (r *HelmRepositoryOCIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, retErr error) {
109110
start := time.Now()
110-
log := ctrl.LoggerFrom(ctx)
111+
log := ctrl.LoggerFrom(ctx).
112+
// Sets a reconcile ID to correlate logs from all suboperations.
113+
WithValues("reconcileID", uuid.NewUUID())
114+
115+
// logger will be associated to the new context that is
116+
// returned from ctrl.LoggerInto.
117+
ctx = ctrl.LoggerInto(ctx, log)
111118

112119
// Fetch the HelmRepository
113120
obj := &sourcev1.HelmRepository{}

0 commit comments

Comments
 (0)