@@ -65,9 +65,9 @@ func (r *ManilaReconciler) GetKClient() kubernetes.Interface {
65
65
return r .Kclient
66
66
}
67
67
68
- // GetLogger -
69
- func (r * ManilaReconciler ) GetLogger () logr.Logger {
70
- return r . Log
68
+ // GetLogger returns a logger object with a prefix of "conroller.name" and aditional controller context fields
69
+ func (r * ManilaReconciler ) GetLogger (ctx context. Context ) logr.Logger {
70
+ return log . FromContext ( ctx ). WithName ( "Controllers" ). WithName ( "Manila" )
71
71
}
72
72
73
73
// GetScheme -
@@ -79,7 +79,6 @@ func (r *ManilaReconciler) GetScheme() *runtime.Scheme {
79
79
type ManilaReconciler struct {
80
80
client.Client
81
81
Kclient kubernetes.Interface
82
- Log logr.Logger
83
82
Scheme * runtime.Scheme
84
83
}
85
84
@@ -114,7 +113,7 @@ type ManilaReconciler struct {
114
113
115
114
// Reconcile -
116
115
func (r * ManilaReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (result ctrl.Result , _err error ) {
117
- _ = log . FromContext (ctx )
116
+ Log := r . GetLogger (ctx )
118
117
119
118
instance := & manilav1beta1.Manila {}
120
119
err := r .Client .Get (ctx , req .NamespacedName , instance )
@@ -130,7 +129,7 @@ func (r *ManilaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
130
129
r .Client ,
131
130
r .Kclient ,
132
131
r .Scheme ,
133
- r . Log ,
132
+ Log ,
134
133
)
135
134
if err != nil {
136
135
return ctrl.Result {}, err
@@ -205,7 +204,9 @@ func (r *ManilaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
205
204
}
206
205
207
206
// SetupWithManager sets up the controller with the Manager.
208
- func (r * ManilaReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
207
+ func (r * ManilaReconciler ) SetupWithManager (ctx context.Context , mgr ctrl.Manager ) error {
208
+ Log := r .GetLogger (ctx )
209
+
209
210
// transportURLSecretFn - Watch for changes made to the secret associated with the RabbitMQ
210
211
// TransportURL created and used by Manila CRs. Watch functions return a list of namespace-scoped
211
212
// CRs that then get fed to the reconciler. Hence, in this case, we need to know the name of the
@@ -225,8 +226,8 @@ func (r *ManilaReconciler) SetupWithManager(mgr ctrl.Manager) error {
225
226
listOpts := []client.ListOption {
226
227
client .InNamespace (o .GetNamespace ()),
227
228
}
228
- if err := r .Client .List (context . Background () , manilas , listOpts ... ); err != nil {
229
- r . Log .Error (err , "Unable to retrieve Manila CRs %v" )
229
+ if err := r .Client .List (ctx , manilas , listOpts ... ); err != nil {
230
+ Log .Error (err , "Unable to retrieve Manila CRs %v" )
230
231
return nil
231
232
}
232
233
@@ -239,7 +240,7 @@ func (r *ManilaReconciler) SetupWithManager(mgr ctrl.Manager) error {
239
240
Namespace : o .GetNamespace (),
240
241
Name : cr .Name ,
241
242
}
242
- r . Log .Info (fmt .Sprintf ("TransportURL Secret %s belongs to TransportURL belonging to Manila CR %s" , o .GetName (), cr .Name ))
243
+ Log .Info (fmt .Sprintf ("TransportURL Secret %s belongs to TransportURL belonging to Manila CR %s" , o .GetName (), cr .Name ))
243
244
result = append (result , reconcile.Request {NamespacedName : name })
244
245
}
245
246
}
@@ -271,7 +272,9 @@ func (r *ManilaReconciler) SetupWithManager(mgr ctrl.Manager) error {
271
272
}
272
273
273
274
func (r * ManilaReconciler ) reconcileDelete (ctx context.Context , instance * manilav1beta1.Manila , helper * helper.Helper ) (ctrl.Result , error ) {
274
- r .Log .Info (fmt .Sprintf ("Reconciling Service '%s' delete" , instance .Name ))
275
+ Log := r .GetLogger (ctx )
276
+
277
+ Log .Info (fmt .Sprintf ("Reconciling Service '%s' delete" , instance .Name ))
275
278
276
279
// remove db finalizer first
277
280
db , err := mariadbv1 .GetDatabaseByName (ctx , helper , instance .Name )
@@ -287,7 +290,7 @@ func (r *ManilaReconciler) reconcileDelete(ctx context.Context, instance *manila
287
290
288
291
// Service is deleted so remove the finalizer.
289
292
controllerutil .RemoveFinalizer (instance , helper .GetFinalizer ())
290
- r . Log .Info (fmt .Sprintf ("Reconciled Service '%s' delete successfully" , instance .Name ))
293
+ Log .Info (fmt .Sprintf ("Reconciled Service '%s' delete successfully" , instance .Name ))
291
294
292
295
return ctrl.Result {}, nil
293
296
}
@@ -299,7 +302,9 @@ func (r *ManilaReconciler) reconcileInit(
299
302
serviceLabels map [string ]string ,
300
303
serviceAnnotations map [string ]string ,
301
304
) (ctrl.Result , error ) {
302
- r .Log .Info (fmt .Sprintf ("Reconciling Service '%s' init" , instance .Name ))
305
+ Log := r .GetLogger (ctx )
306
+
307
+ Log .Info (fmt .Sprintf ("Reconciling Service '%s' init" , instance .Name ))
303
308
304
309
//
305
310
// create service DB instance
@@ -396,18 +401,20 @@ func (r *ManilaReconciler) reconcileInit(
396
401
}
397
402
if dbSyncjob .HasChanged () {
398
403
instance .Status .Hash [manilav1beta1 .DbSyncHash ] = dbSyncjob .GetHash ()
399
- r . Log .Info (fmt .Sprintf ("Service '%s' - Job %s hash added - %s" , instance .Name , jobDef .Name , instance .Status .Hash [manilav1beta1 .DbSyncHash ]))
404
+ Log .Info (fmt .Sprintf ("Service '%s' - Job %s hash added - %s" , instance .Name , jobDef .Name , instance .Status .Hash [manilav1beta1 .DbSyncHash ]))
400
405
}
401
406
instance .Status .Conditions .MarkTrue (condition .DBSyncReadyCondition , condition .DBSyncReadyMessage )
402
407
403
408
// run Manila db sync - end
404
409
405
- r . Log .Info (fmt .Sprintf ("Reconciled Service '%s' init successfully" , instance .Name ))
410
+ Log .Info (fmt .Sprintf ("Reconciled Service '%s' init successfully" , instance .Name ))
406
411
return ctrl.Result {}, nil
407
412
}
408
413
409
414
func (r * ManilaReconciler ) reconcileNormal (ctx context.Context , instance * manilav1beta1.Manila , helper * helper.Helper ) (ctrl.Result , error ) {
410
- r .Log .Info (fmt .Sprintf ("Reconciling Service '%s'" , instance .Name ))
415
+ Log := r .GetLogger (ctx )
416
+
417
+ Log .Info (fmt .Sprintf ("Reconciling Service '%s'" , instance .Name ))
411
418
412
419
// Service account, role, binding
413
420
rbacRules := []rbacv1.PolicyRule {
@@ -450,13 +457,13 @@ func (r *ManilaReconciler) reconcileNormal(ctx context.Context, instance *manila
450
457
}
451
458
452
459
if op != controllerutil .OperationResultNone {
453
- r . Log .Info (fmt .Sprintf ("TransportURL %s successfully reconciled - operation: %s" , transportURL .Name , string (op )))
460
+ Log .Info (fmt .Sprintf ("TransportURL %s successfully reconciled - operation: %s" , transportURL .Name , string (op )))
454
461
}
455
462
456
463
instance .Status .TransportURLSecret = transportURL .Status .SecretName
457
464
458
465
if instance .Status .TransportURLSecret == "" {
459
- r . Log .Info (fmt .Sprintf ("Waiting for TransportURL %s secret to be created" , transportURL .Name ))
466
+ Log .Info (fmt .Sprintf ("Waiting for TransportURL %s secret to be created" , transportURL .Name ))
460
467
instance .Status .Conditions .Set (condition .FalseCondition (
461
468
condition .RabbitMqTransportURLReadyCondition ,
462
469
condition .RequestedReason ,
@@ -613,7 +620,7 @@ func (r *ManilaReconciler) reconcileNormal(ctx context.Context, instance *manila
613
620
return ctrl.Result {}, err
614
621
}
615
622
if op != controllerutil .OperationResultNone {
616
- r . Log .Info (fmt .Sprintf ("Deployment %s successfully reconciled - operation: %s" , instance .Name , string (op )))
623
+ Log .Info (fmt .Sprintf ("Deployment %s successfully reconciled - operation: %s" , instance .Name , string (op )))
617
624
}
618
625
619
626
// Mirror ManilaAPI status' ReadyCount to this parent CR
@@ -638,7 +645,7 @@ func (r *ManilaReconciler) reconcileNormal(ctx context.Context, instance *manila
638
645
return ctrl.Result {}, err
639
646
}
640
647
if op != controllerutil .OperationResultNone {
641
- r . Log .Info (fmt .Sprintf ("Deployment %s successfully reconciled - operation: %s" , instance .Name , string (op )))
648
+ Log .Info (fmt .Sprintf ("Deployment %s successfully reconciled - operation: %s" , instance .Name , string (op )))
642
649
}
643
650
644
651
// Mirror ManilaScheduler status' ReadyCount to this parent CR
@@ -665,7 +672,7 @@ func (r *ManilaReconciler) reconcileNormal(ctx context.Context, instance *manila
665
672
return ctrl.Result {}, err
666
673
}
667
674
if op != controllerutil .OperationResultNone {
668
- r . Log .Info (fmt .Sprintf ("Deployment %s successfully reconciled - operation: %s" , instance .Name , string (op )))
675
+ Log .Info (fmt .Sprintf ("Deployment %s successfully reconciled - operation: %s" , instance .Name , string (op )))
669
676
}
670
677
671
678
// Mirror ManilaShare status' ReadyCount to this parent CR
@@ -716,27 +723,31 @@ func (r *ManilaReconciler) reconcileNormal(ctx context.Context, instance *manila
716
723
instance .Status .Conditions .MarkTrue (condition .CronJobReadyCondition , condition .CronJobReadyMessage )
717
724
// create CronJob - end
718
725
719
- r . Log .Info (fmt .Sprintf ("Reconciled Service '%s' successfully" , instance .Name ))
726
+ Log .Info (fmt .Sprintf ("Reconciled Service '%s' successfully" , instance .Name ))
720
727
return ctrl.Result {}, nil
721
728
}
722
729
723
730
func (r * ManilaReconciler ) reconcileUpdate (ctx context.Context , instance * manilav1beta1.Manila , helper * helper.Helper ) (ctrl.Result , error ) {
724
- r .Log .Info (fmt .Sprintf ("Reconciling Service '%s' update" , instance .Name ))
731
+ Log := r .GetLogger (ctx )
732
+
733
+ Log .Info (fmt .Sprintf ("Reconciling Service '%s' update" , instance .Name ))
725
734
726
735
// TODO: should have minor update tasks if required
727
736
// - delete dbsync hash from status to rerun it?
728
737
729
- r . Log .Info (fmt .Sprintf ("Reconciled Service '%s' update successfully" , instance .Name ))
738
+ Log .Info (fmt .Sprintf ("Reconciled Service '%s' update successfully" , instance .Name ))
730
739
return ctrl.Result {}, nil
731
740
}
732
741
733
742
func (r * ManilaReconciler ) reconcileUpgrade (ctx context.Context , instance * manilav1beta1.Manila , helper * helper.Helper ) (ctrl.Result , error ) {
734
- r .Log .Info (fmt .Sprintf ("Reconciling Service '%s' upgrade" , instance .Name ))
743
+ Log := r .GetLogger (ctx )
744
+
745
+ Log .Info (fmt .Sprintf ("Reconciling Service '%s' upgrade" , instance .Name ))
735
746
736
747
// TODO: should have major version upgrade tasks
737
748
// -delete dbsync hash from status to rerun it?
738
749
739
- r . Log .Info (fmt .Sprintf ("Reconciled Service '%s' upgrade successfully" , instance .Name ))
750
+ Log .Info (fmt .Sprintf ("Reconciled Service '%s' upgrade successfully" , instance .Name ))
740
751
return ctrl.Result {}, nil
741
752
}
742
753
@@ -836,6 +847,8 @@ func (r *ManilaReconciler) createHashOfInputHashes(
836
847
instance * manilav1beta1.Manila ,
837
848
envVars map [string ]env.Setter ,
838
849
) (string , bool , error ) {
850
+ Log := r .GetLogger (ctx )
851
+
839
852
var hashMap map [string ]string
840
853
changed := false
841
854
mergedMapVars := env .MergeEnvs ([]corev1.EnvVar {}, envVars )
@@ -845,7 +858,7 @@ func (r *ManilaReconciler) createHashOfInputHashes(
845
858
}
846
859
if hashMap , changed = util .SetHash (instance .Status .Hash , common .InputHashName , hash ); changed {
847
860
instance .Status .Hash = hashMap
848
- r . Log .Info (fmt .Sprintf ("Input maps hash %s - %s" , common .InputHashName , hash ))
861
+ Log .Info (fmt .Sprintf ("Input maps hash %s - %s" , common .InputHashName , hash ))
849
862
}
850
863
return hash , changed , nil
851
864
}
0 commit comments