-
Notifications
You must be signed in to change notification settings - Fork 27
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 #169 from pinikomarov/structured_logging
switch to structured logging
- Loading branch information
Showing
4 changed files
with
86 additions
and
55 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
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 |
---|---|---|
|
@@ -49,16 +49,21 @@ import ( | |
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
) | ||
|
||
// OctaviaReconciler reconciles an Octavia object | ||
type OctaviaReconciler struct { | ||
client.Client | ||
Kclient kubernetes.Interface | ||
Log logr.Logger | ||
Scheme *runtime.Scheme | ||
} | ||
|
||
// GetLogger returns a logger object with a prefix of "controller.name" and additional controller context fields | ||
func (r *OctaviaReconciler) GetLogger(ctx context.Context) logr.Logger { | ||
return log.FromContext(ctx).WithName("Controllers").WithName("Octavia") | ||
} | ||
|
||
// +kubebuilder:rbac:groups=octavia.openstack.org,resources=octavias,verbs=get;list;watch;create;update;patch;delete | ||
// +kubebuilder:rbac:groups=octavia.openstack.org,resources=octavias/status,verbs=get;update;patch | ||
// +kubebuilder:rbac:groups=octavia.openstack.org,resources=octavias/finalizers,verbs=update | ||
|
@@ -96,7 +101,7 @@ type OctaviaReconciler struct { | |
// For more details, check Reconcile and its Result here: | ||
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile | ||
func (r *OctaviaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) { | ||
_ = r.Log.WithValues("octavia", req.NamespacedName) | ||
Log := r.GetLogger(ctx) | ||
|
||
// Fetch the Octavia instance | ||
instance := &octaviav1.Octavia{} | ||
|
@@ -117,7 +122,7 @@ func (r *OctaviaReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re | |
r.Client, | ||
r.Kclient, | ||
r.Scheme, | ||
r.Log, | ||
Log, | ||
) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
|
@@ -200,6 +205,7 @@ func (r *OctaviaReconciler) SetupWithManager(mgr ctrl.Manager) error { | |
} | ||
|
||
func (r *OctaviaReconciler) reconcileDelete(ctx context.Context, instance *octaviav1.Octavia, helper *helper.Helper) (ctrl.Result, error) { | ||
Log := r.GetLogger(ctx) | ||
util.LogForObject(helper, "Reconciling Service delete", instance) | ||
|
||
// remove db finalizer first | ||
|
@@ -217,7 +223,7 @@ func (r *OctaviaReconciler) reconcileDelete(ctx context.Context, instance *octav | |
// We did all the cleanup on the objects we created so we can remove the | ||
// finalizer from ourselves to allow the deletion | ||
controllerutil.RemoveFinalizer(instance, helper.GetFinalizer()) | ||
r.Log.Info(fmt.Sprintf("Reconciled Service '%s' delete successfully", instance.Name)) | ||
Log.Info(fmt.Sprintf("Reconciled Service '%s' delete successfully", instance.Name)) | ||
|
||
util.LogForObject(helper, "Reconciled Service delete successfully", instance) | ||
return ctrl.Result{}, nil | ||
|
@@ -230,7 +236,8 @@ func (r *OctaviaReconciler) reconcileInit( | |
serviceLabels map[string]string, | ||
serviceAnnotations map[string]string, | ||
) (ctrl.Result, error) { | ||
r.Log.Info("Reconciling Service init") | ||
Log := r.GetLogger(ctx) | ||
Log.Info("Reconciling Service init") | ||
|
||
// | ||
// create service DB instance | ||
|
@@ -296,7 +303,7 @@ func (r *OctaviaReconciler) reconcileInit( | |
// | ||
dbSyncHash := instance.Status.Hash[octaviav1.DbSyncHash] | ||
jobDef := octavia.DbSyncJob(instance, serviceLabels, serviceAnnotations) | ||
r.Log.Info("Initializing db sync job") | ||
Log.Info("Initializing db sync job") | ||
dbSyncjob := job.NewJob( | ||
jobDef, | ||
octaviav1.DbSyncHash, | ||
|
@@ -332,33 +339,36 @@ func (r *OctaviaReconciler) reconcileInit( | |
|
||
// run octavia db sync - end | ||
|
||
r.Log.Info("Reconciled Service init successfully") | ||
Log.Info("Reconciled Service init successfully") | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
func (r *OctaviaReconciler) reconcileUpdate(ctx context.Context, instance *octaviav1.Octavia, helper *helper.Helper) (ctrl.Result, error) { | ||
r.Log.Info("Reconciling Service update") | ||
Log := r.GetLogger(ctx) | ||
Log.Info("Reconciling Service update") | ||
|
||
// TODO: should have minor update tasks if required | ||
// - delete dbsync hash from status to rerun it? | ||
|
||
r.Log.Info("Reconciled Service update successfully") | ||
Log.Info("Reconciled Service update successfully") | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
func (r *OctaviaReconciler) reconcileUpgrade(ctx context.Context, instance *octaviav1.Octavia, helper *helper.Helper) (ctrl.Result, error) { | ||
r.Log.Info("Reconciling Service upgrade") | ||
Log := r.GetLogger(ctx) | ||
Log.Info("Reconciling Service upgrade") | ||
|
||
// TODO: should have major version upgrade tasks | ||
// -delete dbsync hash from status to rerun it? | ||
|
||
r.Log.Info("Reconciled Service upgrade successfully") | ||
Log.Info("Reconciled Service upgrade successfully") | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
// TODO(tweining): implement | ||
func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octaviav1.Octavia, helper *helper.Helper) (ctrl.Result, error) { | ||
r.Log.Info("Reconciling Service") | ||
Log := r.GetLogger(ctx) | ||
Log.Info("Reconciling Service") | ||
|
||
// Service account, role, binding | ||
rbacRules := []rbacv1.PolicyRule{ | ||
|
@@ -395,13 +405,13 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav | |
} | ||
|
||
if op != controllerutil.OperationResultNone { | ||
r.Log.Info(fmt.Sprintf("TransportURL %s successfully reconciled - operation: %s", transportURL.Name, string(op))) | ||
Log.Info(fmt.Sprintf("TransportURL %s successfully reconciled - operation: %s", transportURL.Name, string(op))) | ||
} | ||
|
||
instance.Status.TransportURLSecret = transportURL.Status.SecretName | ||
|
||
if instance.Status.TransportURLSecret == "" { | ||
r.Log.Info(fmt.Sprintf("Waiting for the TransportURL %s secret to be created", transportURL.Name)) | ||
Log.Info(fmt.Sprintf("Waiting for the TransportURL %s secret to be created", transportURL.Name)) | ||
instance.Status.Conditions.Set(condition.FalseCondition( | ||
condition.InputReadyCondition, | ||
condition.RequestedReason, | ||
|
@@ -550,7 +560,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav | |
return ctrlResult, nil | ||
} | ||
|
||
r.Log.Info(fmt.Sprintf("Calling for deploy for API with %s", instance.Status.DatabaseHostname)) | ||
Log.Info(fmt.Sprintf("Calling for deploy for API with %s", instance.Status.DatabaseHostname)) | ||
|
||
// TODO(beagles): look into adding condition types/messages in a common file | ||
octaviaAPI, op, err := r.apiDeploymentCreateOrUpdate(instance) | ||
|
@@ -564,7 +574,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav | |
return ctrl.Result{}, err | ||
} | ||
if op != controllerutil.OperationResultNone { | ||
r.Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", instance.Name, string(op))) | ||
Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", instance.Name, string(op))) | ||
} | ||
|
||
// Mirror OctaviaAPI status' ReadyCount to this parent CR | ||
|
@@ -590,7 +600,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav | |
} | ||
|
||
if op != controllerutil.OperationResultNone { | ||
r.Log.Info(fmt.Sprintf("Deployment of OctaviaHousekeeping for %s successfully reconciled - operation: %s", instance.Name, string(op))) | ||
Log.Info(fmt.Sprintf("Deployment of OctaviaHousekeeping for %s successfully reconciled - operation: %s", instance.Name, string(op))) | ||
} | ||
|
||
instance.Status.OctaviaHousekeepingReadyCount = octaviaHousekeeping.Status.ReadyCount | ||
|
@@ -613,7 +623,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav | |
} | ||
|
||
if op != controllerutil.OperationResultNone { | ||
r.Log.Info(fmt.Sprintf("Deployment of OctaviaHealthManager for %s successfully reconciled - operation: %s", instance.Name, string(op))) | ||
Log.Info(fmt.Sprintf("Deployment of OctaviaHealthManager for %s successfully reconciled - operation: %s", instance.Name, string(op))) | ||
} | ||
|
||
instance.Status.OctaviaHealthManagerReadyCount = octaviaHealthManager.Status.ReadyCount | ||
|
@@ -636,7 +646,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav | |
} | ||
|
||
if op != controllerutil.OperationResultNone { | ||
r.Log.Info(fmt.Sprintf("Deployment of OctaviaWorker for %s successfully reconciled - operation: %s", instance.Name, string(op))) | ||
Log.Info(fmt.Sprintf("Deployment of OctaviaWorker for %s successfully reconciled - operation: %s", instance.Name, string(op))) | ||
} | ||
|
||
instance.Status.OctaviaWorkerReadyCount = octaviaWorker.Status.ReadyCount | ||
|
@@ -649,7 +659,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav | |
|
||
// create Deployment - end | ||
|
||
r.Log.Info("Reconciled Service successfully") | ||
Log.Info("Reconciled Service successfully") | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
|
@@ -720,6 +730,7 @@ func (r *OctaviaReconciler) createHashOfInputHashes( | |
instance *octaviav1.Octavia, | ||
envVars map[string]env.Setter, | ||
) (string, bool, error) { | ||
Log := r.GetLogger(ctx) | ||
var hashMap map[string]string | ||
changed := false | ||
mergedMapVars := env.MergeEnvs([]corev1.EnvVar{}, envVars) | ||
|
@@ -729,7 +740,7 @@ func (r *OctaviaReconciler) createHashOfInputHashes( | |
} | ||
if hashMap, changed = util.SetHash(instance.Status.Hash, common.InputHashName, hash); changed { | ||
instance.Status.Hash = hashMap | ||
r.Log.Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash)) | ||
Log.Info(fmt.Sprintf("Input maps hash %s - %s", common.InputHashName, hash)) | ||
} | ||
return hash, changed, nil | ||
} | ||
|
Oops, something went wrong.