Skip to content

Commit 02410f2

Browse files
committed
Log controller name in predicates
1 parent 9c08773 commit 02410f2

File tree

21 files changed

+86
-65
lines changed

21 files changed

+86
-65
lines changed

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,14 @@ func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl
110110
r.TokenTTL = DefaultTokenTTL
111111
}
112112

113+
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "kubeadmconfig")
113114
b := ctrl.NewControllerManagedBy(mgr).
114115
For(&bootstrapv1.KubeadmConfig{}).
115116
WithOptions(options).
116117
Watches(
117118
&clusterv1.Machine{},
118119
handler.EnqueueRequestsFromMapFunc(r.MachineToBootstrapMapFunc),
119-
).WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue))
120+
).WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(predicateLog, r.WatchFilterValue))
120121

121122
if feature.Gates.Enabled(feature.MachinePool) {
122123
b = b.Watches(
@@ -129,9 +130,9 @@ func (r *KubeadmConfigReconciler) SetupWithManager(ctx context.Context, mgr ctrl
129130
&clusterv1.Cluster{},
130131
handler.EnqueueRequestsFromMapFunc(r.ClusterToKubeadmConfigs),
131132
builder.WithPredicates(
132-
predicates.All(ctrl.LoggerFrom(ctx),
133-
predicates.ClusterUnpausedAndInfrastructureReady(ctrl.LoggerFrom(ctx)),
134-
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue),
133+
predicates.All(predicateLog,
134+
predicates.ClusterUnpausedAndInfrastructureReady(predicateLog),
135+
predicates.ResourceHasFilterLabel(predicateLog, r.WatchFilterValue),
135136
),
136137
),
137138
)

controllers/remote/cluster_cache_reconciler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ type ClusterCacheReconciler struct {
4141
}
4242

4343
func (r *ClusterCacheReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
44+
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "remote/clustercache")
4445
err := ctrl.NewControllerManagedBy(mgr).
4546
Named("remote/clustercache").
4647
For(&clusterv1.Cluster{}).
4748
WithOptions(options).
48-
WithEventFilter(predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
49+
WithEventFilter(predicates.ResourceHasFilterLabel(predicateLog, r.WatchFilterValue)).
4950
Complete(r)
5051

5152
if err != nil {

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,19 @@ type KubeadmControlPlaneReconciler struct {
9393
}
9494

9595
func (r *KubeadmControlPlaneReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
96+
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "kubeadmcontrolplane")
9697
c, err := ctrl.NewControllerManagedBy(mgr).
9798
For(&controlplanev1.KubeadmControlPlane{}).
9899
Owns(&clusterv1.Machine{}).
99100
WithOptions(options).
100-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
101+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(predicateLog, r.WatchFilterValue)).
101102
Watches(
102103
&clusterv1.Cluster{},
103104
handler.EnqueueRequestsFromMapFunc(r.ClusterToKubeadmControlPlane),
104105
builder.WithPredicates(
105-
predicates.All(ctrl.LoggerFrom(ctx),
106-
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue),
107-
predicates.ClusterUnpausedAndInfrastructureReady(ctrl.LoggerFrom(ctx)),
106+
predicates.All(predicateLog,
107+
predicates.ResourceHasFilterLabel(predicateLog, r.WatchFilterValue),
108+
predicates.ClusterUnpausedAndInfrastructureReady(predicateLog),
108109
),
109110
),
110111
).Build(r)

exp/addons/internal/controllers/clusterresourceset_controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ type ClusterResourceSetReconciler struct {
6868
}
6969

7070
func (r *ClusterResourceSetReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options, partialSecretCache cache.Cache) error {
71+
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "clusterresourceset")
7172
err := ctrl.NewControllerManagedBy(mgr).
7273
For(&addonsv1.ClusterResourceSet{}).
7374
Watches(
@@ -80,7 +81,7 @@ func (r *ClusterResourceSetReconciler) SetupWithManager(ctx context.Context, mgr
8081
resourceToClusterResourceSetFunc[client.Object](r.Client),
8182
),
8283
builder.WithPredicates(
83-
resourcepredicates.TypedResourceCreateOrUpdate[client.Object](ctrl.LoggerFrom(ctx)),
84+
resourcepredicates.TypedResourceCreateOrUpdate[client.Object](predicateLog),
8485
),
8586
).
8687
WatchesRawSource(source.Kind(
@@ -94,10 +95,10 @@ func (r *ClusterResourceSetReconciler) SetupWithManager(ctx context.Context, mgr
9495
handler.TypedEnqueueRequestsFromMapFunc(
9596
resourceToClusterResourceSetFunc[*metav1.PartialObjectMetadata](r.Client),
9697
),
97-
resourcepredicates.TypedResourceCreateOrUpdate[*metav1.PartialObjectMetadata](ctrl.LoggerFrom(ctx)),
98+
resourcepredicates.TypedResourceCreateOrUpdate[*metav1.PartialObjectMetadata](predicateLog),
9899
)).
99100
WithOptions(options).
100-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
101+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(predicateLog, r.WatchFilterValue)).
101102
Complete(r)
102103
if err != nil {
103104
return errors.Wrap(err, "failed setting up with a controller manager")

exp/addons/internal/controllers/clusterresourcesetbinding_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,15 @@ type ClusterResourceSetBindingReconciler struct {
4848
}
4949

5050
func (r *ClusterResourceSetBindingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
51+
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "clusterresourcesetbinding")
5152
err := ctrl.NewControllerManagedBy(mgr).
5253
For(&addonsv1.ClusterResourceSetBinding{}).
5354
Watches(
5455
&clusterv1.Cluster{},
5556
handler.EnqueueRequestsFromMapFunc(r.clusterToClusterResourceSetBinding),
5657
).
5758
WithOptions(options).
58-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
59+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(predicateLog, r.WatchFilterValue)).
5960
Complete(r)
6061
if err != nil {
6162
return errors.Wrap(err, "failed setting up with a controller manager")

exp/internal/controllers/machinepool_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ type scope struct {
9696
}
9797

9898
func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
99+
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "machinepool")
99100
clusterToMachinePools, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &expv1.MachinePoolList{}, mgr.GetScheme())
100101
if err != nil {
101102
return err
@@ -104,15 +105,15 @@ func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
104105
c, err := ctrl.NewControllerManagedBy(mgr).
105106
For(&expv1.MachinePool{}).
106107
WithOptions(options).
107-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
108+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(predicateLog, r.WatchFilterValue)).
108109
Watches(
109110
&clusterv1.Cluster{},
110111
handler.EnqueueRequestsFromMapFunc(clusterToMachinePools),
111112
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
112113
builder.WithPredicates(
113-
predicates.All(ctrl.LoggerFrom(ctx),
114-
predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)),
115-
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue),
114+
predicates.All(predicateLog,
115+
predicates.ClusterUnpaused(predicateLog),
116+
predicates.ResourceHasFilterLabel(predicateLog, r.WatchFilterValue),
116117
),
117118
),
118119
).

