Skip to content

Commit

Permalink
use package level logger GetLog
Browse files Browse the repository at this point in the history
  • Loading branch information
pinikomarov committed Jul 4, 2023
1 parent 95a9728 commit 26297ef
Show file tree
Hide file tree
Showing 21 changed files with 43 additions and 46 deletions.
5 changes: 0 additions & 5 deletions controllers/core/openstackcontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ 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) {

l := GetLog(ctx)
Expand Down
6 changes: 4 additions & 2 deletions pkg/openstack/ceilometer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func ReconcileCeilometer(ctx context.Context, instance *corev1beta1.OpenStackCon
},
}

l := GetLog(ctx)

if !instance.Spec.Ceilometer.Enabled {
if res, err := EnsureDeleted(ctx, helper, ceilometer); err != nil {
return res, err
Expand All @@ -38,7 +40,7 @@ func ReconcileCeilometer(ctx context.Context, instance *corev1beta1.OpenStackCon
return ctrl.Result{}, nil
}

helper.GetLogger().Info("Reconciling Ceilometer", ceilometerNamespaceLabel, instance.Namespace, ceilometerNameLabel, ceilometerName)
l.Info("Reconciling Ceilometer", ceilometerNamespaceLabel, instance.Namespace, ceilometerNameLabel, ceilometerName)
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), ceilometer, func() error {
instance.Spec.Ceilometer.Template.DeepCopyInto(&ceilometer.Spec)

Expand All @@ -63,7 +65,7 @@ func ReconcileCeilometer(ctx context.Context, instance *corev1beta1.OpenStackCon
return ctrl.Result{}, err
}
if op != controllerutil.OperationResultNone {
helper.GetLogger().Info(fmt.Sprintf("%s %s - %s", ceilometerName, ceilometer.Name, op))
l.Info(fmt.Sprintf("%s %s - %s", ceilometerName, ceilometer.Name, op))
}

if ceilometer.IsReady() {
Expand Down
3 changes: 1 addition & 2 deletions pkg/openstack/cinder.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

cinderv1 "github.com/openstack-k8s-operators/cinder-operator/api/v1beta1"
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 All @@ -32,7 +31,7 @@ func ReconcileCinder(ctx context.Context, instance *corev1beta1.OpenStackControl
instance.Status.Conditions.Remove(corev1beta1.OpenStackControlPlaneCinderReadyCondition)
return ctrl.Result{}, nil
}
l := core.GetLog(ctx)
l := GetLog(ctx)

l.Info("Reconciling Cinder", "Cinder.Namespace", instance.Namespace, "Cinder.Name", "cinder")
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), cinder, func() error {
Expand Down
7 changes: 7 additions & 0 deletions pkg/openstack/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ package openstack
import (
"context"

"github.com/go-logr/logr"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
)

// 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")
}

// EnsureDeleted - Delete the object which in turn will clean the sub resources
func EnsureDeleted(ctx context.Context, helper *helper.Helper, obj client.Object) (ctrl.Result, error) {
key := client.ObjectKeyFromObject(obj)
Expand Down
6 changes: 4 additions & 2 deletions pkg/openstack/dnsmasq.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ func ReconcileDNSMasqs(ctx context.Context, instance *corev1beta1.OpenStackContr
return ctrl.Result{}, nil
}

helper.GetLogger().Info("Reconciling DNSMasq", "DNSMasq.Namespace", instance.Namespace, "DNSMasq.Name", "dnsmasq")
l := GetLog(ctx)

l.Info("Reconciling DNSMasq", "DNSMasq.Namespace", instance.Namespace, "DNSMasq.Name", "dnsmasq")
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), dnsmasq, func() error {
instance.Spec.DNS.Template.DeepCopyInto(&dnsmasq.Spec)
if dnsmasq.Spec.NodeSelector == nil && instance.Spec.NodeSelector != nil {
Expand All @@ -56,7 +58,7 @@ func ReconcileDNSMasqs(ctx context.Context, instance *corev1beta1.OpenStackContr
return ctrl.Result{}, err
}
if op != controllerutil.OperationResultNone {
helper.GetLogger().Info(fmt.Sprintf("dnsmasq %s - %s", dnsmasq.Name, op))
l.Info(fmt.Sprintf("dnsmasq %s - %s", dnsmasq.Name, op))
}

if dnsmasq.IsReady() {
Expand Down
3 changes: 1 addition & 2 deletions pkg/openstack/galera.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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,7 +93,7 @@ func reconcileGalera(
Namespace: instance.Namespace,
},
}
l := core.GetLog(ctx)
l := GetLog(ctx)

if !instance.Spec.Galera.Enabled {
if _, err := EnsureDeleted(ctx, helper, galera); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/openstack/glance.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

glancev1 "github.com/openstack-k8s-operators/glance-operator/api/v1beta1"
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 All @@ -25,7 +24,7 @@ func ReconcileGlance(ctx context.Context, instance *corev1beta1.OpenStackControl
},
}

l := core.GetLog(ctx)
l := GetLog(ctx)

if !instance.Spec.Glance.Enabled {
if res, err := EnsureDeleted(ctx, helper, glance); err != nil {
Expand Down
7 changes: 5 additions & 2 deletions pkg/openstack/heat.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ func ReconcileHeat(ctx context.Context, instance *corev1beta1.OpenStackControlPl
instance.Status.Conditions.Remove(corev1beta1.OpenStackControlPlaneHeatReadyCondition)
return ctrl.Result{}, nil
}
helper.GetLogger().Info("Reconcile heat", "heat.Namespace", instance.Namespace, "heat.Name", "heat")

l := GetLog(ctx)

l.Info("Reconcile heat", "heat.Namespace", instance.Namespace, "heat.Name", "heat")
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), heat, func() error {
instance.Spec.Heat.Template.DeepCopyInto(&heat.Spec)
err := controllerutil.SetControllerReference(helper.GetBeforeObject(), heat, helper.GetScheme())
Expand All @@ -51,7 +54,7 @@ func ReconcileHeat(ctx context.Context, instance *corev1beta1.OpenStackControlPl
return ctrl.Result{}, err
}
if op != controllerutil.OperationResultNone {
helper.GetLogger().Info(fmt.Sprintf("heat %s - %s", heat.Name, op))
l.Info(fmt.Sprintf("heat %s - %s", heat.Name, op))
}

if heat.IsReady() {
Expand Down
3 changes: 1 addition & 2 deletions pkg/openstack/horizon.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

horizonv1 "github.com/openstack-k8s-operators/horizon-operator/api/v1beta1"
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 All @@ -24,7 +23,7 @@ func ReconcileHorizon(ctx context.Context, instance *corev1beta1.OpenStackContro
Namespace: instance.Namespace,
},
}
l := core.GetLog(ctx)
l := GetLog(ctx)

if !instance.Spec.Horizon.Enabled {
if res, err := EnsureDeleted(ctx, helper, horizon); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/openstack/ironic.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

ironicv1 "github.com/openstack-k8s-operators/ironic-operator/api/v1beta1"
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 All @@ -24,7 +23,7 @@ func ReconcileIronic(ctx context.Context, instance *corev1beta1.OpenStackControl
Namespace: instance.Namespace,
},
}
l := core.GetLog(ctx)
l := GetLog(ctx)

if !instance.Spec.Ironic.Enabled {
if res, err := EnsureDeleted(ctx, helper, ironic); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/openstack/keystone.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
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 All @@ -25,7 +24,7 @@ func ReconcileKeystoneAPI(ctx context.Context, instance *corev1beta1.OpenStackCo
},
}

l := core.GetLog(ctx)
l := GetLog(ctx)

if !instance.Spec.Keystone.Enabled {
if res, err := EnsureDeleted(ctx, helper, keystoneAPI); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/openstack/manila.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

manilav1 "github.com/openstack-k8s-operators/manila-operator/api/v1beta1"
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 All @@ -24,7 +23,7 @@ func ReconcileManila(ctx context.Context, instance *corev1beta1.OpenStackControl
Namespace: instance.Namespace,
},
}
l := core.GetLog(ctx)
l := GetLog(ctx)

if !instance.Spec.Manila.Enabled {
if res, err := EnsureDeleted(ctx, helper, manila); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/openstack/mariadb.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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 @@ -95,7 +94,7 @@ func reconcileMariaDB(
},
}

l := core.GetLog(ctx)
l := GetLog(ctx)

if !instance.Spec.Mariadb.Enabled {
if _, err := EnsureDeleted(ctx, helper, mariadb); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/openstack/memcached.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -139,7 +138,7 @@ func reconcileMemcached(
},
}

l := core.GetLog(ctx)
l := GetLog(ctx)

if !instance.Spec.Memcached.Enabled {
if _, err := EnsureDeleted(ctx, helper, memcached); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/openstack/neutron.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

neutronv1 "github.com/openstack-k8s-operators/neutron-operator/api/v1beta1"
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 All @@ -24,7 +23,7 @@ func ReconcileNeutron(ctx context.Context, instance *corev1beta1.OpenStackContro
Namespace: instance.Namespace,
},
}
l := core.GetLog(ctx)
l := GetLog(ctx)

if !instance.Spec.Neutron.Enabled {
if res, err := EnsureDeleted(ctx, helper, neutronAPI); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions pkg/openstack/nova.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ import (

"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"

"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

novav1 "github.com/openstack-k8s-operators/nova-operator/api/v1beta1"
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 All @@ -40,7 +38,7 @@ func ReconcileNova(ctx context.Context, instance *corev1beta1.OpenStackControlPl
Namespace: instance.Namespace,
},
}
l := core.GetLog(ctx)
l := GetLog(ctx)

if !instance.Spec.Nova.Enabled {
if res, err := EnsureDeleted(ctx, helper, nova); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/openstack/openstackclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
"github.com/openstack-k8s-operators/openstack-operator/controllers/core"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -44,7 +43,7 @@ func ReconcileOpenStackClient(ctx context.Context, instance *corev1beta1.OpenSta
Namespace: instance.Namespace,
},
}
l := core.GetLog(ctx)
l := GetLog(ctx)

l.Info("Reconciling OpenStackClient", "OpenStackClient.Namespace", instance.Namespace, "OpenStackClient.Name", openstackclient.Name)
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), openstackclient, func() error {
Expand Down
9 changes: 5 additions & 4 deletions pkg/openstack/ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ 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"
ovnv1 "github.com/openstack-k8s-operators/ovn-operator/api/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
)

// ReconcileOVN -
func ReconcileOVN(ctx context.Context, instance *corev1beta1.OpenStackControlPlane, helper *helper.Helper) (ctrl.Result, error) {

l := GetLog(ctx)

OVNDBClustersReady := len(instance.Spec.Ovn.Template.OVNDBCluster) != 0
for name, dbcluster := range instance.Spec.Ovn.Template.OVNDBCluster {
OVNDBCluster := &ovnv1.OVNDBCluster{
Expand All @@ -26,7 +28,6 @@ func ReconcileOVN(ctx context.Context, instance *corev1beta1.OpenStackControlPla
Namespace: instance.Namespace,
},
}
l := core.GetLog(ctx)

if !instance.Spec.Ovn.Enabled {
if res, err := EnsureDeleted(ctx, helper, OVNDBCluster); err != nil {
Expand Down Expand Up @@ -129,7 +130,7 @@ func ReconcileOVN(ctx context.Context, instance *corev1beta1.OpenStackControlPla
return ctrl.Result{}, nil
}

helper.GetLogger().Info("Reconciling OVNController", "OVNController.Namespace", instance.Namespace, "OVNController.Name", "ovncontroller")
l.Info("Reconciling OVNController", "OVNController.Namespace", instance.Namespace, "OVNController.Name", "ovncontroller")
op, err = controllerutil.CreateOrPatch(ctx, helper.GetClient(), OVNController, func() error {

instance.Spec.Ovn.Template.OVNController.DeepCopyInto(&OVNController.Spec)
Expand All @@ -155,7 +156,7 @@ func ReconcileOVN(ctx context.Context, instance *corev1beta1.OpenStackControlPla
return ctrl.Result{}, err
}
if op != controllerutil.OperationResultNone {
helper.GetLogger().Info(fmt.Sprintf("OVNController %s - %s", OVNController.Name, op))
l.Info(fmt.Sprintf("OVNController %s - %s", OVNController.Name, op))
}

// Expect all services (dbclusters, northd, ovn-controller) ready
Expand Down
3 changes: 1 addition & 2 deletions pkg/openstack/placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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"
placementv1 "github.com/openstack-k8s-operators/placement-operator/api/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -24,7 +23,7 @@ func ReconcilePlacementAPI(ctx context.Context, instance *corev1beta1.OpenStackC
Namespace: instance.Namespace,
},
}
l := core.GetLog(ctx)
l := GetLog(ctx)

if !instance.Spec.Placement.Enabled {
if res, err := EnsureDeleted(ctx, helper, placementAPI); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/openstack/rabbitmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ 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"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -98,7 +97,7 @@ func reconcileRabbitMQ(
},
}

l := core.GetLog(ctx)
l := 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
Loading

0 comments on commit 26297ef

Please sign in to comment.