Skip to content

Commit d4a8f10

Browse files
authored
Merge pull request #10959 from Karthik-K-N/predicate-log
🌱 Log controller name in predicates
2 parents 83ca75d + 02410f2 commit d4a8f10

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
@@ -99,6 +99,7 @@ type scope struct {
9999
}
100100

101101
func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
102+
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "machinepool")
102103
clusterToMachinePools, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &expv1.MachinePoolList{}, mgr.GetScheme())
103104
if err != nil {
104105
return err
@@ -107,15 +108,15 @@ func (r *MachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
107108
c, err := ctrl.NewControllerManagedBy(mgr).
108109
For(&expv1.MachinePool{}).
109110
WithOptions(options).
110-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
111+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(predicateLog, r.WatchFilterValue)).
111112
Watches(
112113
&clusterv1.Cluster{},
113114
handler.EnqueueRequestsFromMapFunc(clusterToMachinePools),
114115
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
115116
builder.WithPredicates(
116-
predicates.All(ctrl.LoggerFrom(ctx),
117-
predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)),
118-
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue),
117+
predicates.All(predicateLog,
118+
predicates.ClusterUnpaused(predicateLog),
119+
predicates.ResourceHasFilterLabel(predicateLog, r.WatchFilterValue),
119120
),
120121
),
121122
).

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
@@ -80,14 +80,15 @@ type Reconciler struct {
8080
}
8181

8282
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
83+
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "cluster")
8384
c, err := ctrl.NewControllerManagedBy(mgr).
8485
For(&clusterv1.Cluster{}).
8586
Watches(
8687
&clusterv1.Machine{},
8788
handler.EnqueueRequestsFromMapFunc(r.controlPlaneMachineToCluster),
8889
).
8990
WithOptions(options).
90-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
91+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(predicateLog, r.WatchFilterValue)).
9192
Build(r)
9293

9394
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
@@ -98,6 +98,7 @@ type Reconciler struct {
9898
}
9999

100100
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error {
101+
predicateLog := ctrl.LoggerFrom(ctx).WithValues("controller", "machine")
101102
clusterToMachines, err := util.ClusterToTypedObjectsMapper(mgr.GetClient(), &clusterv1.MachineList{}, mgr.GetScheme())
102103
if err != nil {
103104
return err
@@ -118,18 +119,18 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt
118119
c, err := ctrl.NewControllerManagedBy(mgr).
119120
For(&clusterv1.Machine{}).
120121
WithOptions(options).
121-
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue)).
122+
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(predicateLog, r.WatchFilterValue)).
122123
Watches(
123124
&clusterv1.Cluster{},
124125
handler.EnqueueRequestsFromMapFunc(clusterToMachines),
125126
builder.WithPredicates(
126127
// TODO: should this wait for Cluster.Status.InfrastructureReady similar to Infra Machine resources?
127-
predicates.All(ctrl.LoggerFrom(ctx),
128-
predicates.Any(ctrl.LoggerFrom(ctx),
129-
predicates.ClusterUnpaused(ctrl.LoggerFrom(ctx)),
130-
predicates.ClusterControlPlaneInitialized(ctrl.LoggerFrom(ctx)),
128+
predicates.All(predicateLog,
129+
predicates.Any(predicateLog,
130+
predicates.ClusterUnpaused(predicateLog),
131+
predicates.ClusterControlPlaneInitialized(predicateLog),
131132
),
132-
predicates.ResourceHasFilterLabel(ctrl.LoggerFrom(ctx), r.WatchFilterValue),
133+
predicates.ResourceHasFilterLabel(predicateLog, r.WatchFilterValue),
133134
),
134135
)).
135136
Watches(

0 commit comments

Comments
 (0)