Skip to content

Commit

Permalink
controplane getlog func and mariah log update
Browse files Browse the repository at this point in the history
  • Loading branch information
pinikomarov committed Jun 28, 2023
1 parent ce1e894 commit a164ffa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
12 changes: 9 additions & 3 deletions controllers/core/openstackcontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@ type OpenStackControlPlaneReconciler struct {
//
// For more details, check Reconcile and its Result here:
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile

// GetLog returns a logger object with a prefix of "conroller.name" and aditional controller context fields
func GetLog(ctx context.Context) logr.Logger {
return log.FromContext(ctx).WithName("Controllers").WithName("OpenstackControlPlane")
}

func (r *OpenStackControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) {
_ = log.FromContext(ctx)

l := GetLog(ctx)
// Fetch the OpenStackControlPlane instance
instance := &corev1beta1.OpenStackControlPlane{}
err := r.Client.Get(ctx, req.NamespacedName, instance)
Expand All @@ -101,7 +107,7 @@ func (r *OpenStackControlPlaneReconciler) Reconcile(ctx context.Context, req ctr
// Request object not found, could have been deleted after reconcile request.
// Owned objects are automatically garbage collected.
// For additional cleanup logic use finalizers. Return and don't requeue.
r.Log.Info("OpenStackControlPlane instance is not found, probaby deleted. Nothing to do.")
l.Info("OpenStackControlPlane instance is not found, probaby deleted. Nothing to do.")
return ctrl.Result{}, nil
}
// Error reading the object - requeue the request.
Expand All @@ -117,7 +123,7 @@ func (r *OpenStackControlPlaneReconciler) Reconcile(ctx context.Context, req ctr
)
if err != nil {
// helper might be nil, so can't use util.LogErrorForObject since it requires helper as first arg
r.Log.Error(err, fmt.Sprintf("unable to acquire helper for OpenStackControlPlane %s", instance.Name))
l.Error(err, fmt.Sprintf("unable to acquire helper for OpenStackControlPlane %s", instance.Name))
return ctrl.Result{}, err
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/openstack/mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
"github.com/openstack-k8s-operators/openstack-operator/controllers/core"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
)
Expand Down Expand Up @@ -94,6 +95,8 @@ func reconcileMariaDB(
},
}

l := core.GetLog(ctx)

if !instance.Spec.Mariadb.Enabled {
if _, err := EnsureDeleted(ctx, helper, mariadb); err != nil {
return mariadbFailed, err
Expand All @@ -102,7 +105,7 @@ func reconcileMariaDB(
return mariadbReady, nil
}

helper.GetLogger().Info("Reconciling MariaDB", "MariaDB.Namespace", instance.Namespace, "Mariadb.Name", name)
l.Info("Reconciling MariaDB", "MariaDB.Namespace", instance.Namespace, "Mariadb.Name", name)
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), mariadb, func() error {
spec.DeepCopyInto(&mariadb.Spec)
if mariadb.Spec.Secret == "" {
Expand All @@ -123,7 +126,7 @@ func reconcileMariaDB(
return mariadbFailed, err
}
if op != controllerutil.OperationResultNone {
helper.GetLogger().Info(fmt.Sprintf("MariaDB %s - %s", mariadb.Name, op))
l.Info(fmt.Sprintf("MariaDB %s - %s", mariadb.Name, op))
}

if mariadb.IsReady() {
Expand Down
10 changes: 2 additions & 8 deletions pkg/openstack/rabbitmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
"github.com/openstack-k8s-operators/openstack-operator/controllers/core"
corev1 "k8s.io/api/core/v1"

"github.com/go-logr/logr"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log"
)

type mqStatus int
Expand All @@ -34,11 +33,6 @@ const (
mqReady mqStatus = iota
)

// GetLog returns a logger object with a prefix of "conroller.name" and aditional controller context fields
func GetLog(ctx context.Context) logr.Logger {
return log.FromContext(ctx).WithName("Controllers").WithName("OpenstackControlplane")
}

// ReconcileRabbitMQs -
func ReconcileRabbitMQs(
ctx context.Context,
Expand Down Expand Up @@ -104,7 +98,7 @@ func reconcileRabbitMQ(
},
}

l := GetLog(ctx)
l := core.GetLog(ctx)
l.Info("Reconciling RabbitMQ", "RabbitMQ.Namespace", instance.Namespace, "RabbitMQ.Name", name)
if !instance.Spec.Rabbitmq.Enabled {
if _, err := EnsureDeleted(ctx, helper, rabbitmq); err != nil {
Expand Down

0 comments on commit a164ffa

Please sign in to comment.