Skip to content

Commit

Permalink
Set verbosity level for debug logs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
weinimo committed Jun 12, 2024
1 parent 2992026 commit be1c284
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
22 changes: 11 additions & 11 deletions controllers/amphoracontroller_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions controllers/octavia_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
}

Expand Down
20 changes: 10 additions & 10 deletions controllers/octaviaapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
//
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions pkg/octavia/lb_mgmt_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit be1c284

Please sign in to comment.