@@ -53,6 +53,7 @@ import (
53
53
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/secretsmanager"
54
54
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/ssm"
55
55
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/userdata"
56
+ "sigs.k8s.io/cluster-api-provider-aws/v2/pkg/logger"
56
57
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
57
58
"sigs.k8s.io/cluster-api/controllers/noderefutil"
58
59
capierrors "sigs.k8s.io/cluster-api/errors"
@@ -140,7 +141,7 @@ func (r *AWSMachineReconciler) getObjectStoreService(scope scope.S3Scope) servic
140
141
// +kubebuilder:rbac:groups="",resources=events,verbs=get;list;watch;create;update;patch
141
142
142
143
func (r * AWSMachineReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (_ ctrl.Result , reterr error ) {
143
- log := ctrl . LoggerFrom (ctx )
144
+ log := logger . FromContext (ctx )
144
145
145
146
// Fetch the AWSMachine instance.
146
147
awsMachine := & infrav1.AWSMachine {}
@@ -226,7 +227,7 @@ func (r *AWSMachineReconciler) Reconcile(ctx context.Context, req ctrl.Request)
226
227
}
227
228
228
229
func (r * AWSMachineReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager , options controller.Options ) error {
229
- log := ctrl . LoggerFrom (ctx )
230
+ log := logger . FromContext (ctx )
230
231
AWSClusterToAWSMachines := r .AWSClusterToAWSMachines (log )
231
232
232
233
controller , err := ctrl .NewControllerManagedBy (mgr ).
@@ -240,7 +241,7 @@ func (r *AWSMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
240
241
& source.Kind {Type : & infrav1.AWSCluster {}},
241
242
handler .EnqueueRequestsFromMapFunc (AWSClusterToAWSMachines ),
242
243
).
243
- WithEventFilter (predicates .ResourceNotPausedAndHasFilterLabel (log , r .WatchFilterValue )).
244
+ WithEventFilter (predicates .ResourceNotPausedAndHasFilterLabel (log . GetLogger () , r .WatchFilterValue )).
244
245
WithEventFilter (
245
246
predicate.Funcs {
246
247
// Avoid reconciling if the event triggering the reconciliation is related to incremental status updates
@@ -280,7 +281,7 @@ func (r *AWSMachineReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
280
281
return controller .Watch (
281
282
& source.Kind {Type : & clusterv1.Cluster {}},
282
283
handler .EnqueueRequestsFromMapFunc (requeueAWSMachinesForUnpausedCluster ),
283
- predicates .ClusterUnpausedAndInfrastructureReady (log ),
284
+ predicates .ClusterUnpausedAndInfrastructureReady (log . GetLogger () ),
284
285
)
285
286
}
286
287
@@ -308,13 +309,13 @@ func (r *AWSMachineReconciler) reconcileDelete(machineScope *scope.MachineScope,
308
309
// and AWSMachine
309
310
// 3. Issue a delete
310
311
// 4. Scale controller deployment to 1
311
- machineScope .V ( 2 ). Info ("Unable to locate EC2 instance by ID or tags" )
312
+ machineScope .Debug ("Unable to locate EC2 instance by ID or tags" )
312
313
r .Recorder .Eventf (machineScope .AWSMachine , corev1 .EventTypeWarning , "NoInstanceFound" , "Unable to find matching EC2 instance" )
313
314
controllerutil .RemoveFinalizer (machineScope .AWSMachine , infrav1 .MachineFinalizer )
314
315
return ctrl.Result {}, nil
315
316
}
316
317
317
- machineScope .V ( 3 ). Info ("EC2 instance found matching deleted AWSMachine" , "instance-id" , instance .ID )
318
+ machineScope .Debug ("EC2 instance found matching deleted AWSMachine" , "instance-id" , instance .ID )
318
319
319
320
if err := r .reconcileLBAttachment (machineScope , elbScope , instance ); err != nil {
320
321
// We are tolerating AccessDenied error, so this won't block for users with older version of IAM;
@@ -367,7 +368,7 @@ func (r *AWSMachineReconciler) reconcileDelete(machineScope *scope.MachineScope,
367
368
return ctrl.Result {}, err
368
369
}
369
370
370
- machineScope .V ( 3 ). Info (
371
+ machineScope .Debug (
371
372
"Detaching security groups from provided network interface" ,
372
373
"groups" , core ,
373
374
"instanceID" , instance .ID ,
@@ -430,7 +431,7 @@ func (r *AWSMachineReconciler) findInstance(scope *scope.MachineScope, ec2svc se
430
431
}
431
432
432
433
func (r * AWSMachineReconciler ) reconcileNormal (_ context.Context , machineScope * scope.MachineScope , clusterScope cloud.ClusterScoper , ec2Scope scope.EC2Scope , elbScope scope.ELBScope , objectStoreScope scope.S3Scope ) (ctrl.Result , error ) {
433
- machineScope .V ( 4 ). Info ("Reconciling AWSMachine" )
434
+ machineScope .Trace ("Reconciling AWSMachine" )
434
435
435
436
// If the AWSMachine is in an error state, return early.
436
437
if machineScope .HasFailed () {
@@ -837,7 +838,7 @@ func (r *AWSMachineReconciler) reconcileLBAttachment(machineScope *scope.Machine
837
838
838
839
// AWSClusterToAWSMachines is a handler.ToRequestsFunc to be used to enqeue requests for reconciliation
839
840
// of AWSMachines.
840
- func (r * AWSMachineReconciler ) AWSClusterToAWSMachines (log logr. Logger ) handler.MapFunc {
841
+ func (r * AWSMachineReconciler ) AWSClusterToAWSMachines (log logger. Wrapper ) handler.MapFunc {
841
842
return func (o client.Object ) []ctrl.Request {
842
843
c , ok := o .(* infrav1.AWSCluster )
843
844
if ! ok {
@@ -848,14 +849,14 @@ func (r *AWSMachineReconciler) AWSClusterToAWSMachines(log logr.Logger) handler.
848
849
849
850
// Don't handle deleted AWSClusters
850
851
if ! c .ObjectMeta .DeletionTimestamp .IsZero () {
851
- log .V ( 4 ). Info ("AWSCluster has a deletion timestamp, skipping mapping." )
852
+ log .Trace ("AWSCluster has a deletion timestamp, skipping mapping." )
852
853
return nil
853
854
}
854
855
855
856
cluster , err := util .GetOwnerCluster (context .TODO (), r .Client , c .ObjectMeta )
856
857
switch {
857
858
case apierrors .IsNotFound (err ) || cluster == nil :
858
- log .V ( 4 ). Info ("Cluster for AWSCluster not found, skipping mapping." )
859
+ log .Trace ("Cluster for AWSCluster not found, skipping mapping." )
859
860
return nil
860
861
case err != nil :
861
862
log .Error (err , "Failed to get owning cluster, skipping mapping." )
@@ -866,7 +867,7 @@ func (r *AWSMachineReconciler) AWSClusterToAWSMachines(log logr.Logger) handler.
866
867
}
867
868
}
868
869
869
- func (r * AWSMachineReconciler ) requeueAWSMachinesForUnpausedCluster (log logr. Logger ) handler.MapFunc {
870
+ func (r * AWSMachineReconciler ) requeueAWSMachinesForUnpausedCluster (log logger. Wrapper ) handler.MapFunc {
870
871
return func (o client.Object ) []ctrl.Request {
871
872
c , ok := o .(* clusterv1.Cluster )
872
873
if ! ok {
@@ -877,15 +878,15 @@ func (r *AWSMachineReconciler) requeueAWSMachinesForUnpausedCluster(log logr.Log
877
878
878
879
// Don't handle deleted clusters
879
880
if ! c .ObjectMeta .DeletionTimestamp .IsZero () {
880
- log .V ( 4 ). Info ("Cluster has a deletion timestamp, skipping mapping." )
881
+ log .Trace ("Cluster has a deletion timestamp, skipping mapping." )
881
882
return nil
882
883
}
883
884
884
885
return r .requestsForCluster (log , c .Namespace , c .Name )
885
886
}
886
887
}
887
888
888
- func (r * AWSMachineReconciler ) requestsForCluster (log logr. Logger , namespace , name string ) []ctrl.Request {
889
+ func (r * AWSMachineReconciler ) requestsForCluster (log logger. Wrapper , namespace , name string ) []ctrl.Request {
889
890
labels := map [string ]string {clusterv1 .ClusterLabelName : name }
890
891
machineList := & clusterv1.MachineList {}
891
892
if err := r .Client .List (context .TODO (), machineList , client .InNamespace (namespace ), client .MatchingLabels (labels )); err != nil {
@@ -898,21 +899,21 @@ func (r *AWSMachineReconciler) requestsForCluster(log logr.Logger, namespace, na
898
899
m := m
899
900
log .WithValues ("machine" , klog .KObj (& m ))
900
901
if m .Spec .InfrastructureRef .GroupVersionKind ().Kind != "AWSMachine" {
901
- log .V ( 4 ). Info ("Machine has an InfrastructureRef for a different type, will not add to reconciliation request." )
902
+ log .Trace ("Machine has an InfrastructureRef for a different type, will not add to reconciliation request." )
902
903
continue
903
904
}
904
905
if m .Spec .InfrastructureRef .Name == "" {
905
- log .V ( 4 ). Info ("Machine has an InfrastructureRef with an empty name, will not add to reconciliation request." )
906
+ log .Trace ("Machine has an InfrastructureRef with an empty name, will not add to reconciliation request." )
906
907
continue
907
908
}
908
909
log .WithValues ("awsMachine" , klog .KRef (m .Spec .InfrastructureRef .Namespace , m .Spec .InfrastructureRef .Name ))
909
- log .V ( 4 ). Info ("Adding AWSMachine to reconciliation request." )
910
+ log .Trace ("Adding AWSMachine to reconciliation request." )
910
911
result = append (result , ctrl.Request {NamespacedName : client.ObjectKey {Namespace : m .Namespace , Name : m .Spec .InfrastructureRef .Name }})
911
912
}
912
913
return result
913
914
}
914
915
915
- func (r * AWSMachineReconciler ) getInfraCluster (ctx context.Context , log logr .Logger , cluster * clusterv1.Cluster , awsMachine * infrav1.AWSMachine ) (scope.EC2Scope , error ) {
916
+ func (r * AWSMachineReconciler ) getInfraCluster (ctx context.Context , log * logger .Logger , cluster * clusterv1.Cluster , awsMachine * infrav1.AWSMachine ) (scope.EC2Scope , error ) {
916
917
var clusterScope * scope.ClusterScope
917
918
var managedControlPlaneScope * scope.ManagedControlPlaneScope
918
919
var err error
@@ -931,7 +932,7 @@ func (r *AWSMachineReconciler) getInfraCluster(ctx context.Context, log logr.Log
931
932
932
933
managedControlPlaneScope , err = scope .NewManagedControlPlaneScope (scope.ManagedControlPlaneScopeParams {
933
934
Client : r .Client ,
934
- Logger : & log ,
935
+ Logger : log ,
935
936
Cluster : cluster ,
936
937
ControlPlane : controlPlane ,
937
938
ControllerName : "awsManagedControlPlane" ,
@@ -959,7 +960,7 @@ func (r *AWSMachineReconciler) getInfraCluster(ctx context.Context, log logr.Log
959
960
// Create the cluster scope
960
961
clusterScope , err = scope .NewClusterScope (scope.ClusterScopeParams {
961
962
Client : r .Client ,
962
- Logger : & log ,
963
+ Logger : log ,
963
964
Cluster : cluster ,
964
965
AWSCluster : awsCluster ,
965
966
ControllerName : "awsmachine" ,
0 commit comments