-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #206 from gibizer/new-logging-interface
Use the new lib-common/common/log interface
- Loading branch information
Showing
4 changed files
with
33 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,12 +26,12 @@ import ( | |
"k8s.io/apimachinery/pkg/types" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
|
||
common "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/endpoint" | ||
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper" | ||
log "github.com/openstack-k8s-operators/lib-common/modules/common/log" | ||
util "github.com/openstack-k8s-operators/lib-common/modules/common/util" | ||
database "github.com/openstack-k8s-operators/lib-common/modules/database" | ||
|
||
|
@@ -67,6 +67,7 @@ type NovaReconciler struct { | |
// For more details, check Reconcile and its Result here: | ||
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile | ||
func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { | ||
ctx = log.IntoContext(ctx, req, "Nova") | ||
l := log.FromContext(ctx) | ||
|
||
// Fetch the NovaAPI instance that needs to be reconciled | ||
|
@@ -96,7 +97,7 @@ func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul | |
l.Error(err, "Failed to create lib-common Helper") | ||
return ctrl.Result{}, err | ||
} | ||
util.LogForObject(h, "Reconciling", instance) | ||
l.Info("Reconciling") | ||
|
||
// initialize status fields | ||
if err = r.initStatus(ctx, h, instance); err != nil { | ||
|
@@ -128,7 +129,7 @@ func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul | |
// the our KeystoneService so that is also deleted. | ||
updated := controllerutil.AddFinalizer(instance, h.GetFinalizer()) | ||
if updated { | ||
util.LogForObject(h, "Added finalizer to ourselves", instance) | ||
l.Info("Added finalizer to ourselves") | ||
// we intentionally return imediately to force the deferred function | ||
// to persist the Instance with the finalizer. We need to have our own | ||
// finalizer persisted before we try to create the KeystoneService with | ||
|
@@ -150,7 +151,7 @@ func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul | |
|
||
// We have to wait until our service is registered to keystone | ||
if !instance.Status.Conditions.IsTrue(condition.KeystoneServiceReadyCondition) { | ||
util.LogForObject(h, "Waiting for the KeystoneService to become Ready", instance) | ||
l.Info("Waiting for the KeystoneService to become Ready") | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
|
@@ -325,17 +326,13 @@ func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul | |
if cellDB.Status != nova.DBCompleted { | ||
allCellsReady = false | ||
skippedCells = append(skippedCells, cellName) | ||
util.LogForObject( | ||
h, "Skipping NovaCell as waiting for the cell DB to be created", | ||
instance, "CellName", cellName) | ||
l.Info("Skipping NovaCell as waiting for the cell DB to be created", "CellName", cellName) | ||
continue | ||
} | ||
if cellMQ.Status != nova.MQCompleted { | ||
allCellsReady = false | ||
skippedCells = append(skippedCells, cellName) | ||
util.LogForObject( | ||
h, "Skipping NovaCell as waiting for the cell MQ to be created", | ||
instance, "CellName", cellName) | ||
l.Info("Skipping NovaCell as waiting for the cell MQ to be created", "CellName", cellName) | ||
continue | ||
} | ||
|
||
|
@@ -345,9 +342,8 @@ func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul | |
if cellName != Cell0Name && cellTemplate.HasAPIAccess && !cells[Cell0Name].IsReady() { | ||
allCellsReady = false | ||
skippedCells = append(skippedCells, cellName) | ||
util.LogForObject( | ||
h, "Skippig NovaCell as cell0 is not ready yet and this cell needs API DB access", | ||
instance, "CellName", cellName) | ||
l.Info( | ||
"Skippig NovaCell as cell0 is not ready yet and this cell needs API DB access", "CellName", cellName) | ||
continue | ||
} | ||
|
||
|
@@ -366,10 +362,14 @@ func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul | |
|
||
allCellsReady = allCellsReady && cell.IsReady() | ||
} | ||
util.LogForObject( | ||
h, "Cell statuses", instance, "failed", failedCells, | ||
"creating", creatingCells, "waiting", skippedCells, | ||
"ready", readyCells, "all cells ready", allCellsReady) | ||
l.Info( | ||
"Cell statuses", | ||
"failed", failedCells, | ||
"creating", creatingCells, | ||
"waiting", skippedCells, | ||
"ready", readyCells, | ||
"all cells ready", allCellsReady, | ||
) | ||
if len(failedCells) > 0 { | ||
instance.Status.Conditions.Set(condition.FalseCondition( | ||
novav1.NovaAllCellsReadyCondition, | ||
|
@@ -403,7 +403,7 @@ func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul | |
// until cell0 is ready as top level services need cell0 to register in | ||
if cell0, ok := cells[Cell0Name]; !ok || !cell0.IsReady() { | ||
// we need to stop here until cell0 is ready | ||
util.LogForObject(h, "Waiting for cell0 to become Ready before creating the top level services", instance) | ||
l.Info("Waiting for cell0 to become Ready before creating the top level services") | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
|
@@ -415,7 +415,7 @@ func (r *NovaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resul | |
return result, err | ||
} | ||
|
||
util.LogForObject(h, "Successfully reconciled", instance) | ||
l.Info("Successfully reconciled") | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
|
@@ -644,7 +644,7 @@ func (r *NovaReconciler) ensureCell( | |
} | ||
|
||
if op != controllerutil.OperationResultNone { | ||
util.LogForObject(h, fmt.Sprintf("NovaCell %s.", string(op)), instance, "NovaCell.Name", cell.Name) | ||
log.FromContext(ctx).Info(fmt.Sprintf("NovaCell %s.", string(op)), "NovaCell.Name", cell.Name) | ||
} | ||
|
||
return cell, ctrl.Result{}, nil | ||
|
@@ -709,7 +709,7 @@ func (r *NovaReconciler) ensureAPI( | |
} | ||
|
||
if op != controllerutil.OperationResultNone { | ||
util.LogForObject(h, fmt.Sprintf("NovaAPI %s.", string(op)), instance, "NovaAPI.Name", api.Name) | ||
log.FromContext(ctx).Info(fmt.Sprintf("NovaAPI %s.", string(op)), "NovaAPI.Name", api.Name) | ||
} | ||
|
||
c := api.Status.Conditions.Mirror(novav1.NovaAPIReadyCondition) | ||
|
@@ -788,7 +788,7 @@ func (r *NovaReconciler) ensureKeystoneServiceUserDeletion( | |
if err = h.GetClient().Update(ctx, service); err != nil && !k8s_errors.IsNotFound(err) { | ||
return err | ||
} | ||
util.LogForObject(h, "Removed finalizer from nova KeystoneService", instance) | ||
log.FromContext(ctx).Info("Removed finalizer from nova KeystoneService") | ||
|
||
return nil | ||
} | ||
|
@@ -817,7 +817,8 @@ func (r *NovaReconciler) reconcileDelete( | |
h *helper.Helper, | ||
instance *novav1.Nova, | ||
) error { | ||
util.LogForObject(h, "Reconciling delete", instance) | ||
l := log.FromContext(ctx) | ||
l.Info("Reconciling delete") | ||
|
||
err := r.ensureKeystoneServiceUserDeletion(ctx, h, instance) | ||
if err != nil { | ||
|
@@ -828,10 +829,10 @@ func (r *NovaReconciler) reconcileDelete( | |
// finalizer from ourselves to allow the deletion of Nova CR itself | ||
updated := controllerutil.RemoveFinalizer(instance, h.GetFinalizer()) | ||
if updated { | ||
util.LogForObject(h, "Removed finalizer from ourselves", instance) | ||
l.Info("Removed finalizer from ourselves") | ||
} | ||
|
||
util.LogForObject(h, "Reconciled delete successfully", instance) | ||
l.Info("Reconciled delete successfully") | ||
return nil | ||
} | ||
|
||
|
@@ -865,7 +866,7 @@ func (r *NovaReconciler) ensureMQ( | |
} | ||
|
||
if op != controllerutil.OperationResultNone { | ||
util.LogForObject(h, fmt.Sprintf("TransportURL object %s created or patched", transportName), transportURL) | ||
log.FromContext(ctx).Info("TransportURL created or patched", "TransportURL", transportURL) | ||
return "", nova.MQCreating, nil | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters