diff --git a/controllers/ovncontroller_controller.go b/controllers/ovncontroller_controller.go index 836556a6..d5b3004a 100644 --- a/controllers/ovncontroller_controller.go +++ b/controllers/ovncontroller_controller.go @@ -32,6 +32,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/source" "github.com/openstack-k8s-operators/lib-common/modules/common" @@ -53,11 +54,15 @@ import ( rbacv1 "k8s.io/api/rbac/v1" ) +// getlog returns a logger object with a prefix of "conroller.name" and aditional controller context fields +func (r *OVNControllerReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("OVNController") +} + // OVNControllerReconciler reconciles a OVNController object type OVNControllerReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } @@ -66,11 +71,6 @@ func (r *OVNControllerReconciler) GetClient() client.Client { return r.Client } -// GetLogger - -func (r *OVNControllerReconciler) GetLogger() logr.Logger { - return r.Log -} - //+kubebuilder:rbac:groups=ovn.openstack.org,resources=ovncontrollers,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=ovn.openstack.org,resources=ovncontrollers/status,verbs=get;update;patch //+kubebuilder:rbac:groups=ovn.openstack.org,resources=ovncontrollers/finalizers,verbs=update @@ -90,7 +90,8 @@ func (r *OVNControllerReconciler) GetLogger() logr.Logger { // +kubebuilder:rbac:groups="",resources=pods,verbs=create;delete;get;list;patch;update;watch func (r *OVNControllerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { - _ = r.Log.WithValues("ovncontroller", req.NamespacedName) + + Log := r.GetLogger(ctx) // Fetch OVNController instance instance := &v1beta1.OVNController{} @@ -111,7 +112,7 @@ func (r *OVNControllerReconciler) Reconcile(ctx context.Context, req ctrl.Reques r.Client, r.Kclient, r.Scheme, - r.Log, + Log, ) if err != nil { return ctrl.Result{}, err @@ -182,7 +183,7 @@ func (r *OVNControllerReconciler) Reconcile(ctx context.Context, req ctrl.Reques } // SetupWithManager sets up the controller with the Manager. -func (r *OVNControllerReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *OVNControllerReconciler) SetupWithManager(mgr ctrl.Manager, ctx context.Context) error { crs := &v1beta1.OVNControllerList{} return ctrl.NewControllerManagedBy(mgr). For(&v1beta1.OVNController{}). @@ -193,16 +194,18 @@ func (r *OVNControllerReconciler) SetupWithManager(mgr ctrl.Manager) error { Owns(&corev1.ServiceAccount{}). Owns(&rbacv1.Role{}). Owns(&rbacv1.RoleBinding{}). - Watches(&source.Kind{Type: &v1beta1.OVNDBCluster{}}, handler.EnqueueRequestsFromMapFunc(v1beta1.OVNDBClusterNamespaceMapFunc(crs, mgr.GetClient(), r.Log))). + Watches(&source.Kind{Type: &v1beta1.OVNDBCluster{}}, handler.EnqueueRequestsFromMapFunc(v1beta1.OVNDBClusterNamespaceMapFunc(crs, mgr.GetClient(), r.GetLogger(ctx)))). Complete(r) } func (r *OVNControllerReconciler) reconcileDelete(ctx context.Context, instance *v1beta1.OVNController, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Service delete") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service delete") // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - r.Log.Info("Reconciled Service delete successfully") + Log.Info("Reconciled Service delete successfully") return ctrl.Result{}, nil } @@ -212,31 +215,39 @@ func (r *OVNControllerReconciler) reconcileInit( instance *v1beta1.OVNController, helper *helper.Helper, ) (ctrl.Result, error) { - r.Log.Info("Reconciling Service init") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service init") //TODO(slaweq): // * read status of the external IDs // * if external IDs are different than required once, change them - r.Log.Info("Reconciled Service init successfully") + Log.Info("Reconciled Service init successfully") return ctrl.Result{}, nil } func (r *OVNControllerReconciler) reconcileUpdate(ctx context.Context, instance *v1beta1.OVNController, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Service update") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service update") - r.Log.Info("Reconciled Service update successfully") + Log.Info("Reconciled Service update successfully") return ctrl.Result{}, nil } func (r *OVNControllerReconciler) reconcileUpgrade(ctx context.Context, instance *v1beta1.OVNController, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Service upgrade") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service upgrade") - r.Log.Info("Reconciled Service upgrade successfully") + Log.Info("Reconciled Service upgrade successfully") return ctrl.Result{}, nil } func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance *v1beta1.OVNController, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Service") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service") // Service account, role, binding rbacRules := []rbacv1.PolicyRule{ @@ -311,7 +322,7 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance // Create additional Physical Network Attachments networkAttachments, err := ovncontroller.CreateAdditionalNetworks(ctx, helper, instance, serviceLabels) if err != nil { - r.Log.Info(fmt.Sprintf("Failed to create additional networks: %s", err)) + Log.Info(fmt.Sprintf("Failed to create additional networks: %s", err)) return ctrl.Result{}, err } @@ -378,7 +389,7 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance // Define a new DaemonSet object ovnDaemonSet, err := ovncontroller.DaemonSet(instance, inputHash, serviceLabels, serviceAnnotations) if err != nil { - r.Log.Error(err, "Failed to create OVNController DaemonSet") + Log.Error(err, "Failed to create OVNController DaemonSet") return ctrl.Result{}, err } dset := daemonset.NewDaemonSet( @@ -435,10 +446,10 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance sbCluster, err := v1beta1.GetDBClusterByType(ctx, helper, instance.Namespace, map[string]string{}, v1beta1.SBDBType) if err != nil { - r.Log.Info("No SB OVNDBCluster defined, deleting external ConfigMap") + Log.Info("No SB OVNDBCluster defined, deleting external ConfigMap") cleanupConfigMapErr := r.deleteExternalConfigMaps(ctx, helper, instance) if cleanupConfigMapErr != nil { - r.Log.Error(cleanupConfigMapErr, "Failed to delete external ConfigMap") + Log.Error(cleanupConfigMapErr, "Failed to delete external ConfigMap") return ctrl.Result{}, cleanupConfigMapErr } return ctrl.Result{}, nil @@ -446,10 +457,10 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance _, err = sbCluster.GetExternalEndpoint() if err != nil { - r.Log.Info("No external endpoint defined for SB OVNDBCluster, deleting external ConfigMap") + Log.Info("No external endpoint defined for SB OVNDBCluster, deleting external ConfigMap") cleanupConfigMapErr := r.deleteExternalConfigMaps(ctx, helper, instance) if cleanupConfigMapErr != nil { - r.Log.Error(cleanupConfigMapErr, "Failed to delete external ConfigMap") + Log.Error(cleanupConfigMapErr, "Failed to delete external ConfigMap") return ctrl.Result{}, cleanupConfigMapErr } return ctrl.Result{}, nil @@ -459,7 +470,7 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance // TODO(ihar) - is there any hashing mechanism for EDP config? do we trigger deploy somehow? err = r.generateExternalConfigMaps(ctx, helper, instance, sbCluster, &configMapVars) if err != nil { - r.Log.Error(err, "Failed to generate external ConfigMap") + Log.Error(err, "Failed to generate external ConfigMap") return ctrl.Result{}, err } @@ -467,7 +478,7 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance if instance.Status.NumberReady == instance.Status.DesiredNumberScheduled { jobsDef, err := ovncontroller.ConfigJob(ctx, helper, r.Client, instance, sbCluster, serviceLabels) if err != nil { - r.Log.Error(err, "Failed to create OVN controller configuration Job") + Log.Error(err, "Failed to create OVN controller configuration Job") return ctrl.Result{}, err } for _, jobDef := range jobsDef { @@ -493,7 +504,7 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance return ctrlResult, nil } if err != nil { - r.Log.Error(err, "Failed to configure OVN controller") + Log.Error(err, "Failed to configure OVN controller") instance.Status.Conditions.Set( condition.FalseCondition( condition.ServiceConfigReadyCondition, @@ -507,17 +518,17 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance } if configJob.HasChanged() { instance.Status.Hash[configHashKey] = configJob.GetHash() - r.Log.Info(fmt.Sprintf("Job %s hash added - %s", jobDef.Name, instance.Status.Hash[configHashKey])) + Log.Info(fmt.Sprintf("Job %s hash added - %s", jobDef.Name, instance.Status.Hash[configHashKey])) } } instance.Status.Conditions.MarkTrue(condition.ServiceConfigReadyCondition, condition.ServiceConfigReadyMessage) } else { - r.Log.Info("OVNController DaemonSet not ready yet. Configuration job cannot be started.") + Log.Info("OVNController DaemonSet not ready yet. Configuration job cannot be started.") return ctrl.Result{Requeue: true}, nil } // create OVN Config Job - end - r.Log.Info("Reconciled Service successfully") + Log.Info("Reconciled Service successfully") return ctrl.Result{}, nil } @@ -616,6 +627,8 @@ func (r *OVNControllerReconciler) createHashOfInputHashes( instance *v1beta1.OVNController, 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) @@ -625,7 +638,7 @@ func (r *OVNControllerReconciler) 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/ovndbcluster_controller.go b/controllers/ovndbcluster_controller.go index 5d8ec06f..9383a6b7 100644 --- a/controllers/ovndbcluster_controller.go +++ b/controllers/ovndbcluster_controller.go @@ -22,13 +22,14 @@ import ( "strings" "time" - "github.com/go-logr/logr" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + "sigs.k8s.io/controller-runtime/pkg/log" + "github.com/go-logr/logr" "github.com/openstack-k8s-operators/lib-common/modules/common" "github.com/openstack-k8s-operators/lib-common/modules/common/condition" "github.com/openstack-k8s-operators/lib-common/modules/common/configmap" @@ -53,7 +54,6 @@ import ( type OVNDBClusterReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } @@ -67,16 +67,16 @@ func (r *OVNDBClusterReconciler) GetKClient() kubernetes.Interface { return r.Kclient } -// GetLogger - -func (r *OVNDBClusterReconciler) GetLogger() logr.Logger { - return r.Log -} - // GetScheme - func (r *OVNDBClusterReconciler) GetScheme() *runtime.Scheme { return r.Scheme } +// getlog returns a logger object with a prefix of "conroller.name" and aditional controller context fields +func (r *OVNDBClusterReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("OVNDBCluster") +} + //+kubebuilder:rbac:groups=ovn.openstack.org,resources=ovndbclusters,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=ovn.openstack.org,resources=ovndbclusters/status,verbs=get;update;patch //+kubebuilder:rbac:groups=ovn.openstack.org,resources=ovndbclusters/finalizers,verbs=update @@ -97,7 +97,7 @@ func (r *OVNDBClusterReconciler) GetScheme() *runtime.Scheme { // Reconcile - OVN DBCluster func (r *OVNDBClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { _ = context.Background() - _ = r.Log.WithValues("ovndbcluster", req.NamespacedName) + Log := r.GetLogger(ctx) // Fetch the OVNDBCluster instance instance := &ovnv1.OVNDBCluster{} @@ -148,7 +148,7 @@ func (r *OVNDBClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request r.Client, r.Kclient, r.Scheme, - r.Log, + Log, ) if err != nil { return ctrl.Result{}, err @@ -198,11 +198,13 @@ func (r *OVNDBClusterReconciler) SetupWithManager(mgr ctrl.Manager) error { } func (r *OVNDBClusterReconciler) reconcileDelete(ctx context.Context, instance *ovnv1.OVNDBCluster, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Service delete") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service delete") // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - r.Log.Info("Reconciled Service delete successfully") + Log.Info("Reconciled Service delete successfully") if err := r.Update(ctx, instance); err != nil && !k8s_errors.IsNotFound(err) { return ctrl.Result{}, err } @@ -211,27 +213,33 @@ func (r *OVNDBClusterReconciler) reconcileDelete(ctx context.Context, instance * } func (r *OVNDBClusterReconciler) reconcileUpdate(ctx context.Context, instance *ovnv1.OVNDBCluster, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Service update") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service update") // TODO: should have minor update tasks if required // - delete dbsync hash from status to rerun it? - r.Log.Info("Reconciled Service update successfully") + Log.Info("Reconciled Service update successfully") return ctrl.Result{}, nil } func (r *OVNDBClusterReconciler) reconcileUpgrade(ctx context.Context, instance *ovnv1.OVNDBCluster, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Service upgrade") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service upgrade") // TODO: should have major version upgrade tasks // -delete dbsync hash from status to rerun it? - r.Log.Info("Reconciled Service upgrade successfully") + Log.Info("Reconciled Service upgrade successfully") return ctrl.Result{}, nil } func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance *ovnv1.OVNDBCluster, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Service") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service") if !controllerutil.ContainsFinalizer(instance, helper.GetFinalizer()) { // If the service object doesn't have our finalizer, add it. @@ -484,7 +492,7 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance * // Set RaftAddress instance.Status.RaftAddress = strings.Join(raftAddress, ",") } - r.Log.Info("Reconciled Service successfully") + Log.Info("Reconciled Service successfully") return ctrl.Result{}, nil } @@ -495,7 +503,9 @@ func (r *OVNDBClusterReconciler) reconcileServices( serviceLabels map[string]string, serviceName string, ) (ctrl.Result, error) { - r.Log.Info("Reconciling OVN DB Cluster Service") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling OVN DB Cluster Service") // // Ensure the ovndbcluster headless service Exists @@ -571,7 +581,7 @@ func (r *OVNDBClusterReconciler) reconcileServices( } } } - r.Log.Info("Reconciled OVN DB Cluster Service successfully") + Log.Info("Reconciled OVN DB Cluster Service successfully") return ctrl.Result{}, nil } @@ -630,6 +640,8 @@ func (r *OVNDBClusterReconciler) createHashOfInputHashes( instance *ovnv1.OVNDBCluster, envVars map[string]env.Setter, ) (string, error) { + Log := r.GetLogger(ctx) + mergedMapVars := env.MergeEnvs([]corev1.EnvVar{}, envVars) hash, err := util.ObjectHash(mergedMapVars) if err != nil { @@ -640,7 +652,7 @@ func (r *OVNDBClusterReconciler) createHashOfInputHashes( if err := r.Client.Status().Update(ctx, instance); err != nil { return hash, err } - 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, nil } diff --git a/controllers/ovnnorthd_controller.go b/controllers/ovnnorthd_controller.go index 8edb900b..d06da219 100644 --- a/controllers/ovnnorthd_controller.go +++ b/controllers/ovnnorthd_controller.go @@ -21,15 +21,16 @@ import ( "fmt" "time" - "github.com/go-logr/logr" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/kubernetes" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/source" + "github.com/go-logr/logr" "github.com/openstack-k8s-operators/lib-common/modules/common" "github.com/openstack-k8s-operators/lib-common/modules/common/condition" "github.com/openstack-k8s-operators/lib-common/modules/common/configmap" @@ -53,7 +54,6 @@ import ( type OVNNorthdReconciler struct { client.Client Kclient kubernetes.Interface - Log logr.Logger Scheme *runtime.Scheme } @@ -62,16 +62,16 @@ func (r *OVNNorthdReconciler) GetClient() client.Client { return r.Client } -// GetLogger - -func (r *OVNNorthdReconciler) GetLogger() logr.Logger { - return r.Log -} - // GetScheme - func (r *OVNNorthdReconciler) GetScheme() *runtime.Scheme { return r.Scheme } +// getlog returns a logger object with a prefix of "conroller.name" and aditional controller context fields +func (r *OVNNorthdReconciler) GetLogger(ctx context.Context) logr.Logger { + return log.FromContext(ctx).WithName("Controllers").WithName("OVNNorthd") +} + //+kubebuilder:rbac:groups=ovn.openstack.org,resources=ovnnorthds,verbs=get;list;watch;create;update;patch;delete //+kubebuilder:rbac:groups=ovn.openstack.org,resources=ovnnorthds/status,verbs=get;update;patch //+kubebuilder:rbac:groups=ovn.openstack.org,resources=ovnnorthds/finalizers,verbs=update @@ -93,7 +93,7 @@ func (r *OVNNorthdReconciler) GetScheme() *runtime.Scheme { // Reconcile - OVN Northd func (r *OVNNorthdReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { _ = context.Background() - _ = r.Log.WithValues("ovnnorthd", req.NamespacedName) + Log := r.GetLogger(ctx) // Fetch the OVNNorthd instance instance := &ovnv1.OVNNorthd{} @@ -143,7 +143,7 @@ func (r *OVNNorthdReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( r.Client, r.Kclient, r.Scheme, - r.Log, + Log, ) if err != nil { return ctrl.Result{}, err @@ -180,7 +180,8 @@ func (r *OVNNorthdReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( } // SetupWithManager sets up the controller with the Manager. -func (r *OVNNorthdReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *OVNNorthdReconciler) SetupWithManager(mgr ctrl.Manager, ctx context.Context) error { + Log := r.GetLogger(ctx) crs := &ovnv1.OVNNorthdList{} return ctrl.NewControllerManagedBy(mgr). For(&ovnv1.OVNNorthd{}). @@ -189,16 +190,18 @@ func (r *OVNNorthdReconciler) SetupWithManager(mgr ctrl.Manager) error { Owns(&corev1.ServiceAccount{}). Owns(&rbacv1.Role{}). Owns(&rbacv1.RoleBinding{}). - Watches(&source.Kind{Type: &ovnv1.OVNDBCluster{}}, handler.EnqueueRequestsFromMapFunc(ovnv1.OVNDBClusterNamespaceMapFunc(crs, mgr.GetClient(), r.Log))). + Watches(&source.Kind{Type: &ovnv1.OVNDBCluster{}}, handler.EnqueueRequestsFromMapFunc(ovnv1.OVNDBClusterNamespaceMapFunc(crs, mgr.GetClient(), Log))). Complete(r) } func (r *OVNNorthdReconciler) reconcileDelete(ctx context.Context, instance *ovnv1.OVNNorthd, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Service delete") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service delete") // Service is deleted so remove the finalizer. controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - r.Log.Info("Reconciled Service delete successfully") + Log.Info("Reconciled Service delete successfully") if err := r.Update(ctx, instance); err != nil && !k8s_errors.IsNotFound(err) { return ctrl.Result{}, err } @@ -207,27 +210,33 @@ func (r *OVNNorthdReconciler) reconcileDelete(ctx context.Context, instance *ovn } func (r *OVNNorthdReconciler) reconcileUpdate(ctx context.Context, instance *ovnv1.OVNNorthd, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Service update") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service update") // TODO: should have minor update tasks if required // - delete dbsync hash from status to rerun it? - r.Log.Info("Reconciled Service update successfully") + Log.Info("Reconciled Service update successfully") return ctrl.Result{}, nil } func (r *OVNNorthdReconciler) reconcileUpgrade(ctx context.Context, instance *ovnv1.OVNNorthd, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Service upgrade") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service upgrade") // TODO: should have major version upgrade tasks // -delete dbsync hash from status to rerun it? - r.Log.Info("Reconciled Service upgrade successfully") + Log.Info("Reconciled Service upgrade successfully") return ctrl.Result{}, nil } func (r *OVNNorthdReconciler) reconcileNormal(ctx context.Context, instance *ovnv1.OVNNorthd, helper *helper.Helper) (ctrl.Result, error) { - r.Log.Info("Reconciling Service") + Log := r.GetLogger(ctx) + + Log.Info("Reconciling Service") if !controllerutil.ContainsFinalizer(instance, helper.GetFinalizer()) { // If the service object doesn't have our finalizer, add it. @@ -412,7 +421,7 @@ func (r *OVNNorthdReconciler) reconcileNormal(ctx context.Context, instance *ovn } // create Deployment - end - r.Log.Info("Reconciled Service successfully") + Log.Info("Reconciled Service successfully") return ctrl.Result{}, nil } @@ -478,6 +487,8 @@ func (r *OVNNorthdReconciler) createHashOfInputHashes( instance *ovnv1.OVNNorthd, envVars map[string]env.Setter, ) (string, error) { + Log := r.GetLogger(ctx) + mergedMapVars := env.MergeEnvs([]corev1.EnvVar{}, envVars) hash, err := util.ObjectHash(mergedMapVars) if err != nil { @@ -488,7 +499,7 @@ func (r *OVNNorthdReconciler) createHashOfInputHashes( if err := r.Client.Status().Update(ctx, instance); err != nil { return hash, err } - 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, nil } diff --git a/main.go b/main.go index 3815c3e7..f9e74c67 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ limitations under the License. package main import ( + "context" "flag" "os" "strings" @@ -98,8 +99,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("OVNNorthd"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(mgr, context.Background()); err != nil { setupLog.Error(err, "unable to create controller", "controller", "OVNNorthd") os.Exit(1) } @@ -107,7 +107,6 @@ func main() { Client: mgr.GetClient(), Kclient: kclient, Scheme: mgr.GetScheme(), - Log: ctrl.Log.WithName("controllers").WithName("OVNDBCluster"), }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "OVNDBCluster") os.Exit(1) @@ -116,8 +115,7 @@ func main() { Client: mgr.GetClient(), Kclient: kclient, Scheme: mgr.GetScheme(), - Log: ctrl.Log.WithName("controllers").WithName("OVNController"), - }).SetupWithManager(mgr); err != nil { + }).SetupWithManager(mgr, context.Background()); err != nil { setupLog.Error(err, "unable to create controller", "controller", "OVNController") os.Exit(1) } diff --git a/tests/functional/suite_test.go b/tests/functional/suite_test.go index 39081065..2392cce6 100644 --- a/tests/functional/suite_test.go +++ b/tests/functional/suite_test.go @@ -150,15 +150,13 @@ var _ = BeforeSuite(func() { Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("OVNNorthd"), - }).SetupWithManager(k8sManager) + }).SetupWithManager(k8sManager, context.Background()) Expect(err).ToNot(HaveOccurred()) err = (&controllers.OVNDBClusterReconciler{ Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("OVNDBCluster"), }).SetupWithManager(k8sManager) Expect(err).ToNot(HaveOccurred()) @@ -166,8 +164,7 @@ var _ = BeforeSuite(func() { Client: k8sManager.GetClient(), Scheme: k8sManager.GetScheme(), Kclient: kclient, - Log: ctrl.Log.WithName("controllers").WithName("OVNController"), - }).SetupWithManager(k8sManager) + }).SetupWithManager(k8sManager, context.Background()) Expect(err).ToNot(HaveOccurred()) // Acquire environmental defaults and initialize operator defaults with them