exp/runtime/internal/controllers/extensionconfig_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type Reconciler struct {
6363
}
6464

6565
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options, partialSecretCache cache.Cache) error {
66+
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "extensionconfig")
6667
err := ctrl.NewControllerManagedBy(mgr).
6768
For(&runtimev1.ExtensionConfig{}).
6869
WatchesRawSource(source.Kind(
@@ -78,7 +79,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
7879
),
7980
)).
8081
WithOptions(options).
81-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
82+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(predicateLog, r.WatchFilterValue)).
8283
Complete(r)
8384
if err != nil {
8485
return errors.Wrap(err, "failed setting up with a controller manager")

internal/controllers/cluster/cluster_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,15 @@ type Reconciler struct {
7777
}
7878

7979
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
80+
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "cluster")
8081
c, err := ctrl.NewControllerManagedBy(mgr).
8182
For(&clusterv1.Cluster{}).
8283
Watches(
8384
&clusterv1.Machine{},
8485
handler.EnqueueRequestsFromMapFunc(r.controlPlaneMachineToCluster),
8586
).
8687
WithOptions(options).
87-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
88+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(predicateLog, r.WatchFilterValue)).
8889
Build(r)
8990

9091
if err != nil {

internal/controllers/clusterclass/clusterclass_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type Reconciler struct {
7070
}
7171

7272
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
73+
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "clusterclass")
7374
err := ctrl.NewControllerManagedBy(mgr).
7475
For(&clusterv1.ClusterClass{}).
7576
Named("clusterclass").
@@ -78,7 +79,7 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
7879
&runtimev1.ExtensionConfig{},
7980
handler.EnqueueRequestsFromMapFunc(r.extensionConfigToClusterClass),
8081
).
81-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
82+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(predicateLog, r.WatchFilterValue)).
8283
Complete(r)
8384

8485
if err != nil {

internal/controllers/machine/machine_controller.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ type Reconciler struct {
9494
}
9595

9696
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
97+
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "machine")
9798
clusterToMachines, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &clusterv1.MachineList{}, mgr.GetScheme())
9899
if err != nil {
99100
return err
@@ -114,18 +115,18 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
114115
c, err := ctrl.NewControllerManagedBy(mgr).
115116
For(&clusterv1.Machine{}).
116117
WithOptions(options).
117-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
118+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(predicateLog, r.WatchFilterValue)).
118119
Watches(
119120
&clusterv1.Cluster{},
120121
handler.EnqueueRequestsFromMapFunc(clusterToMachines),
121122
builder.WithPredicates(
122123
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
123-
predicates.All(ctrl.LoggerFrom(ctx),
124-
predicates.Any(ctrl.LoggerFrom(ctx),
125-
predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)),
126-
predicates.ClusterControlPlaneInitialized(ctrl.LoggerFrom(ctx)),
124+
predicates.All(predicateLog,
125+
predicates.Any(predicateLog,
126+
predicates.ClusterUnpaused(predicateLog),
127+
predicates.ClusterControlPlaneInitialized(predicateLog),
127128
),
128-
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue),
129+
predicates.ResourceHasFilterLabel(predicateLog, r.WatchFilterValue),
129130
),
130131
)).
131132
Watches(

0 commit comments

Comments
 (0)