Skip to content

Commit

Permalink
Use the new lib-common/common/log interface
Browse files Browse the repository at this point in the history
  • Loading branch information
gibizer committed Dec 19, 2022
1 parent e5faf6b commit a529564
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
53 changes: 27 additions & 26 deletions controllers/nova_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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,
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@ require (
)

replace github.com/openstack-k8s-operators/nova-operator/api => ./api

replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/gibizer/lib-common/modules/common v0.0.0-20221219140315-47b042183a5b
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ github.com/flowstack/go-jsonschema v0.1.1/go.mod h1:yL7fNggx1o8rm9RlgXv7hTBWxdBM
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gibizer/lib-common/modules/common v0.0.0-20221219140315-47b042183a5b h1:J7HneemRRPUAFpBUxlTEIXQ3za4J/kUwpSwWf8fNchw=
github.com/gibizer/lib-common/modules/common v0.0.0-20221219140315-47b042183a5b/go.mod h1:qV9OlokZRpqbHI3lmeN5EOmIKynWphw6GPl3zP9KOGM=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down Expand Up @@ -284,8 +286,6 @@ github.com/openshift/api v3.9.0+incompatible h1:fJ/KsefYuZAjmrr3+5U9yZIZbTOpVkDD
github.com/openshift/api v3.9.0+incompatible/go.mod h1:dh9o4Fs58gpFXGSYfnVxGR9PnV53I8TW84pQaJDdGiY=
github.com/openstack-k8s-operators/keystone-operator/api v0.0.0-20221123090515-e2561e258f0a h1:x1MGRitaQNIKdcyJUtcXRvKFhN3l5hcYlc7lD5N0APg=
github.com/openstack-k8s-operators/keystone-operator/api v0.0.0-20221123090515-e2561e258f0a/go.mod h1:SwhyYcQUbpT4QLuqdsLjAlM0oPouHIJy1gVOkM4O5xQ=
github.com/openstack-k8s-operators/lib-common/modules/common v0.0.0-20221124114404-c42a739be111 h1:X5Y2zXwOiPPFoQN0Ox8C2jL1tZo3+S9BjcOf9h/EYbU=
github.com/openstack-k8s-operators/lib-common/modules/common v0.0.0-20221124114404-c42a739be111/go.mod h1:qV9OlokZRpqbHI3lmeN5EOmIKynWphw6GPl3zP9KOGM=
github.com/openstack-k8s-operators/lib-common/modules/database v0.0.0-20221115095652-2c390a9d20b4 h1:RSIOKTJoJivtHJPhXXU6raTApSXsHK/CJS10iFqeI8s=
github.com/openstack-k8s-operators/lib-common/modules/database v0.0.0-20221115095652-2c390a9d20b4/go.mod h1:umGUqQO4JtgefAaIwZjP+TxfxsLMEEeK/6VNzk8ooaI=
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.0.0-20220915080953-f73a201a1da6 h1:MVNEHyqD0ZdO9jiyUSKw5M2T9Lc4l4Wx1pdC2/BSJ5Y=
Expand Down
2 changes: 2 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg=
github.com/getsentry/raven-go v0.2.0/go.mod h1:KungGk8q33+aIAZUIVWZDr2OfAEBsO49PX4NzFV5kcQ=
github.com/gibizer/lib-common/modules/common v0.0.0-20221219140315-47b042183a5b h1:J7HneemRRPUAFpBUxlTEIXQ3za4J/kUwpSwWf8fNchw=
github.com/gibizer/lib-common/modules/common v0.0.0-20221219140315-47b042183a5b/go.mod h1:qV9OlokZRpqbHI3lmeN5EOmIKynWphw6GPl3zP9KOGM=
github.com/gibizer/openstack-operator/apis v0.0.0-20221117131348-5458078589f5/go.mod h1:ScmKvwvPeQv9qbFQ5wPnVE3y7iRuxic29NxX+P7iWG8=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
Expand Down

0 comments on commit a529564

Please sign in to comment.