From be1c284e433d3e457d87dddf79727689352c8aad Mon Sep 17 00:00:00 2001 From: Tom Weininger Date: Mon, 10 Jun 2024 14:59:46 +0000 Subject: [PATCH] Set verbosity level for debug logs In order to be able to filter debug logs from other info logs, we should use verbosity level. Zap used level 1 (-1 actually) for debug. --- controllers/amphoracontroller_controller.go | 22 ++++++++++----------- controllers/octavia_controller.go | 16 +++++++-------- controllers/octaviaapi_controller.go | 20 +++++++++---------- main.go | 2 ++ pkg/octavia/lb_mgmt_network.go | 4 ++-- 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/controllers/amphoracontroller_controller.go b/controllers/amphoracontroller_controller.go index 30e7c9a7..d516aad1 100644 --- a/controllers/amphoracontroller_controller.go +++ b/controllers/amphoracontroller_controller.go @@ -187,32 +187,32 @@ func (r *OctaviaAmphoraControllerReconciler) Reconcile(ctx context.Context, req func (r *OctaviaAmphoraControllerReconciler) reconcileDelete(ctx context.Context, instance *octaviav1.OctaviaAmphoraController, helper *helper.Helper) (ctrl.Result, error) { Log := r.GetLogger(ctx) - Log.Info("Reconciling Service delete") + Log.V(1).Info("Reconciling Service delete") controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) - Log.Info("Reconciled Service delete successfully") + Log.V(1).Info("Reconciled Service delete successfully") return ctrl.Result{}, nil } func (r *OctaviaAmphoraControllerReconciler) reconcileUpdate(ctx context.Context) (ctrl.Result, error) { Log := r.GetLogger(ctx) - Log.Info("Reconciling Service update") - Log.Info("Reconciled Service update successfully") + Log.V(1).Info("Reconciling Service update") + Log.V(1).Info("Reconciled Service update successfully") return ctrl.Result{}, nil } func (r *OctaviaAmphoraControllerReconciler) reconcileUpgrade(ctx context.Context) (ctrl.Result, error) { Log := r.GetLogger(ctx) - Log.Info("Reconciling Service upgrade") - Log.Info("Reconciled Service upgrade successfully") + Log.V(1).Info("Reconciling Service upgrade") + Log.V(1).Info("Reconciled Service upgrade successfully") return ctrl.Result{}, nil } func (r *OctaviaAmphoraControllerReconciler) reconcileNormal(ctx context.Context, instance *octaviav1.OctaviaAmphoraController, helper *helper.Helper) (ctrl.Result, error) { Log := r.GetLogger(ctx) - Log.Info("Reconciling Service") + Log.V(1).Info("Reconciling Service") // Prepare NetworkAttachments first, it must be done before generating the // configuration as the config uses IP addresses of the attachments. @@ -459,6 +459,7 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileNormal(ctx context.Context // We reached the end of the Reconcile, update the Ready condition based on // the sub conditions if instance.Status.Conditions.AllSubConditionIsTrue() { + Log.V(1).Info("Setting Ready condition to true.") instance.Status.Conditions.MarkTrue( condition.ReadyCondition, condition.ReadyMessage) } else { @@ -475,7 +476,7 @@ func (r *OctaviaAmphoraControllerReconciler) generateServiceConfigMaps( templateVars OctaviaTemplateVars, ospSecret *corev1.Secret, ) error { - r.Log.Info(fmt.Sprintf("generating service config map for %s (%s)", instance.Name, instance.Kind)) + r.Log.V(1).Info(fmt.Sprintf("generating service config map for %s (%s)", instance.Name, instance.Kind)) cmLabels := labels.GetLabels(instance, labels.GetGroupLabel(instance.ObjectMeta.Name), map[string]string{}) db, err := mariadbv1.GetDatabaseByNameAndAccount(ctx, helper, octavia.DatabaseName, instance.Spec.DatabaseAccount, instance.Namespace) if err != nil { @@ -666,8 +667,7 @@ func (r *OctaviaAmphoraControllerReconciler) generateServiceConfigMaps( return err } - r.Log.Info("Service config map generated") - + r.Log.V(1).Info("Service config map generated") return nil } @@ -732,7 +732,7 @@ func listHealthManagerPods(name string, ns string, client kubernetes.Interface, LabelSelector: fmt.Sprintf("%s=%s", common.AppSelector, name), FieldSelector: "status.phase==Running", } - log.Info(fmt.Sprintf("Listing pods using label selector %s and field selector %s", listOptions.LabelSelector, listOptions.FieldSelector)) + log.V(1).Info(fmt.Sprintf("Listing pods using label selector %s and field selector %s", listOptions.LabelSelector, listOptions.FieldSelector)) pods, err := client.CoreV1().Pods(ns).List(context.Background(), listOptions) if err != nil { return nil, err diff --git a/controllers/octavia_controller.go b/controllers/octavia_controller.go index 75baa807..42b37b0b 100644 --- a/controllers/octavia_controller.go +++ b/controllers/octavia_controller.go @@ -299,7 +299,7 @@ func (r *OctaviaReconciler) reconcileInit( serviceAnnotations map[string]string, ) (ctrl.Result, error) { Log := r.GetLogger(ctx) - Log.Info("Reconciling Service init") + Log.V(1).Info("Reconciling Service init") // ConfigMap configMapVars := make(map[string]env.Setter) @@ -428,35 +428,35 @@ func (r *OctaviaReconciler) reconcileInit( // run octavia db sync - end - Log.Info("Reconciled Service init successfully") + Log.V(1).Info("Reconciled Service init successfully") return ctrl.Result{}, nil } func (r *OctaviaReconciler) reconcileUpdate(ctx context.Context) (ctrl.Result, error) { Log := r.GetLogger(ctx) - Log.Info("Reconciling Service update") + Log.V(1).Info("Reconciling Service update") // TODO: should have minor update tasks if required // - delete dbsync hash from status to rerun it? - Log.Info("Reconciled Service update successfully") + Log.V(1).Info("Reconciled Service update successfully") return ctrl.Result{}, nil } func (r *OctaviaReconciler) reconcileUpgrade(ctx context.Context) (ctrl.Result, error) { Log := r.GetLogger(ctx) - Log.Info("Reconciling Service upgrade") + Log.V(1).Info("Reconciling Service upgrade") // TODO: should have major version upgrade tasks // -delete dbsync hash from status to rerun it? - Log.Info("Reconciled Service upgrade successfully") + Log.V(1).Info("Reconciled Service upgrade successfully") return ctrl.Result{}, nil } func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octaviav1.Octavia, helper *helper.Helper) (ctrl.Result, error) { Log := r.GetLogger(ctx) - Log.Info("Reconciling Service") + Log.V(1).Info("Reconciling Service") // Service account, role, binding rbacRules := []rbacv1.PolicyRule{ @@ -831,7 +831,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav instance.Status.Conditions.MarkTrue( condition.ReadyCondition, condition.ReadyMessage) } - Log.Info("Reconciled Service successfully") + Log.V(1).Info("Reconciled Service successfully") return ctrl.Result{}, nil } diff --git a/controllers/octaviaapi_controller.go b/controllers/octaviaapi_controller.go index 3bda932a..7427fb35 100644 --- a/controllers/octaviaapi_controller.go +++ b/controllers/octaviaapi_controller.go @@ -361,7 +361,7 @@ func (r *OctaviaAPIReconciler) reconcileInit( serviceLabels map[string]string, ) (ctrl.Result, error) { Log := r.GetLogger(ctx) - Log.Info("Reconciling Service init") + Log.V(1).Info("Reconciling Service init") // // expose the service (create service and return the created endpoint URLs) // @@ -526,36 +526,36 @@ func (r *OctaviaAPIReconciler) reconcileInit( instance.Status.Conditions.Set(c) } - Log.Info("Reconciled Service init successfully") + Log.V(1).Info("Reconciled Service init successfully") return ctrlResult, nil } func (r *OctaviaAPIReconciler) reconcileUpdate(ctx context.Context) (ctrl.Result, error) { Log := r.GetLogger(ctx) - Log.Info("Reconciling Service update") + Log.V(1).Info("Reconciling Service update") // TODO: should have minor update tasks if required // - delete dbsync hash from status to rerun it? - Log.Info("Reconciled Service update successfully") + Log.V(1).Info("Reconciled Service update successfully") return ctrl.Result{}, nil } func (r *OctaviaAPIReconciler) reconcileUpgrade(ctx context.Context) (ctrl.Result, error) { Log := r.GetLogger(ctx) - Log.Info("Reconciling Service upgrade") + Log.V(1).Info("Reconciling Service upgrade") // TODO: should have major version upgrade tasks // -delete dbsync hash from status to rerun it? - Log.Info("Reconciled Service upgrade successfully") + Log.V(1).Info("Reconciled Service upgrade successfully") return ctrl.Result{}, nil } // TODO(tweining): implement func (r *OctaviaAPIReconciler) reconcileNormal(ctx context.Context, instance *octaviav1.OctaviaAPI, helper *helper.Helper) (ctrl.Result, error) { Log := r.GetLogger(ctx) - Log.Info("Reconciling Service") + Log.V(1).Info("Reconciling Service") // ConfigMap configMapVars := make(map[string]env.Setter) @@ -836,7 +836,7 @@ func (r *OctaviaAPIReconciler) reconcileNormal(ctx context.Context, instance *oc instance.Status.Conditions.MarkTrue( condition.ReadyCondition, condition.ReadyMessage) } - Log.Info("Reconciled Service successfully") + Log.V(1).Info("Reconciled Service successfully") return ctrl.Result{}, nil } @@ -849,7 +849,7 @@ func (r *OctaviaAPIReconciler) generateServiceConfigMaps( envVars *map[string]env.Setter, ) error { Log := r.GetLogger(ctx) - Log.Info("Generating service config map") + Log.V(1).Info("Generating service config map") // // create Configmap/Secret required for octavia input // - %-scripts configmap holding scripts to e.g. bootstrap the service @@ -1004,7 +1004,7 @@ func (r *OctaviaAPIReconciler) generateServiceConfigMaps( Log.Error(err, "unable to process config map") return err } - Log.Info("Service config map generated") + Log.V(1).Info("Service config map generated") return nil } diff --git a/main.go b/main.go index 032c741a..baedecaa 100644 --- a/main.go +++ b/main.go @@ -81,6 +81,8 @@ func main() { opts := zap.Options{ Development: true, TimeEncoder: zapcore.ISO8601TimeEncoder, + // Set level to 0 in order to hide all debug logs + // Level: zapcore.Level(0), } opts.BindFlags(flag.CommandLine) flag.Parse() diff --git a/pkg/octavia/lb_mgmt_network.go b/pkg/octavia/lb_mgmt_network.go index 17327e86..08aefba2 100644 --- a/pkg/octavia/lb_mgmt_network.go +++ b/pkg/octavia/lb_mgmt_network.go @@ -845,12 +845,12 @@ func EnsureAmphoraManagementNetwork( return NetworkProvisioningSummary{}, err } if router != nil { - log.Info("Router object found, reconciling") + log.V(1).Info("Router object found, reconciling") router, err = reconcileRouter(client, router, providerNetwork, providerSubnet, networkParameters, log) if err != nil { return NetworkProvisioningSummary{}, err } - log.Info(fmt.Sprintf("Reconciled router %s (%s)", router.Name, router.ID)) + log.V(1).Info(fmt.Sprintf("Reconciled router %s (%s)", router.Name, router.ID)) } else { log.Info("Creating octavia provider router") enableSNAT := false