diff --git a/controllers/cinder_controller.go b/controllers/cinder_controller.go index c907c9df..059a89cf 100644 --- a/controllers/cinder_controller.go +++ b/controllers/cinder_controller.go @@ -70,11 +70,6 @@ func (r *CinderReconciler) GetKClient() kubernetes.Interface { return r.Kclient } -// GetLogger - -func (r *CinderReconciler) GetLogger() logr.Logger { - return r.Log -} - // GetScheme - func (r *CinderReconciler) GetScheme() *runtime.Scheme { return r.Scheme @@ -84,10 +79,14 @@ func (r *CinderReconciler) GetScheme() *runtime.Scheme { type CinderReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } +// GetLogger returns a logger object with a logging prefix of "controller.name" and additional controller context fields +func (r *CinderReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("Cinder") +} + // +kubebuilder:rbac:groups=cinder.openstack.org,resources=cinders,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=cinder.openstack.org,resources=cinders/status,verbs=get;update;patch // +kubebuilder:rbac:groups=cinder.openstack.org,resources=cinders/finalizers,verbs=update @@ -122,7 +121,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{} @@ -143,7 +142,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 @@ -218,7 +217,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(ctx context.Context, mgr ctrl.Manager) 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 @@ -233,13 +232,15 @@ func (r *CinderReconciler) SetupWithManager(mgr ctrl.Manager) error { transportURLSecretFn := func(o client.Object) []reconcile.Request { result := []reconcile.Request{} + Log := r.GetLogger(ctx) + // get all Cinder CRs cinders := &cinderv1beta1.CinderList{} 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 %v") return nil } @@ -252,7 +253,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}) } } @@ -265,6 +266,8 @@ func (r *CinderReconciler) SetupWithManager(mgr ctrl.Manager) error { } memcachedFn := func(o client.Object) []reconcile.Request { + Log := r.GetLogger(ctx) + result := []reconcile.Request{} // get all Cinder CRs @@ -273,7 +276,7 @@ func (r *CinderReconciler) SetupWithManager(mgr ctrl.Manager) error { client.InNamespace(o.GetNamespace()), } if err := r.Client.List(context.Background(), cinders, listOpts...); err != nil { - r.Log.Error(err, "Unable to retrieve Cinder CRs %w") + Log.Error(err, "Unable to retrieve Cinder CRs %w") return nil } @@ -283,7 +286,7 @@ func (r *CinderReconciler) SetupWithManager(mgr ctrl.Manager) error { Namespace: o.GetNamespace(), Name: cr.Name, } - r.Log.Info(fmt.Sprintf("Memcached %s is used by Cinder CR %s", o.GetName(), cr.Name)) + Log.Info(fmt.Sprintf("Memcached %s is used by Cinder CR %s", o.GetName(), cr.Name)) result = append(result, reconcile.Request{NamespacedName: name}) } } @@ -316,7 +319,9 @@ 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) @@ -335,7 +340,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 } @@ -347,7 +352,9 @@ 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)) // // create service DB instance @@ -442,7 +449,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) @@ -451,12 +458,14 @@ 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)) // Service account, role, binding rbacRules := []rbacv1.PolicyRule{ @@ -502,13 +511,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, @@ -691,7 +700,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 @@ -717,7 +726,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 @@ -746,7 +755,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 @@ -787,7 +796,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 @@ -843,27 +852,31 @@ func (r *CinderReconciler) reconcileNormal(ctx context.Context, instance *cinder instance.Status.Conditions.MarkTrue(condition.CronJobReadyCondition, condition.CronJobReadyMessage) // create CronJob - 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 *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 } @@ -954,6 +967,8 @@ 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) @@ -963,7 +978,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 } @@ -1184,13 +1199,15 @@ 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 f158264b..cd429611 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,10 +71,14 @@ func (r *CinderAPIReconciler) GetScheme() *runtime.Scheme { type CinderAPIReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } +// GetLogger returns a logger object with a logging prefix of "controller.name" and additional controller context fields +func (r *CinderAPIReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("CinderAPI") +} + var ( keystoneServices = []map[string]string{ { @@ -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,7 +194,9 @@ 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(ctx context.Context, mgr ctrl.Manager) 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 { @@ -209,7 +210,7 @@ func (r *CinderAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { client.InNamespace(namespace), } if err := r.Client.List(context.Background(), apis, listOpts...); err != nil { - r.Log.Error(err, "Unable to retrieve API CRs %v") + Log.Error(err, "Unable to retrieve API CRs %v") return nil } @@ -225,7 +226,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 +241,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 +265,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 +305,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 +316,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 +508,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 +729,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 } @@ -849,6 +860,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) @@ -858,7 +871,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 f7fc95e8..daabd42a 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 "controller.name" and additional 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,10 +167,12 @@ 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(ctx context.Context, mgr ctrl.Manager) 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{} @@ -182,7 +183,7 @@ func (r *CinderBackupReconciler) SetupWithManager(mgr ctrl.Manager) error { client.InNamespace(namespace), } if err := r.Client.List(context.Background(), backups, listOpts...); err != nil { - r.Log.Error(err, "Unable to retrieve backups CRs %v") + 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 } @@ -592,6 +603,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) @@ -601,7 +614,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 40f256a1..da69535b 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 "controller.name" and additional 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(ctx context.Context, mgr ctrl.Manager) 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 { @@ -182,7 +183,7 @@ func (r *CinderSchedulerReconciler) SetupWithManager(mgr ctrl.Manager) error { client.InNamespace(namespace), } if err := r.Client.List(context.Background(), schedulers, listOpts...); err != nil { - r.Log.Error(err, "Unable to retrieve scheduler CRs %v") + 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) + + 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 *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 } @@ -591,6 +602,7 @@ 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) @@ -600,7 +612,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 c5553d76..eb401e82 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 "controller.name" and additional 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,7 +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{} @@ -110,7 +109,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,9 +169,11 @@ 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(ctx context.Context, mgr ctrl.Manager) error { // Watch for changes to secrets we don't own. Global secrets // (e.g. TransportURLSecret) are handled by the main cinder controller. + Log := r.GetLogger(ctx) + secretFn := func(o client.Object) []reconcile.Request { var namespace string = o.GetNamespace() var secretName string = o.GetName() @@ -184,7 +185,7 @@ func (r *CinderVolumeReconciler) SetupWithManager(mgr ctrl.Manager) error { client.InNamespace(namespace), } if err := r.Client.List(context.Background(), 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 } @@ -200,7 +201,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 +216,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 +237,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 +253,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) - 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 *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 +479,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 } @@ -614,6 +625,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) @@ -623,7 +636,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 03381090..0e6b87ce 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ limitations under the License. package main import ( + "context" "crypto/tls" "flag" "os" @@ -128,8 +129,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("Cinder"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(context.Background(), mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "Cinder") os.Exit(1) } @@ -137,8 +137,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("CinderAPI"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(context.Background(), mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "CinderAPI") os.Exit(1) } @@ -146,8 +145,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("CinderBackup"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(context.Background(), mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "CinderBackup") os.Exit(1) } @@ -155,8 +153,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("CinderScheduler"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(context.Background(), mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "CinderScheduler") os.Exit(1) } @@ -164,8 +161,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("CinderVolume"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(context.Background(), mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "CinderVolume") os.Exit(1) } diff --git a/test/functional/suite_test.go b/test/functional/suite_test.go index c9680a8e..e65f2c60 100644 --- a/test/functional/suite_test.go +++ b/test/functional/suite_test.go @@ -193,8 +193,7 @@ var _ = BeforeSuite(func() { Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("Cinder"), - }).SetupWithManager(k8sManager) + }).SetupWithManager(context.Background(), k8sManager) Expect(err).ToNot(HaveOccurred()) @@ -205,24 +204,21 @@ var _ = BeforeSuite(func() { Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("CinderAPI"), - }).SetupWithManager(k8sManager) + }).SetupWithManager(context.Background(), k8sManager) Expect(err).ToNot(HaveOccurred()) err = (&controllers.CinderSchedulerReconciler{ Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("CinderScheduler"), - }).SetupWithManager(k8sManager) + }).SetupWithManager(context.Background(), k8sManager) Expect(err).ToNot(HaveOccurred()) err = (&controllers.CinderVolumeReconciler{ Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("CinderVolume"), - }).SetupWithManager(k8sManager) + }).SetupWithManager(context.Background(), k8sManager) Expect(err).ToNot(HaveOccurred()) go func() {