From 6919c00d4fb074ab5235079e707206bc8669a370 Mon Sep 17 00:00:00 2001 From: r Date: Mon, 21 Aug 2023 01:08:24 +0300 Subject: [PATCH] switch to structured logging update logging implementation update loggingWq update logging update logging --- controllers/ironic_controller.go | 57 ++++++++------ controllers/ironicapi_controller.go | 52 ++++++++----- controllers/ironicconductor_controller.go | 63 +++++++++------- controllers/ironicinspector_controller.go | 78 ++++++++++++-------- controllers/ironicneutronagent_controller.go | 51 ++++++++----- main.go | 12 +-- tests/functional/suite_test.go | 11 +-- 7 files changed, 197 insertions(+), 127 deletions(-) diff --git a/controllers/ironic_controller.go b/controllers/ironic_controller.go index ca1ce05e..bc81fea3 100644 --- a/controllers/ironic_controller.go +++ b/controllers/ironic_controller.go @@ -52,16 +52,21 @@ import ( rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + "sigs.k8s.io/controller-runtime/pkg/log" ) // IronicReconciler reconciles a Ironic object type IronicReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } +// getlog returns a logger object with a prefix of "conroller.name" and aditional controller context fields +func (r *IronicReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("Ironic") +} + // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironics,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironics/status,verbs=get;update;patch // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironics/finalizers,verbs=update @@ -102,7 +107,7 @@ type IronicReconciler struct { // For more details, check Reconcile and its Result here: // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.12.1/pkg/reconcile func (r *IronicReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { - _ = r.Log.WithValues("ironic", req.NamespacedName) + Log := r.GetLogger(ctx) // Fetch the Ironic instance instance := &ironicv1.Ironic{} @@ -123,7 +128,7 @@ func (r *IronicReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res r.Client, r.Kclient, r.Scheme, - r.Log, + Log, ) if err != nil { return ctrl.Result{}, err @@ -217,7 +222,9 @@ func (r *IronicReconciler) SetupWithManager(mgr ctrl.Manager) error { } func (r *IronicReconciler) reconcileDelete(ctx context.Context, instance *ironicv1.Ironic, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Ironic delete") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Ironic delete") // remove db finalizer first db, err := mariadbv1.GetDatabaseByName(ctx, helper, instance.Name) @@ -233,13 +240,15 @@ func (r *IronicReconciler) reconcileDelete(ctx context.Context, instance *ironic // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - r.Log.Info("Reconciled Ironic delete successfully") + Log.Info("Reconciled Ironic delete successfully") return ctrl.Result{}, nil } func (r *IronicReconciler) reconcileNormal(ctx context.Context, instance *ironicv1.Ironic, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Service") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service") // Service account, role, binding rbacResult, err := common_rbac.ReconcileRbac(ctx, helper, instance, getCommonRbacRules()) @@ -279,13 +288,13 @@ func (r *IronicReconciler) reconcileNormal(ctx context.Context, instance *ironic } 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, @@ -443,7 +452,7 @@ func (r *IronicReconciler) reconcileNormal(ctx context.Context, instance *ironic return ctrl.Result{}, err } if op != controllerutil.OperationResultNone { - r.Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", ironicConductor.Name, string(op))) + Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", ironicConductor.Name, string(op))) } // Mirror IronicConductor status' ReadyCount to this parent CR condGrp := conductorSpec.ConductorGroup @@ -470,7 +479,7 @@ func (r *IronicReconciler) reconcileNormal(ctx context.Context, instance *ironic return ctrl.Result{}, err } if op != controllerutil.OperationResultNone { - r.Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", ironicAPI.Name, string(op))) + Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", ironicAPI.Name, string(op))) } // Mirror IronicAPI status' APIEndpoints and ReadyCount to this parent CR @@ -499,7 +508,7 @@ func (r *IronicReconciler) reconcileNormal(ctx context.Context, instance *ironic return ctrl.Result{}, err } if op != controllerutil.OperationResultNone { - r.Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", ironicInspector.Name, string(op))) + Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", ironicInspector.Name, string(op))) } // Mirror IronicInspector status APIEndpoints and ReadyCount to this parent CR @@ -543,7 +552,7 @@ func (r *IronicReconciler) reconcileNormal(ctx context.Context, instance *ironic return ctrl.Result{}, err } if op != controllerutil.OperationResultNone { - r.Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", ironicNeutronAgent.Name, string(op))) + Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", ironicNeutronAgent.Name, string(op))) } // Mirror IronicNeutronAgent status ReadyCount to this parent CR instance.Status.IronicNeutronAgentReadyCount = ironicNeutronAgent.Status.ReadyCount @@ -568,7 +577,7 @@ func (r *IronicReconciler) reconcileNormal(ctx context.Context, instance *ironic instance.Status.Conditions.MarkTrue(ironicv1.IronicNeutronAgentReadyCondition, "") } - r.Log.Info("Reconciled Ironic successfully") + Log.Info("Reconciled Ironic successfully") return ctrl.Result{}, nil } @@ -578,7 +587,9 @@ func (r *IronicReconciler) reconcileInit( helper *helper.Helper, serviceLabels map[string]string, ) (ctrl.Result, error) { - r.Log.Info("Reconciling Ironic init") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Ironic init") // // create service DB instance @@ -639,14 +650,14 @@ func (r *IronicReconciler) reconcileInit( // create service DB - end - r.Log.Info("Reconciled Ironic init successfully") + Log.Info("Reconciled Ironic init successfully") return ctrl.Result{}, nil } func (r *IronicReconciler) reconcileUpdate(ctx context.Context, instance *ironicv1.Ironic, helper *helper.Helper) (ctrl.Result, error) { - // r.Log.Info("Reconciling Ironic update") + // Log.Info("Reconciling Ironic update") - // r.Log.Info("Reconciled Ironic update successfully") + // Log.Info("Reconciled Ironic update successfully") return ctrl.Result{}, nil } @@ -656,7 +667,9 @@ func (r *IronicReconciler) reconcileUpgrade( helper *helper.Helper, serviceLabels map[string]string, ) (ctrl.Result, error) { - r.Log.Info("Reconciling Ironic upgrade") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Ironic upgrade") // // run ironic db sync @@ -693,13 +706,13 @@ func (r *IronicReconciler) reconcileUpgrade( } if dbSyncjob.HasChanged() { instance.Status.Hash[ironicv1.DbSyncHash] = dbSyncjob.GetHash() - r.Log.Info(fmt.Sprintf("Job %s hash added - %s", jobDef.Name, instance.Status.Hash[ironicv1.DbSyncHash])) + Log.Info(fmt.Sprintf("Job %s hash added - %s", jobDef.Name, instance.Status.Hash[ironicv1.DbSyncHash])) } instance.Status.Conditions.MarkTrue(condition.DBSyncReadyCondition, condition.DBSyncReadyMessage) // run ironic db sync - end - r.Log.Info("Reconciled Ironic upgrade successfully") + Log.Info("Reconciled Ironic upgrade successfully") return ctrl.Result{}, nil } @@ -874,6 +887,8 @@ func (r *IronicReconciler) createHashOfInputHashes( instance *ironicv1.Ironic, 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) @@ -883,7 +898,7 @@ func (r *IronicReconciler) 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/ironicapi_controller.go b/controllers/ironicapi_controller.go index 1531f358..bbb4ebf1 100644 --- a/controllers/ironicapi_controller.go +++ b/controllers/ironicapi_controller.go @@ -21,6 +21,7 @@ import ( "fmt" "time" + "github.com/go-logr/logr" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" @@ -35,7 +36,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - "github.com/go-logr/logr" ironicv1 "github.com/openstack-k8s-operators/ironic-operator/api/v1beta1" ironic "github.com/openstack-k8s-operators/ironic-operator/pkg/ironic" ironicapi "github.com/openstack-k8s-operators/ironic-operator/pkg/ironicapi" @@ -59,7 +59,6 @@ import ( type IronicAPIReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } @@ -73,6 +72,11 @@ var ( } ) +// getlog returns a logger object with a prefix of "conroller.name" and aditional controller context fields +func (r *IronicAPIReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("Ironic") +} + // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironicapis,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironicapis/status,verbs=get;update;patch // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironicapis/finalizers,verbs=update @@ -95,7 +99,7 @@ var ( // Reconcile - func (r *IronicAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { - _ = log.FromContext(ctx) + Log := r.GetLogger(ctx) // Fetch the IronicAPI instance instance := &ironicv1.IronicAPI{} @@ -116,7 +120,7 @@ func (r *IronicAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( r.Client, r.Kclient, r.Scheme, - r.Log, + Log, ) if err != nil { return ctrl.Result{}, err @@ -198,9 +202,11 @@ func (r *IronicAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( } // SetupWithManager sets up the controller with the Manager. -func (r *IronicAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *IronicAPIReconciler) SetupWithManager(mgr ctrl.Manager, ctx context.Context) error { // watch for configmap where the CM owner label AND the CR.Spec.ManagingCrName label matches configMapFn := func(o client.Object) []reconcile.Request { + Log := r.GetLogger(ctx) + result := []reconcile.Request{} // get all API CRs @@ -209,7 +215,7 @@ func (r *IronicAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { client.InNamespace(o.GetNamespace()), } 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 } @@ -224,7 +230,7 @@ func (r *IronicAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { Namespace: o.GetNamespace(), Name: cr.Name, } - r.Log.Info(fmt.Sprintf("ConfigMap object %s and CR %s marked with label: %s", o.GetName(), cr.Name, l)) + Log.Info(fmt.Sprintf("ConfigMap object %s and CR %s marked with label: %s", o.GetName(), cr.Name, l)) result = append(result, reconcile.Request{NamespacedName: name}) } } @@ -252,7 +258,9 @@ func (r *IronicAPIReconciler) SetupWithManager(mgr ctrl.Manager) error { } func (r *IronicAPIReconciler) reconcileDelete(ctx context.Context, instance *ironicv1.IronicAPI, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling API delete") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling API delete") for _, ksSvc := range keystoneServices { // Remove the finalizer from our KeystoneEndpoint CR @@ -290,7 +298,7 @@ func (r *IronicAPIReconciler) reconcileDelete(ctx context.Context, instance *iro // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - r.Log.Info("Reconciled API delete successfully") + Log.Info("Reconciled API delete successfully") return ctrl.Result{}, nil } @@ -301,7 +309,9 @@ func (r *IronicAPIReconciler) reconcileInit( helper *helper.Helper, serviceLabels map[string]string, ) (ctrl.Result, error) { - r.Log.Info("Reconciling API init") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling API init") // // expose the service (create service and return the created endpoint URLs) @@ -423,7 +433,7 @@ func (r *IronicAPIReconciler) reconcileInit( if !instance.Spec.Standalone { for _, ksSvc := range keystoneServices { - r.Log.Info("Reconciled API init successfully") + Log.Info("Reconciled API init successfully") ksSvcSpec := keystonev1.KeystoneServiceSpec{ ServiceType: ksSvc["type"], ServiceName: ksSvc["name"], @@ -481,12 +491,14 @@ func (r *IronicAPIReconciler) reconcileInit( } } - r.Log.Info("Reconciled API init successfully") + Log.Info("Reconciled API init successfully") return ctrl.Result{}, nil } func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *ironicv1.IronicAPI, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Service") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service") if ironicv1.GetOwningIronicName(instance) == "" { // Service account, role, binding @@ -721,21 +733,21 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro } // create Deployment - end - r.Log.Info("Reconciled API successfully") + Log.Info("Reconciled API successfully") return ctrl.Result{}, nil } func (r *IronicAPIReconciler) reconcileUpdate(ctx context.Context, instance *ironicv1.IronicAPI, helper *helper.Helper) (ctrl.Result, error) { - // r.Log.Info("Reconciling API update") + // Log.Info("Reconciling API update") - // r.Log.Info("Reconciled API update successfully") + // Log.Info("Reconciled API update successfully") return ctrl.Result{}, nil } func (r *IronicAPIReconciler) reconcileUpgrade(ctx context.Context, instance *ironicv1.IronicAPI, helper *helper.Helper) (ctrl.Result, error) { - // r.Log.Info("Reconciling API upgrade") + // Log.Info("Reconciling API upgrade") - // r.Log.Info("Reconciled API upgrade successfully") + // Log.Info("Reconciled API upgrade successfully") return ctrl.Result{}, nil } @@ -819,6 +831,8 @@ func (r *IronicAPIReconciler) createHashOfInputHashes( instance *ironicv1.IronicAPI, 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) @@ -828,7 +842,7 @@ func (r *IronicAPIReconciler) 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/ironicconductor_controller.go b/controllers/ironicconductor_controller.go index 64013ec7..708e4fa2 100644 --- a/controllers/ironicconductor_controller.go +++ b/controllers/ironicconductor_controller.go @@ -24,6 +24,7 @@ import ( k8s_types "k8s.io/apimachinery/pkg/types" + "github.com/go-logr/logr" routev1 "github.com/openshift/api/route/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -39,7 +40,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" - "github.com/go-logr/logr" ironicv1 "github.com/openstack-k8s-operators/ironic-operator/api/v1beta1" ironic "github.com/openstack-k8s-operators/ironic-operator/pkg/ironic" ironicconductor "github.com/openstack-k8s-operators/ironic-operator/pkg/ironicconductor" @@ -62,10 +62,14 @@ import ( type IronicConductorReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } +// getlogger returns a logger object with a prefix of "conroller.name" and aditional controller context fields +func (r *IronicConductorReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("IronicConductor") +} + // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironicconductors,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironicconductors/status,verbs=get;update;patch // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironicconductors/finalizers,verbs=update @@ -90,7 +94,7 @@ type IronicConductorReconciler struct { // Reconcile - func (r *IronicConductorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { - _ = log.FromContext(ctx) + Log := r.GetLogger(ctx) // Fetch the IronicConductor instance instance := &ironicv1.IronicConductor{} @@ -111,7 +115,7 @@ func (r *IronicConductorReconciler) Reconcile(ctx context.Context, req ctrl.Requ r.Client, r.Kclient, r.Scheme, - r.Log, + Log, ) if err != nil { return ctrl.Result{}, err @@ -199,18 +203,19 @@ func (r *IronicConductorReconciler) Reconcile(ctx context.Context, req ctrl.Requ } // SetupWithManager sets up the controller with the Manager. -func (r *IronicConductorReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *IronicConductorReconciler) SetupWithManager(mgr ctrl.Manager, ctx context.Context) error { // watch for configmap where the CM owner label AND the CR.Spec.ManagingCrName label matches configMapFn := func(o client.Object) []reconcile.Request { result := []reconcile.Request{} + Log := r.GetLogger(ctx) // get all API CRs apis := &ironicv1.IronicConductorList{} listOpts := []client.ListOption{ client.InNamespace(o.GetNamespace()), } - 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 %v") return nil } @@ -225,7 +230,7 @@ func (r *IronicConductorReconciler) SetupWithManager(mgr ctrl.Manager) error { Namespace: o.GetNamespace(), Name: cr.Name, } - r.Log.Info(fmt.Sprintf("ConfigMap object %s and CR %s marked with label: %s", o.GetName(), cr.Name, l)) + Log.Info(fmt.Sprintf("ConfigMap object %s and CR %s marked with label: %s", o.GetName(), cr.Name, l)) result = append(result, reconcile.Request{NamespacedName: name}) } } @@ -253,11 +258,13 @@ func (r *IronicConductorReconciler) SetupWithManager(mgr ctrl.Manager) error { } func (r *IronicConductorReconciler) reconcileDelete(ctx context.Context, instance *ironicv1.IronicConductor, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Conductor delete") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Conductor delete") // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - r.Log.Info("Reconciled Conductor delete successfully") + Log.Info("Reconciled Conductor delete successfully") return ctrl.Result{}, nil } @@ -268,7 +275,9 @@ func (r *IronicConductorReconciler) reconcileServices( helper *helper.Helper, serviceLabels map[string]string, ) (ctrl.Result, error) { - r.Log.Info("Reconciling Conductor Services") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Conductor Services") podList, err := ironicconductor.ConductorPods(ctx, instance, helper, serviceLabels) if err != nil { @@ -302,13 +311,13 @@ func (r *IronicConductorReconciler) reconcileServices( conductorService, ) if err != nil && k8s_errors.IsNotFound(err) { - r.Log.Info(fmt.Sprintf("Service port %s does not exist, creating it", conductorService.Name)) + Log.Info(fmt.Sprintf("Service port %s does not exist, creating it", conductorService.Name)) err = r.Create(ctx, conductorService) if err != nil { return ctrl.Result{}, err } } else { - r.Log.Info(fmt.Sprintf("Service port %s exists, updating it", conductorService.Name)) + Log.Info(fmt.Sprintf("Service port %s exists, updating it", conductorService.Name)) err = r.Update(ctx, conductorService) if err != nil { return ctrl.Result{}, err @@ -345,13 +354,13 @@ func (r *IronicConductorReconciler) reconcileServices( conductorRoute, ) if err != nil && k8s_errors.IsNotFound(err) { - r.Log.Info(fmt.Sprintf("Route %s does not exist, creating it", conductorRoute.Name)) + Log.Info(fmt.Sprintf("Route %s does not exist, creating it", conductorRoute.Name)) err = r.Create(ctx, conductorRoute) if err != nil { return ctrl.Result{}, err } } else { - r.Log.Info(fmt.Sprintf("Route %s exists, updating it", conductorRoute.Name)) + Log.Info(fmt.Sprintf("Route %s exists, updating it", conductorRoute.Name)) err = r.Update(ctx, conductorRoute) if err != nil { return ctrl.Result{}, err @@ -365,12 +374,14 @@ func (r *IronicConductorReconciler) reconcileServices( // TODO: rework this // - r.Log.Info("Reconciled Conductor Services successfully") + Log.Info("Reconciled Conductor Services successfully") return ctrl.Result{}, nil } func (r *IronicConductorReconciler) reconcileNormal(ctx context.Context, instance *ironicv1.IronicConductor, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Conductor") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Conductor") if ironicv1.GetOwningIronicName(instance) == "" { // Service account, role, binding @@ -615,21 +626,21 @@ func (r *IronicConductorReconciler) reconcileNormal(ctx context.Context, instanc instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage) } - r.Log.Info("Reconciled Conductor successfully") + Log.Info("Reconciled Conductor successfully") return ctrl.Result{}, nil } func (r *IronicConductorReconciler) reconcileUpdate(ctx context.Context, instance *ironicv1.IronicConductor, helper *helper.Helper) (ctrl.Result, error) { - // r.Log.Info("Reconciling Service update") + // Log.Info("Reconciling Service update") - // r.Log.Info("Reconciled Service update successfully") + // Log.Info("Reconciled Service update successfully") return ctrl.Result{}, nil } func (r *IronicConductorReconciler) reconcileUpgrade(ctx context.Context, instance *ironicv1.IronicConductor, helper *helper.Helper) (ctrl.Result, error) { - // r.Log.Info("Reconciling Service upgrade") + // Log.Info("Reconciling Service upgrade") - // r.Log.Info("Reconciled Service upgrade successfully") + // Log.Info("Reconciled Service upgrade successfully") return ctrl.Result{}, nil } @@ -645,7 +656,7 @@ func (r *IronicConductorReconciler) generateServiceConfigMaps( // create custom Configmap for ironic-conductor-specific config input // - %-config-data configmap holding custom config for the service's ironic.conf // - + Log := r.GetLogger(ctx) cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(ironic.ServiceName), map[string]string{}) // customData hold any customization for the service. @@ -678,7 +689,7 @@ func (r *IronicConductorReconciler) generateServiceConfigMaps( } dhcpRanges, err := ironic.PrefixOrNetmaskFromCIDR(instance.Spec.DHCPRanges) if err != nil { - r.Log.Error(err, "Failed to get Prefix or Netmask from IP network Prefix (CIDR)") + Log.Error(err, "Failed to get Prefix or Netmask from IP network Prefix (CIDR)") } templateParameters["DHCPRanges"] = dhcpRanges templateParameters["Standalone"] = instance.Spec.Standalone @@ -726,6 +737,8 @@ func (r *IronicConductorReconciler) createHashOfInputHashes( instance *ironicv1.IronicConductor, 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) @@ -735,7 +748,7 @@ func (r *IronicConductorReconciler) 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/ironicinspector_controller.go b/controllers/ironicinspector_controller.go index 69a2ec6f..ed581103 100644 --- a/controllers/ironicinspector_controller.go +++ b/controllers/ironicinspector_controller.go @@ -44,7 +44,6 @@ import ( k8s_types "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/source" @@ -60,6 +59,7 @@ import ( "k8s.io/client-go/kubernetes" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" @@ -70,7 +70,6 @@ import ( type IronicInspectorReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } @@ -84,6 +83,11 @@ var ( } ) +// getlog returns a logger object with a prefix of "conroller.name" and aditional controller context fields +func (r *IronicInspectorReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("IronicInspector") +} + // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironicinspectors,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironicinspectors/status,verbs=get;update;patch // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironicinspectors/finalizers,verbs=update @@ -113,7 +117,7 @@ func (r *IronicInspectorReconciler) Reconcile( ctx context.Context, req ctrl.Request, ) (result ctrl.Result, _err error) { - _ = log.FromContext(ctx) + Log := r.GetLogger(ctx) // Fetch the IronicInspector instance instance := &ironicv1.IronicInspector{} @@ -136,7 +140,7 @@ func (r *IronicInspectorReconciler) Reconcile( r.Client, r.Kclient, r.Scheme, - r.Log, + Log, ) if err != nil { return ctrl.Result{}, err @@ -254,10 +258,11 @@ func (r *IronicInspectorReconciler) Reconcile( // SetupWithManager sets up the controller with the Manager. func (r *IronicInspectorReconciler) SetupWithManager( - mgr ctrl.Manager, -) error { + mgr ctrl.Manager, ctx context.Context) error { // watch for configmap where the CM owner label AND the CR.Spec.ManagingCrName label matches configMapFn := func(o client.Object) []reconcile.Request { + Log := r.GetLogger(ctx) + result := []reconcile.Request{} // get all API CRs @@ -266,11 +271,11 @@ func (r *IronicInspectorReconciler) SetupWithManager( client.InNamespace(o.GetNamespace()), } if err := r.Client.List( - context.Background(), + ctx, 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 } @@ -288,7 +293,7 @@ func (r *IronicInspectorReconciler) SetupWithManager( Namespace: o.GetNamespace(), Name: cr.Name, } - r.Log.Info(fmt.Sprintf( + Log.Info(fmt.Sprintf( "ConfigMap object %s and CR %s marked with label: %s", o.GetName(), cr.Name, l)) result = append( @@ -322,6 +327,8 @@ func (r *IronicInspectorReconciler) reconcileTransportURL( instance *ironicv1.IronicInspector, helper *helper.Helper, ) (ctrl.Result, error) { + Log := r.GetLogger(ctx) + if instance.Spec.RPCTransport == "oslo" { // // Create RabbitMQ transport URL CR and get the actual URL from the @@ -347,7 +354,7 @@ func (r *IronicInspectorReconciler) reconcileTransportURL( } if op != controllerutil.OperationResultNone { - r.Log.Info(fmt.Sprintf( + Log.Info(fmt.Sprintf( "TransportURL %s successfully reconciled - operation: %s", transportURL.Name, string(op))) } @@ -355,7 +362,7 @@ func (r *IronicInspectorReconciler) reconcileTransportURL( instance.Status.TransportURLSecret = transportURL.Status.SecretName if instance.Status.TransportURLSecret == "" { - r.Log.Info(fmt.Sprintf( + Log.Info(fmt.Sprintf( "Waiting for TransportURL %s secret to be created", transportURL.Name)) instance.Status.Conditions.Set(condition.FalseCondition( @@ -560,7 +567,9 @@ func (r *IronicInspectorReconciler) reconcileNormal( instance *ironicv1.IronicInspector, helper *helper.Helper, ) (ctrl.Result, error) { - r.Log.Info("Reconciling Ironic Inspector") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Ironic Inspector") if ironicv1.GetOwningIronicName(instance) == "" { // Service account, role, binding @@ -676,7 +685,7 @@ func (r *IronicInspectorReconciler) reconcileNormal( return ctrlResult, nil } - r.Log.Info("Reconciled Ironic Inspector successfully") + Log.Info("Reconciled Ironic Inspector successfully") return ctrl.Result{}, nil } @@ -745,7 +754,9 @@ func (r *IronicInspectorReconciler) reconcileDelete( instance *ironicv1.IronicInspector, helper *helper.Helper, ) (ctrl.Result, error) { - r.Log.Info("Reconciling Ironic Inspector delete") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Ironic Inspector delete") ctrlResult, err := r.reconcileDeleteKeystoneServices(ctx, instance, helper) if err != nil { @@ -763,7 +774,7 @@ func (r *IronicInspectorReconciler) reconcileDelete( // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - r.Log.Info("Reconciled Ironic Inspector delete successfully") + Log.Info("Reconciled Ironic Inspector delete successfully") return ctrl.Result{}, nil } @@ -842,6 +853,7 @@ func (r *IronicInspectorReconciler) reconcileServiceDBsync( helper *helper.Helper, serviceLabels map[string]string, ) (ctrl.Result, error) { + Log := r.GetLogger(ctx) dbSyncHash := instance.Status.Hash[ironicv1.DbSyncHash] jobDef := ironicinspector.DbSyncJob(instance, serviceLabels) dbSyncjob := job.NewJob( @@ -874,7 +886,7 @@ func (r *IronicInspectorReconciler) reconcileServiceDBsync( } if dbSyncjob.HasChanged() { instance.Status.Hash[ironicv1.DbSyncHash] = dbSyncjob.GetHash() - r.Log.Info(fmt.Sprintf( + Log.Info(fmt.Sprintf( "Job %s hash added - %s", jobDef.Name, instance.Status.Hash[ironicv1.DbSyncHash])) @@ -1089,7 +1101,9 @@ func (r *IronicInspectorReconciler) reconcileInit( helper *helper.Helper, serviceLabels map[string]string, ) (ctrl.Result, error) { - r.Log.Info("Reconciling Ironic Inspector init") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Ironic Inspector init") ctrlResult, err := r.reconcileServiceDBinstance(ctx, instance, helper, serviceLabels) if err != nil { @@ -1119,7 +1133,7 @@ func (r *IronicInspectorReconciler) reconcileInit( return ctrlResult, nil } - r.Log.Info("Reconciled Ironic Inspector init successfully") + Log.Info("Reconciled Ironic Inspector init successfully") return ctrl.Result{}, nil } @@ -1128,7 +1142,9 @@ func (r *IronicInspectorReconciler) reconcileUpdate( instance *ironicv1.IronicInspector, helper *helper.Helper, ) (ctrl.Result, error) { - r.Log.Info("Reconciling Ironic Inspector Service update") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Ironic Inspector Service update") // TODO: should have minor update tasks if required // - delete dbsync hash from status to rerun it? @@ -1141,7 +1157,8 @@ func (r *IronicInspectorReconciler) reconcileUpgrade( instance *ironicv1.IronicInspector, helper *helper.Helper, ) (ctrl.Result, error) { - r.Log.Info("Reconciling Ironic Inspector Service upgrade") + Log := r.GetLogger(ctx) + Log.Info("Reconciling Ironic Inspector Service upgrade") // TODO: should have major version upgrade tasks // -delete dbsync hash from status to rerun it? @@ -1170,7 +1187,7 @@ func (r *IronicInspectorReconciler) generateServiceConfigMaps( instance, labels.GetGroupLabel(ironic.ServiceName), map[string]string{}) - + Log := r.GetLogger(ctx) // customData hold any customization for the service. // custom.conf is going to /etc/ironic-inspector/inspector.conf.d // all other files get placed into /etc/ironic-inspector to allow @@ -1215,7 +1232,7 @@ func (r *IronicInspectorReconciler) generateServiceConfigMaps( } dhcpRanges, err := ironic.PrefixOrNetmaskFromCIDR(instance.Spec.DHCPRanges) if err != nil { - r.Log.Error(err, "unable to get Prefix or Netmask from IP network Prefix (CIDR)") + Log.Error(err, "unable to get Prefix or Netmask from IP network Prefix (CIDR)") } templateParameters["DHCPRanges"] = dhcpRanges templateParameters["Standalone"] = instance.Spec.Standalone @@ -1257,6 +1274,7 @@ func (r *IronicInspectorReconciler) createHashOfInputHashes( instance *ironicv1.IronicInspector, 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) @@ -1266,7 +1284,7 @@ func (r *IronicInspectorReconciler) 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 } @@ -1277,7 +1295,9 @@ func (r *IronicInspectorReconciler) reconcileServices( helper *helper.Helper, serviceLabels map[string]string, ) (ctrl.Result, error) { - r.Log.Info("Reconciling Inspector Services") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Inspector Services") podList, err := ironicinspector.InspectorPods( ctx, instance, helper, serviceLabels) @@ -1309,13 +1329,13 @@ func (r *IronicInspectorReconciler) reconcileServices( inspectorService, ) if err != nil && k8s_errors.IsNotFound(err) { - r.Log.Info(fmt.Sprintf("Service port %s does not exist, creating it", inspectorService.Name)) + Log.Info(fmt.Sprintf("Service port %s does not exist, creating it", inspectorService.Name)) err = r.Create(ctx, inspectorService) if err != nil { return ctrl.Result{}, err } } else { - r.Log.Info(fmt.Sprintf("Service port %s exists, updating it", inspectorService.Name)) + Log.Info(fmt.Sprintf("Service port %s exists, updating it", inspectorService.Name)) err = r.Update(ctx, inspectorService) if err != nil { return ctrl.Result{}, err @@ -1345,13 +1365,13 @@ func (r *IronicInspectorReconciler) reconcileServices( inspectorRoute, ) if err != nil && k8s_errors.IsNotFound(err) { - r.Log.Info(fmt.Sprintf("Route %s does not exist, creating it", inspectorRoute.Name)) + Log.Info(fmt.Sprintf("Route %s does not exist, creating it", inspectorRoute.Name)) err = r.Create(ctx, inspectorRoute) if err != nil { return ctrl.Result{}, err } } else { - r.Log.Info(fmt.Sprintf("Route %s exists, updating it", inspectorRoute.Name)) + Log.Info(fmt.Sprintf("Route %s exists, updating it", inspectorRoute.Name)) err = r.Update(ctx, inspectorRoute) if err != nil { return ctrl.Result{}, err @@ -1365,6 +1385,6 @@ func (r *IronicInspectorReconciler) reconcileServices( // TODO: rework this // - r.Log.Info("Reconciled Inspector Services successfully") + Log.Info("Reconciled Inspector Services successfully") return ctrl.Result{}, nil } diff --git a/controllers/ironicneutronagent_controller.go b/controllers/ironicneutronagent_controller.go index 7719bacd..36e4cc9a 100644 --- a/controllers/ironicneutronagent_controller.go +++ b/controllers/ironicneutronagent_controller.go @@ -26,7 +26,6 @@ import ( rbacv1 "k8s.io/api/rbac/v1" k8s_errors "k8s.io/apimachinery/pkg/api/errors" - "github.com/go-logr/logr" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes" ctrl "sigs.k8s.io/controller-runtime" @@ -34,6 +33,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/log" + "github.com/go-logr/logr" rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1" ironicv1 "github.com/openstack-k8s-operators/ironic-operator/api/v1beta1" ironic "github.com/openstack-k8s-operators/ironic-operator/pkg/ironic" @@ -57,10 +57,14 @@ import ( type IronicNeutronAgentReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } +// getlogger returns a logger object with a prefix of "conroller.name" and aditional controller context fields +func (r *IronicNeutronAgentReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("IronicNeutronAgent") +} + // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironicneutronagents,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironicneutronagents/status,verbs=get;update;patch // +kubebuilder:rbac:groups=ironic.openstack.org,resources=ironicneutronagents/finalizers,verbs=update @@ -85,7 +89,7 @@ func (r *IronicNeutronAgentReconciler) Reconcile( ctx context.Context, req ctrl.Request, ) (result ctrl.Result, _err error) { - _ = log.FromContext(ctx) + Log := r.GetLogger(ctx) // Fetch the IronicNeutronAgent instance instance := &ironicv1.IronicNeutronAgent{} @@ -106,7 +110,7 @@ func (r *IronicNeutronAgentReconciler) Reconcile( r.Client, r.Kclient, r.Scheme, - r.Log, + Log, ) if err != nil { return ctrl.Result{}, err @@ -218,6 +222,8 @@ func (r *IronicNeutronAgentReconciler) reconcileTransportURL( // Create RabbitMQ transport URL CR and get the actual URL from the // associted secret that is created // + Log := r.GetLogger(ctx) + transportURL, op, err := ironic.TransportURLCreateOrUpdate( instance.Name, instance.Namespace, @@ -236,13 +242,13 @@ func (r *IronicNeutronAgentReconciler) reconcileTransportURL( return ctrl.Result{}, err } if op != controllerutil.OperationResultNone { - r.Log.Info(fmt.Sprintf( + 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( + Log.Info(fmt.Sprintf( "Waiting for TransportURL %s secret to be created", transportURL.Name)) instance.Status.Conditions.Set(condition.FalseCondition( @@ -383,7 +389,8 @@ func (r *IronicNeutronAgentReconciler) reconcileNormal( instance *ironicv1.IronicNeutronAgent, helper *helper.Helper, ) (ctrl.Result, error) { - r.Log.Info("Reconciling IronicNeutronAgent") + Log := r.GetLogger(ctx) + Log.Info("Reconciling IronicNeutronAgent") if ironicv1.GetOwningIronicName(instance) == "" { // Service account, role, binding @@ -462,7 +469,7 @@ func (r *IronicNeutronAgentReconciler) reconcileNormal( return ctrlResult, nil } - r.Log.Info("Reconciled IronicNeutronAgent Service successfully") + Log.Info("Reconciled IronicNeutronAgent Service successfully") return ctrl.Result{}, nil } @@ -472,8 +479,10 @@ func (r *IronicNeutronAgentReconciler) reconcileInit( helper *helper.Helper, serviceLabels map[string]string, ) (ctrl.Result, error) { - r.Log.Info("Reconciling IronicNeutronAgent init") - r.Log.Info("Reconciled IronicNeutronAgent init successfully") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling IronicNeutronAgent init") + Log.Info("Reconciled IronicNeutronAgent init successfully") return ctrl.Result{}, nil } @@ -483,10 +492,12 @@ func (r *IronicNeutronAgentReconciler) reconcileDelete( instance *ironicv1.IronicNeutronAgent, helper *helper.Helper, ) (ctrl.Result, error) { - r.Log.Info("Reconciling IronicNeutronAgent delete") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling IronicNeutronAgent delete") // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - r.Log.Info("Reconciled IronicNeutronAgent delete successfully") + Log.Info("Reconciled IronicNeutronAgent delete successfully") return ctrl.Result{}, nil } @@ -496,8 +507,10 @@ func (r *IronicNeutronAgentReconciler) reconcileUpdate( instance *ironicv1.IronicNeutronAgent, helper *helper.Helper, ) (ctrl.Result, error) { - r.Log.Info("Reconciling IronicNeutronAgent update") - r.Log.Info("Reconciled IronicNeutronAgent update successfully") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling IronicNeutronAgent update") + Log.Info("Reconciled IronicNeutronAgent update successfully") return ctrl.Result{}, nil } @@ -507,8 +520,10 @@ func (r *IronicNeutronAgentReconciler) reconcileUpgrade( instance *ironicv1.IronicNeutronAgent, helper *helper.Helper, ) (ctrl.Result, error) { - r.Log.Info("Reconciling IronicNeutronAgent upgrade") - r.Log.Info("Reconciled IronicNeutronAgent upgrade successfully") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling IronicNeutronAgent upgrade") + Log.Info("Reconciled IronicNeutronAgent upgrade successfully") return ctrl.Result{}, nil } @@ -587,6 +602,8 @@ func (r *IronicNeutronAgentReconciler) createHashOfInputHashes( instance *ironicv1.IronicNeutronAgent, 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) @@ -596,7 +613,7 @@ func (r *IronicNeutronAgentReconciler) 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 7225f24a..60537802 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ limitations under the License. package main import ( + "context" "flag" "os" "strings" @@ -120,7 +121,6 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("Ironic"), }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "Ironic") os.Exit(1) @@ -129,8 +129,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("IronicConductor"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(mgr, context.Background()); err != nil { setupLog.Error(err, "unable to create controller", "controller", "IronicConductor") os.Exit(1) } @@ -138,8 +137,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("IronicAPI"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(mgr, context.Background()); err != nil { setupLog.Error(err, "unable to create controller", "controller", "IronicAPI") os.Exit(1) } @@ -147,8 +145,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("IronicInspector"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(mgr, context.Background()); err != nil { setupLog.Error(err, "unable to create controller", "controller", "IronicInspector") os.Exit(1) } @@ -156,7 +153,6 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("IronicNeutronAgent"), }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "IronicNeutronAgent") os.Exit(1) diff --git a/tests/functional/suite_test.go b/tests/functional/suite_test.go index 8c6df677..31b56a2d 100644 --- a/tests/functional/suite_test.go +++ b/tests/functional/suite_test.go @@ -175,7 +175,6 @@ var _ = BeforeSuite(func() { Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("IronicNeutronAgent"), }).SetupWithManager(k8sManager) Expect(err).ToNot(HaveOccurred()) @@ -183,31 +182,27 @@ var _ = BeforeSuite(func() { Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("IronicInspector"), - }).SetupWithManager(k8sManager) + }).SetupWithManager(k8sManager, context.Background()) Expect(err).ToNot(HaveOccurred()) err = (&controllers.IronicConductorReconciler{ Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("IronicConductor"), - }).SetupWithManager(k8sManager) + }).SetupWithManager(k8sManager, context.Background()) Expect(err).ToNot(HaveOccurred()) err = (&controllers.IronicAPIReconciler{ Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("IronicAPI"), - }).SetupWithManager(k8sManager) + }).SetupWithManager(k8sManager, context.Background()) Expect(err).ToNot(HaveOccurred()) err = (&controllers.IronicReconciler{ Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("Ironic"), }).SetupWithManager(k8sManager) Expect(err).ToNot(HaveOccurred())