From 06561946cc42d7fc590b6c48e31e98807a5649b3 Mon Sep 17 00:00:00 2001 From: r Date: Sun, 3 Sep 2023 01:38:32 +0300 Subject: [PATCH] switch to structured logging This automatically adds additional fields like reconcile_id etc.. from the controller context. before : 2023-05-18T01:53:14+03:00 INFO controllers.KeystoneAPI Reconciled Service init successfully after: 2023-10-04T16:06:31+03:00 INFO Controllers.CinderAPI Reconciled Service 'cinder-api' successfully {"controller": "cinderapi", "controllerGroup": "cinder.openstack.org", "controllerKind": "CinderAPI", "CinderAPI": {"name":"cinder-api","namespace":"openstack"}, "namespace": "openstack", "name": "cinder-api", "reconcileID": "09fed477-8ad5-4186-8b20-790f409de78a"} *by using per reconcile function respective logger objects, the intention is to lay the ground for parallel reconciliation in future and avoid race conditions as ctx objects are reconcile run specific. fix logging implementations update correct controller name use single controller name in top logger func set controler unique log func name fix log usage in scheduler add top level ctx use propogated ctx from main in controllers use struct method for same logger signiture in controllers use struct method for same logger signiture in controllers getlog->GetLogger sed log->Log --- controllers/cinder_controller.go | 71 ++++++++++++++--------- controllers/cinderapi_controller.go | 60 +++++++++++-------- controllers/cinderbackup_controller.go | 61 +++++++++++-------- controllers/cinderscheduler_controller.go | 61 +++++++++++-------- controllers/cindervolume_controller.go | 62 ++++++++++++-------- main.go | 16 ++--- 6 files changed, 195 insertions(+), 136 deletions(-) diff --git a/controllers/cinder_controller.go b/controllers/cinder_controller.go index 50130afbd..5f16f09e6 100644 --- a/controllers/cinder_controller.go +++ b/controllers/cinder_controller.go @@ -66,9 +66,9 @@ func (r *CinderReconciler) GetKClient() kubernetes.Interface { return r.Kclient } -// GetLogger - -func (r *CinderReconciler) GetLogger() logr.Logger { - return r.Log +// GetLogger returns a logger object with a logging prefix of "conrollers.name" and aditional controller context fields +func (r *CinderReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("Cinder") } // GetScheme - @@ -80,7 +80,6 @@ func (r *CinderReconciler) GetScheme() *runtime.Scheme { type CinderReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } @@ -116,7 +115,7 @@ type CinderReconciler struct { // Reconcile - func (r *CinderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { - _ = log.FromContext(ctx) + Log := r.GetLogger(ctx) // Fetch the Cinder instance instance := &cinderv1beta1.Cinder{} @@ -137,7 +136,7 @@ func (r *CinderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res r.Client, r.Kclient, r.Scheme, - r.Log, + Log, ) if err != nil { return ctrl.Result{}, err @@ -211,7 +210,7 @@ func (r *CinderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res } // SetupWithManager sets up the controller with the Manager. -func (r *CinderReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *CinderReconciler) SetupWithManager(mgr ctrl.Manager, ctx context.Context) error { // transportURLSecretFn - Watch for changes made to the secret associated with the RabbitMQ // TransportURL created and used by Cinder CRs. Watch functions return a list of namespace-scoped // CRs that then get fed to the reconciler. Hence, in this case, we need to know the name of the @@ -222,6 +221,9 @@ func (r *CinderReconciler) SetupWithManager(mgr ctrl.Manager) error { // matches the name of an existing Cinder CR. In that case changes to that secret would trigger // reconciliation for a Cinder CR that does not need it. // + + Log := r.GetLogger(ctx) + // TODO: We also need a watch func to monitor for changes to the secret referenced by Cinder.Spec.Secret transportURLSecretFn := func(o client.Object) []reconcile.Request { result := []reconcile.Request{} @@ -231,8 +233,8 @@ func (r *CinderReconciler) SetupWithManager(mgr ctrl.Manager) error { listOpts := []client.ListOption{ client.InNamespace(o.GetNamespace()), } - if err := r.Client.List(context.Background(), cinders, listOpts...); err != nil { - r.Log.Error(err, "Unable to retrieve Cinder CRs %v") + if err := r.Client.List(ctx, cinders, listOpts...); err != nil { + Log.Error(err, "Unable to retrieve Cinder CRs") return nil } @@ -245,7 +247,7 @@ func (r *CinderReconciler) SetupWithManager(mgr ctrl.Manager) error { Namespace: o.GetNamespace(), Name: cr.Name, } - r.Log.Info(fmt.Sprintf("TransportURL Secret %s belongs to TransportURL belonging to Cinder CR %s", o.GetName(), cr.Name)) + Log.Info(fmt.Sprintf("TransportURL Secret %s belongs to TransportURL belonging to Cinder CR %s", o.GetName(), cr.Name)) result = append(result, reconcile.Request{NamespacedName: name}) } } @@ -277,7 +279,8 @@ func (r *CinderReconciler) SetupWithManager(mgr ctrl.Manager) error { } func (r *CinderReconciler) reconcileDelete(ctx context.Context, instance *cinderv1beta1.Cinder, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' delete", instance.Name)) + Log := r.GetLogger(ctx) + Log.Info(fmt.Sprintf("Reconciling Service '%s' delete", instance.Name)) // remove db finalizer first db, err := mariadbv1.GetDatabaseByName(ctx, helper, instance.Name) @@ -296,7 +299,7 @@ func (r *CinderReconciler) reconcileDelete(ctx context.Context, instance *cinder // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' delete successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' delete successfully", instance.Name)) return ctrl.Result{}, nil } @@ -308,7 +311,8 @@ func (r *CinderReconciler) reconcileInit( serviceLabels map[string]string, serviceAnnotations map[string]string, ) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' init", instance.Name)) + Log := r.GetLogger(ctx) + Log.Info(fmt.Sprintf("Reconciling Service '%s' init", instance.Name)) // Service account, role, binding rbacRules := []rbacv1.PolicyRule{ @@ -424,7 +428,7 @@ func (r *CinderReconciler) reconcileInit( } if dbSyncjob.HasChanged() { instance.Status.Hash[cinderv1beta1.DbSyncHash] = dbSyncjob.GetHash() - r.Log.Info(fmt.Sprintf("Service '%s' - Job %s hash added - %s", instance.Name, jobDef.Name, instance.Status.Hash[cinderv1beta1.DbSyncHash])) + Log.Info(fmt.Sprintf("Service '%s' - Job %s hash added - %s", instance.Name, jobDef.Name, instance.Status.Hash[cinderv1beta1.DbSyncHash])) } instance.Status.Conditions.MarkTrue(condition.DBSyncReadyCondition, condition.DBSyncReadyMessage) @@ -433,12 +437,13 @@ func (r *CinderReconciler) reconcileInit( // run Cinder db sync - end - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' init successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' init successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderReconciler) reconcileNormal(ctx context.Context, instance *cinderv1beta1.Cinder, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s'", instance.Name)) + Log := r.GetLogger(ctx) + Log.Info(fmt.Sprintf("Reconciling Service '%s'", instance.Name)) serviceLabels := map[string]string{ common.AppSelector: cinder.ServiceName, @@ -463,13 +468,13 @@ func (r *CinderReconciler) reconcileNormal(ctx context.Context, instance *cinder } if op != controllerutil.OperationResultNone { - r.Log.Info(fmt.Sprintf("TransportURL %s successfully reconciled - operation: %s", transportURL.Name, string(op))) + Log.Info(fmt.Sprintf("TransportURL %s successfully reconciled - operation: %s", transportURL.Name, string(op))) } instance.Status.TransportURLSecret = transportURL.Status.SecretName if instance.Status.TransportURLSecret == "" { - r.Log.Info(fmt.Sprintf("Waiting for TransportURL %s secret to be created", transportURL.Name)) + Log.Info(fmt.Sprintf("Waiting for TransportURL %s secret to be created", transportURL.Name)) instance.Status.Conditions.Set(condition.FalseCondition( condition.RabbitMqTransportURLReadyCondition, condition.RequestedReason, @@ -617,7 +622,7 @@ func (r *CinderReconciler) reconcileNormal(ctx context.Context, instance *cinder return ctrl.Result{}, err } if op != controllerutil.OperationResultNone { - r.Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", instance.Name, string(op))) + Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", instance.Name, string(op))) } // Mirror CinderAPI status' APIEndpoints and ReadyCount to this parent CR @@ -643,7 +648,7 @@ func (r *CinderReconciler) reconcileNormal(ctx context.Context, instance *cinder return ctrl.Result{}, err } if op != controllerutil.OperationResultNone { - r.Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", instance.Name, string(op))) + Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", instance.Name, string(op))) } // Mirror CinderScheduler status' ReadyCount to this parent CR @@ -672,7 +677,7 @@ func (r *CinderReconciler) reconcileNormal(ctx context.Context, instance *cinder return ctrl.Result{}, err } if op != controllerutil.OperationResultNone { - r.Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", instance.Name, string(op))) + Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", instance.Name, string(op))) } // Mirror CinderBackup status' ReadyCount to this parent CR @@ -713,7 +718,7 @@ func (r *CinderReconciler) reconcileNormal(ctx context.Context, instance *cinder return ctrl.Result{}, err } if op != controllerutil.OperationResultNone { - r.Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", instance.Name, string(op))) + Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", instance.Name, string(op))) } // Mirror CinderVolume status' ReadyCount to this parent CR @@ -748,27 +753,29 @@ func (r *CinderReconciler) reconcileNormal(ctx context.Context, instance *cinder return ctrl.Result{}, err } - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderReconciler) reconcileUpdate(ctx context.Context, instance *cinderv1beta1.Cinder, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' update", instance.Name)) + Log := r.GetLogger(ctx) + Log.Info(fmt.Sprintf("Reconciling Service '%s' update", instance.Name)) // TODO: should have minor update tasks if required // - delete dbsync hash from status to rerun it? - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' update successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' update successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderReconciler) reconcileUpgrade(ctx context.Context, instance *cinderv1beta1.Cinder, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' upgrade", instance.Name)) + Log := r.GetLogger(ctx) + Log.Info(fmt.Sprintf("Reconciling Service '%s' upgrade", instance.Name)) // TODO: should have major version upgrade tasks // -delete dbsync hash from status to rerun it? - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' upgrade successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' upgrade successfully", instance.Name)) return ctrl.Result{}, nil } @@ -862,6 +869,9 @@ func (r *CinderReconciler) createHashOfInputHashes( instance *cinderv1beta1.Cinder, envVars map[string]env.Setter, ) (string, bool, error) { + + Log := r.GetLogger(ctx) + var hashMap map[string]string changed := false mergedMapVars := env.MergeEnvs([]corev1.EnvVar{}, envVars) @@ -871,7 +881,7 @@ func (r *CinderReconciler) createHashOfInputHashes( } if hashMap, changed = util.SetHash(instance.Status.Hash, common.InputHashName, hash); changed { instance.Status.Hash = hashMap - r.Log.Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash)) + Log.Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash)) } return hash, changed, nil } @@ -1072,13 +1082,16 @@ func (r *CinderReconciler) volumeDeploymentCreateOrUpdate(ctx context.Context, i // longer appears in the spec. These will be volumes named something like // "cinder-volume-X" where "X" is not in the CinderVolumes spec. func (r *CinderReconciler) volumeCleanupDeployments(ctx context.Context, instance *cinderv1beta1.Cinder) error { + + Log := r.GetLogger(ctx) + // Generate a list of volume CRs volumes := &cinderv1beta1.CinderVolumeList{} listOpts := []client.ListOption{ client.InNamespace(instance.Namespace), } if err := r.Client.List(ctx, volumes, listOpts...); err != nil { - r.Log.Error(err, "Unable to retrieve volume CRs %v") + Log.Error(err, "Unable to retrieve volume CRs %v") return nil } diff --git a/controllers/cinderapi_controller.go b/controllers/cinderapi_controller.go index 619200b20..dee2d0b82 100644 --- a/controllers/cinderapi_controller.go +++ b/controllers/cinderapi_controller.go @@ -62,11 +62,6 @@ func (r *CinderAPIReconciler) GetKClient() kubernetes.Interface { return r.Kclient } -// GetLogger - -func (r *CinderAPIReconciler) GetLogger() logr.Logger { - return r.Log -} - // GetScheme - func (r *CinderAPIReconciler) GetScheme() *runtime.Scheme { return r.Scheme @@ -76,7 +71,6 @@ func (r *CinderAPIReconciler) GetScheme() *runtime.Scheme { type CinderAPIReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } @@ -90,6 +84,11 @@ var ( } ) +// GetLogger returns a logger object with a logging prefix of "conrollers.name" and aditional controller context fields +func (r *CinderAPIReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("CinderAPI") +} + //+kubebuilder:rbac:groups=cinder.openstack.org,resources=cinderapis,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=cinder.openstack.org,resources=cinderapis/status,verbs=get;update;patch //+kubebuilder:rbac:groups=cinder.openstack.org,resources=cinderapis/finalizers,verbs=update @@ -104,7 +103,7 @@ var ( // Reconcile - func (r *CinderAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { - _ = log.FromContext(ctx) + Log := r.GetLogger(ctx) // Fetch the CinderAPI instance instance := &cinderv1beta1.CinderAPI{} @@ -125,7 +124,7 @@ func (r *CinderAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( r.Client, r.Kclient, r.Scheme, - r.Log, + Log, ) if err != nil { return ctrl.Result{}, err @@ -195,10 +194,11 @@ func (r *CinderAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( } // SetupWithManager sets up the controller with the Manager. -func (r *CinderAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *CinderAPIReconciler) SetupWithManager(mgr ctrl.Manager, ctx context.Context) error { // Watch for changes to secrets we don't own. Global secrets // (e.g. TransportURLSecret) are handled by the main cinder controller. secretFn := func(o client.Object) []reconcile.Request { + Log := r.GetLogger(ctx) var namespace string = o.GetNamespace() var secretName string = o.GetName() result := []reconcile.Request{} @@ -208,8 +208,8 @@ func (r *CinderAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { listOpts := []client.ListOption{ client.InNamespace(namespace), } - if err := r.Client.List(context.Background(), apis, listOpts...); err != nil { - r.Log.Error(err, "Unable to retrieve API CRs %v") + if err := r.Client.List(ctx, apis, listOpts...); err != nil { + Log.Error(err, "Unable to retrieve API CRs") return nil } @@ -225,7 +225,7 @@ func (r *CinderAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { Namespace: o.GetNamespace(), Name: cr.Name, } - r.Log.Info(fmt.Sprintf("Secret %s and CR %s marked with label: %s", o.GetName(), cr.Name, l)) + Log.Info(fmt.Sprintf("Secret %s and CR %s marked with label: %s", o.GetName(), cr.Name, l)) result = append(result, reconcile.Request{NamespacedName: name}) } @@ -240,7 +240,7 @@ func (r *CinderAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { Namespace: namespace, Name: cr.Name, } - r.Log.Info(fmt.Sprintf("Secret %s is used by Cinder CR %s", secretName, cr.Name)) + Log.Info(fmt.Sprintf("Secret %s is used by Cinder CR %s", secretName, cr.Name)) result = append(result, reconcile.Request{NamespacedName: name}) } } @@ -264,7 +264,9 @@ func (r *CinderAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { } func (r *CinderAPIReconciler) reconcileDelete(ctx context.Context, instance *cinderv1beta1.CinderAPI, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' delete", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s' delete", instance.Name)) // It's possible to get here before the endpoints have been set in the status, so check for this if instance.Status.APIEndpoints != nil { @@ -302,7 +304,7 @@ func (r *CinderAPIReconciler) reconcileDelete(ctx context.Context, instance *cin // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' delete successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' delete successfully", instance.Name)) return ctrl.Result{}, nil } @@ -313,7 +315,9 @@ func (r *CinderAPIReconciler) reconcileInit( helper *helper.Helper, serviceLabels map[string]string, ) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' init", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s' init", instance.Name)) // // expose the service (create service and return the created endpoint URLs) @@ -503,12 +507,14 @@ func (r *CinderAPIReconciler) reconcileInit( } } - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' init successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' init successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderAPIReconciler) reconcileNormal(ctx context.Context, instance *cinderv1beta1.CinderAPI, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s'", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s'", instance.Name)) configVars := make(map[string]env.Setter) @@ -722,27 +728,31 @@ func (r *CinderAPIReconciler) reconcileNormal(ctx context.Context, instance *cin } // create Deployment - end - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderAPIReconciler) reconcileUpdate(ctx context.Context, instance *cinderv1beta1.CinderAPI, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' update", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s' update", instance.Name)) // TODO: should have minor update tasks if required // - delete dbsync hash from status to rerun it? - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' update successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' update successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderAPIReconciler) reconcileUpgrade(ctx context.Context, instance *cinderv1beta1.CinderAPI, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' upgrade", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s' upgrade", instance.Name)) // TODO: should have major version upgrade tasks // -delete dbsync hash from status to rerun it? - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' upgrade successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' upgrade successfully", instance.Name)) return ctrl.Result{}, nil } @@ -856,6 +866,8 @@ func (r *CinderAPIReconciler) createHashOfInputHashes( instance *cinderv1beta1.CinderAPI, envVars map[string]env.Setter, ) (string, bool, error) { + Log := r.GetLogger(ctx) + var hashMap map[string]string changed := false mergedMapVars := env.MergeEnvs([]corev1.EnvVar{}, envVars) @@ -865,7 +877,7 @@ func (r *CinderAPIReconciler) createHashOfInputHashes( } if hashMap, changed = util.SetHash(instance.Status.Hash, common.InputHashName, hash); changed { instance.Status.Hash = hashMap - r.Log.Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash)) + Log.Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash)) } return hash, changed, nil } diff --git a/controllers/cinderbackup_controller.go b/controllers/cinderbackup_controller.go index 52e1d2752..2fabda976 100644 --- a/controllers/cinderbackup_controller.go +++ b/controllers/cinderbackup_controller.go @@ -59,11 +59,6 @@ func (r *CinderBackupReconciler) GetKClient() kubernetes.Interface { return r.Kclient } -// GetLogger - -func (r *CinderBackupReconciler) GetLogger() logr.Logger { - return r.Log -} - // GetScheme - func (r *CinderBackupReconciler) GetScheme() *runtime.Scheme { return r.Scheme @@ -73,10 +68,14 @@ func (r *CinderBackupReconciler) GetScheme() *runtime.Scheme { type CinderBackupReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } +// GetLogger returns a logger object with a logging prefix of "conrollers.name" and aditional controller context fields +func (r *CinderBackupReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("CinderBackup") +} + //+kubebuilder:rbac:groups=cinder.openstack.org,resources=cinderbackups,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=cinder.openstack.org,resources=cinderbackups/status,verbs=get;update;patch //+kubebuilder:rbac:groups=cinder.openstack.org,resources=cinderbackups/finalizers,verbs=update @@ -87,7 +86,7 @@ type CinderBackupReconciler struct { // Reconcile - func (r *CinderBackupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { - _ = log.FromContext(ctx) + Log := r.GetLogger(ctx) // Fetch the CinderBackup instance instance := &cinderv1beta1.CinderBackup{} @@ -108,7 +107,7 @@ func (r *CinderBackupReconciler) Reconcile(ctx context.Context, req ctrl.Request r.Client, r.Kclient, r.Scheme, - r.Log, + Log, ) if err != nil { return ctrl.Result{}, err @@ -168,7 +167,9 @@ func (r *CinderBackupReconciler) Reconcile(ctx context.Context, req ctrl.Request } // SetupWithManager sets up the controller with the Manager. -func (r *CinderBackupReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *CinderBackupReconciler) SetupWithManager(mgr ctrl.Manager, ctx context.Context) error { + Log := r.GetLogger(ctx) + // Watch for changes to secrets we don't own. Global secrets // (e.g. TransportURLSecret) are handled by the main cinder controller. secretFn := func(o client.Object) []reconcile.Request { @@ -181,8 +182,8 @@ func (r *CinderBackupReconciler) SetupWithManager(mgr ctrl.Manager) error { listOpts := []client.ListOption{ client.InNamespace(namespace), } - if err := r.Client.List(context.Background(), backups, listOpts...); err != nil { - r.Log.Error(err, "Unable to retrieve backups CRs %v") + if err := r.Client.List(ctx, backups, listOpts...); err != nil { + Log.Error(err, "Unable to retrieve backups CRs %v") return nil } @@ -198,7 +199,7 @@ func (r *CinderBackupReconciler) SetupWithManager(mgr ctrl.Manager) error { Namespace: o.GetNamespace(), Name: cr.Name, } - r.Log.Info(fmt.Sprintf("Secret %s and CR %s marked with label: %s", o.GetName(), cr.Name, l)) + Log.Info(fmt.Sprintf("Secret %s and CR %s marked with label: %s", o.GetName(), cr.Name, l)) result = append(result, reconcile.Request{NamespacedName: name}) } @@ -213,7 +214,7 @@ func (r *CinderBackupReconciler) SetupWithManager(mgr ctrl.Manager) error { Namespace: namespace, Name: cr.Name, } - r.Log.Info(fmt.Sprintf("Secret %s is used by Cinder CR %s", secretName, cr.Name)) + Log.Info(fmt.Sprintf("Secret %s is used by Cinder CR %s", secretName, cr.Name)) result = append(result, reconcile.Request{NamespacedName: name}) } } @@ -234,11 +235,13 @@ func (r *CinderBackupReconciler) SetupWithManager(mgr ctrl.Manager) error { } func (r *CinderBackupReconciler) reconcileDelete(ctx context.Context, instance *cinderv1beta1.CinderBackup, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' delete", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s' delete", instance.Name)) // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' delete successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' delete successfully", instance.Name)) return ctrl.Result{}, nil } @@ -248,14 +251,18 @@ func (r *CinderBackupReconciler) reconcileInit( instance *cinderv1beta1.CinderBackup, helper *helper.Helper, ) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' init", instance.Name)) + Log := r.GetLogger(ctx) - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' init successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciling Service '%s' init", instance.Name)) + + Log.Info(fmt.Sprintf("Reconciled Service '%s' init successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderBackupReconciler) reconcileNormal(ctx context.Context, instance *cinderv1beta1.CinderBackup, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s'", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s'", instance.Name)) // ConfigMap configVars := make(map[string]env.Setter) @@ -470,27 +477,31 @@ func (r *CinderBackupReconciler) reconcileNormal(ctx context.Context, instance * } // create StatefulSet - end - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderBackupReconciler) reconcileUpdate(ctx context.Context, instance *cinderv1beta1.CinderBackup, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' update", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s' update", instance.Name)) // TODO: should have minor update tasks if required // - delete dbsync hash from status to rerun it? - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' update successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' update successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderBackupReconciler) reconcileUpgrade(ctx context.Context, instance *cinderv1beta1.CinderBackup, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' upgrade", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s' upgrade", instance.Name)) // TODO: should have major version upgrade tasks // -delete dbsync hash from status to rerun it? - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' upgrade successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' upgrade successfully", instance.Name)) return ctrl.Result{}, nil } @@ -599,6 +610,8 @@ func (r *CinderBackupReconciler) createHashOfInputHashes( instance *cinderv1beta1.CinderBackup, envVars map[string]env.Setter, ) (string, bool, error) { + Log := r.GetLogger(ctx) + var hashMap map[string]string changed := false mergedMapVars := env.MergeEnvs([]corev1.EnvVar{}, envVars) @@ -608,7 +621,7 @@ func (r *CinderBackupReconciler) createHashOfInputHashes( } if hashMap, changed = util.SetHash(instance.Status.Hash, common.InputHashName, hash); changed { instance.Status.Hash = hashMap - r.Log.Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash)) + Log.Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash)) } return hash, changed, nil } diff --git a/controllers/cinderscheduler_controller.go b/controllers/cinderscheduler_controller.go index 556c7b615..c3722126f 100644 --- a/controllers/cinderscheduler_controller.go +++ b/controllers/cinderscheduler_controller.go @@ -59,11 +59,6 @@ func (r *CinderSchedulerReconciler) GetKClient() kubernetes.Interface { return r.Kclient } -// GetLogger - -func (r *CinderSchedulerReconciler) GetLogger() logr.Logger { - return r.Log -} - // GetScheme - func (r *CinderSchedulerReconciler) GetScheme() *runtime.Scheme { return r.Scheme @@ -73,10 +68,14 @@ func (r *CinderSchedulerReconciler) GetScheme() *runtime.Scheme { type CinderSchedulerReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } +// GetLogger returns a logger object with a logging prefix of "conrollers.name" and aditional controller context fields +func (r *CinderSchedulerReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("CinderScheduler") +} + //+kubebuilder:rbac:groups=cinder.openstack.org,resources=cinderschedulers,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=cinder.openstack.org,resources=cinderschedulers/status,verbs=get;update;patch //+kubebuilder:rbac:groups=cinder.openstack.org,resources=cinderschedulers/finalizers,verbs=update @@ -87,7 +86,7 @@ type CinderSchedulerReconciler struct { // Reconcile - func (r *CinderSchedulerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { - _ = log.FromContext(ctx) + Log := r.GetLogger(ctx) // Fetch the CinderScheduler instance instance := &cinderv1beta1.CinderScheduler{} @@ -108,7 +107,7 @@ func (r *CinderSchedulerReconciler) Reconcile(ctx context.Context, req ctrl.Requ r.Client, r.Kclient, r.Scheme, - r.Log, + Log, ) if err != nil { return ctrl.Result{}, err @@ -168,7 +167,9 @@ func (r *CinderSchedulerReconciler) Reconcile(ctx context.Context, req ctrl.Requ } // SetupWithManager sets up the controller with the Manager. -func (r *CinderSchedulerReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *CinderSchedulerReconciler) SetupWithManager(mgr ctrl.Manager, ctx context.Context) error { + Log := r.GetLogger(ctx) + // Watch for changes to secrets we don't own. Global secrets // (e.g. TransportURLSecret) are handled by the main cinder controller. secretFn := func(o client.Object) []reconcile.Request { @@ -181,8 +182,8 @@ func (r *CinderSchedulerReconciler) SetupWithManager(mgr ctrl.Manager) error { listOpts := []client.ListOption{ client.InNamespace(namespace), } - if err := r.Client.List(context.Background(), schedulers, listOpts...); err != nil { - r.Log.Error(err, "Unable to retrieve scheduler CRs %v") + if err := r.Client.List(ctx, schedulers, listOpts...); err != nil { + Log.Error(err, "Unable to retrieve scheduler CRs %v") return nil } @@ -198,7 +199,7 @@ func (r *CinderSchedulerReconciler) SetupWithManager(mgr ctrl.Manager) error { Namespace: o.GetNamespace(), Name: cr.Name, } - r.Log.Info(fmt.Sprintf("Secret %s and CR %s marked with label: %s", o.GetName(), cr.Name, l)) + Log.Info(fmt.Sprintf("Secret %s and CR %s marked with label: %s", o.GetName(), cr.Name, l)) result = append(result, reconcile.Request{NamespacedName: name}) } @@ -213,7 +214,7 @@ func (r *CinderSchedulerReconciler) SetupWithManager(mgr ctrl.Manager) error { Namespace: namespace, Name: cr.Name, } - r.Log.Info(fmt.Sprintf("Secret %s is used by Cinder CR %s", secretName, cr.Name)) + Log.Info(fmt.Sprintf("Secret %s is used by Cinder CR %s", secretName, cr.Name)) result = append(result, reconcile.Request{NamespacedName: name}) } } @@ -234,11 +235,13 @@ func (r *CinderSchedulerReconciler) SetupWithManager(mgr ctrl.Manager) error { } func (r *CinderSchedulerReconciler) reconcileDelete(ctx context.Context, instance *cinderv1beta1.CinderScheduler, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' delete", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s' delete", instance.Name)) // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' delete successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' delete successfully", instance.Name)) return ctrl.Result{}, nil } @@ -248,14 +251,18 @@ func (r *CinderSchedulerReconciler) reconcileInit( instance *cinderv1beta1.CinderScheduler, helper *helper.Helper, ) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' init", instance.Name)) + Log := r.GetLogger(ctx) - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' init successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciling Service '%s' init", instance.Name)) + + Log.Info(fmt.Sprintf("Reconciled Service '%s' init successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderSchedulerReconciler) reconcileNormal(ctx context.Context, instance *cinderv1beta1.CinderScheduler, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s'", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s'", instance.Name)) configVars := make(map[string]env.Setter) @@ -469,27 +476,31 @@ func (r *CinderSchedulerReconciler) reconcileNormal(ctx context.Context, instanc } // create StatefulSet - end - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderSchedulerReconciler) reconcileUpdate(ctx context.Context, instance *cinderv1beta1.CinderScheduler, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' update", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s' update", instance.Name)) // TODO: should have minor update tasks if required // - delete dbsync hash from status to rerun it? - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' update successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' update successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderSchedulerReconciler) reconcileUpgrade(ctx context.Context, instance *cinderv1beta1.CinderScheduler, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' upgrade", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s' upgrade", instance.Name)) // TODO: should have major version upgrade tasks // -delete dbsync hash from status to rerun it? - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' upgrade successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' upgrade successfully", instance.Name)) return ctrl.Result{}, nil } @@ -598,6 +609,8 @@ func (r *CinderSchedulerReconciler) createHashOfInputHashes( instance *cinderv1beta1.CinderScheduler, envVars map[string]env.Setter, ) (string, bool, error) { + Log := r.GetLogger(ctx) + var hashMap map[string]string changed := false mergedMapVars := env.MergeEnvs([]corev1.EnvVar{}, envVars) @@ -607,7 +620,7 @@ func (r *CinderSchedulerReconciler) createHashOfInputHashes( } if hashMap, changed = util.SetHash(instance.Status.Hash, common.InputHashName, hash); changed { instance.Status.Hash = hashMap - r.Log.Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash)) + Log.Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash)) } return hash, changed, nil } diff --git a/controllers/cindervolume_controller.go b/controllers/cindervolume_controller.go index b7d49a081..56bda2c48 100644 --- a/controllers/cindervolume_controller.go +++ b/controllers/cindervolume_controller.go @@ -60,11 +60,6 @@ func (r *CinderVolumeReconciler) GetKClient() kubernetes.Interface { return r.Kclient } -// GetLogger - -func (r *CinderVolumeReconciler) GetLogger() logr.Logger { - return r.Log -} - // GetScheme - func (r *CinderVolumeReconciler) GetScheme() *runtime.Scheme { return r.Scheme @@ -74,10 +69,14 @@ func (r *CinderVolumeReconciler) GetScheme() *runtime.Scheme { type CinderVolumeReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } +// GetLogger returns a logger object with a logging prefix of "conrollers.name" and aditional controller context fields +func (r *CinderVolumeReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("CinderVolume") +} + //+kubebuilder:rbac:groups=cinder.openstack.org,resources=cindervolumes,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=cinder.openstack.org,resources=cindervolumes/status,verbs=get;update;patch //+kubebuilder:rbac:groups=cinder.openstack.org,resources=cindervolumes/finalizers,verbs=update @@ -89,8 +88,7 @@ type CinderVolumeReconciler struct { // Reconcile - func (r *CinderVolumeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { - _ = log.FromContext(ctx) - + Log := r.GetLogger(ctx) // Fetch the CinderVolume instance instance := &cinderv1beta1.CinderVolume{} err := r.Client.Get(ctx, req.NamespacedName, instance) @@ -110,7 +108,7 @@ func (r *CinderVolumeReconciler) Reconcile(ctx context.Context, req ctrl.Request r.Client, r.Kclient, r.Scheme, - r.Log, + Log, ) if err != nil { return ctrl.Result{}, err @@ -170,7 +168,9 @@ func (r *CinderVolumeReconciler) Reconcile(ctx context.Context, req ctrl.Request } // SetupWithManager sets up the controller with the Manager. -func (r *CinderVolumeReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *CinderVolumeReconciler) SetupWithManager(mgr ctrl.Manager, ctx context.Context) error { + Log := r.GetLogger(ctx) + // Watch for changes to secrets we don't own. Global secrets // (e.g. TransportURLSecret) are handled by the main cinder controller. secretFn := func(o client.Object) []reconcile.Request { @@ -183,8 +183,8 @@ func (r *CinderVolumeReconciler) SetupWithManager(mgr ctrl.Manager) error { listOpts := []client.ListOption{ client.InNamespace(namespace), } - if err := r.Client.List(context.Background(), volumes, listOpts...); err != nil { - r.Log.Error(err, "Unable to retrieve volume CRs %v") + if err := r.Client.List(ctx, volumes, listOpts...); err != nil { + Log.Error(err, "Unable to retrieve volume CRs %v") return nil } @@ -200,7 +200,7 @@ func (r *CinderVolumeReconciler) SetupWithManager(mgr ctrl.Manager) error { Namespace: o.GetNamespace(), Name: cr.Name, } - r.Log.Info(fmt.Sprintf("Secret %s and CR %s marked with label: %s", o.GetName(), cr.Name, l)) + Log.Info(fmt.Sprintf("Secret %s and CR %s marked with label: %s", o.GetName(), cr.Name, l)) result = append(result, reconcile.Request{NamespacedName: name}) } @@ -215,7 +215,7 @@ func (r *CinderVolumeReconciler) SetupWithManager(mgr ctrl.Manager) error { Namespace: namespace, Name: cr.Name, } - r.Log.Info(fmt.Sprintf("Secret %s is used by Cinder CR %s", secretName, cr.Name)) + Log.Info(fmt.Sprintf("Secret %s is used by Cinder CR %s", secretName, cr.Name)) result = append(result, reconcile.Request{NamespacedName: name}) } } @@ -236,11 +236,13 @@ func (r *CinderVolumeReconciler) SetupWithManager(mgr ctrl.Manager) error { } func (r *CinderVolumeReconciler) reconcileDelete(ctx context.Context, instance *cinderv1beta1.CinderVolume, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' delete", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s' delete", instance.Name)) // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' delete successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' delete successfully", instance.Name)) return ctrl.Result{}, nil } @@ -250,14 +252,18 @@ func (r *CinderVolumeReconciler) reconcileInit( instance *cinderv1beta1.CinderVolume, helper *helper.Helper, ) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' init", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s' init", instance.Name)) - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' init successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' init successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderVolumeReconciler) reconcileNormal(ctx context.Context, instance *cinderv1beta1.CinderVolume, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s'", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s'", instance.Name)) configVars := make(map[string]env.Setter) @@ -472,27 +478,31 @@ func (r *CinderVolumeReconciler) reconcileNormal(ctx context.Context, instance * } // create StatefulSet - end - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderVolumeReconciler) reconcileUpdate(ctx context.Context, instance *cinderv1beta1.CinderVolume, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' update", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s' update", instance.Name)) // TODO: should have minor update tasks if required // - delete dbsync hash from status to rerun it? - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' update successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' update successfully", instance.Name)) return ctrl.Result{}, nil } func (r *CinderVolumeReconciler) reconcileUpgrade(ctx context.Context, instance *cinderv1beta1.CinderVolume, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info(fmt.Sprintf("Reconciling Service '%s' upgrade", instance.Name)) + Log := r.GetLogger(ctx) + + Log.Info(fmt.Sprintf("Reconciling Service '%s' upgrade", instance.Name)) // TODO: should have major version upgrade tasks // -delete dbsync hash from status to rerun it? - r.Log.Info(fmt.Sprintf("Reconciled Service '%s' upgrade successfully", instance.Name)) + Log.Info(fmt.Sprintf("Reconciled Service '%s' upgrade successfully", instance.Name)) return ctrl.Result{}, nil } @@ -619,6 +629,8 @@ func (r *CinderVolumeReconciler) createHashOfInputHashes( instance *cinderv1beta1.CinderVolume, envVars map[string]env.Setter, ) (string, bool, error) { + Log := r.GetLogger(ctx) + var hashMap map[string]string changed := false mergedMapVars := env.MergeEnvs([]corev1.EnvVar{}, envVars) @@ -628,7 +640,7 @@ func (r *CinderVolumeReconciler) createHashOfInputHashes( } if hashMap, changed = util.SetHash(instance.Status.Hash, common.InputHashName, hash); changed { instance.Status.Hash = hashMap - r.Log.Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash)) + Log.Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash)) } return hash, changed, nil } diff --git a/main.go b/main.go index 94a6a42da..581d1687f 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ limitations under the License. package main import ( + "context" "flag" "os" "strings" @@ -116,8 +117,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("Cinder"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(mgr, context.Background()); err != nil { setupLog.Error(err, "unable to create controller", "controller", "Cinder") os.Exit(1) } @@ -125,8 +125,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("CinderAPI"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(mgr, context.Background()); err != nil { setupLog.Error(err, "unable to create controller", "controller", "CinderAPI") os.Exit(1) } @@ -134,8 +133,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("CinderBackup"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(mgr, context.Background()); err != nil { setupLog.Error(err, "unable to create controller", "controller", "CinderBackup") os.Exit(1) } @@ -143,8 +141,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("CinderScheduler"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(mgr, context.Background()); err != nil { setupLog.Error(err, "unable to create controller", "controller", "CinderScheduler") os.Exit(1) } @@ -152,8 +149,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("CinderVolume"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(mgr, context.Background()); err != nil { setupLog.Error(err, "unable to create controller", "controller", "CinderVolume") os.Exit(1) }