Skip to content

Commit

Permalink
update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
pinikomarov committed Sep 16, 2023
1 parent f0bc157 commit 5c9afe7
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions controllers/heatapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (r *HeatAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
r.Client,
r.Kclient,
r.Scheme,
l,
log,
)
if err != nil {
return ctrl.Result{}, err
Expand Down Expand Up @@ -196,7 +196,7 @@ func (r *HeatAPIReconciler) SetupWithManager(mgr ctrl.Manager, ctx context.Conte
client.InNamespace(o.GetNamespace()),
}
if err := r.Client.List(context.Background(), apis, listOpts...); err != nil {
l.Error(err, "Unable to get API CRs")
log.Error(err, "Unable to get API CRs")
return nil
}

Expand All @@ -209,7 +209,7 @@ func (r *HeatAPIReconciler) SetupWithManager(mgr ctrl.Manager, ctx context.Conte
Namespace: o.GetNamespace(),
Name: cr.Name,
}
l.Info("", "ConfigMap object", o.GetName(), "and CR", cr.Name, "marked with label:", lbl)
log.Info("", "ConfigMap object", o.GetName(), "and CR", cr.Name, "marked with label:", lbl)
result = append(result, reconcile.Request{NamespacedName: name})
}
}
Expand All @@ -236,7 +236,7 @@ func (r *HeatAPIReconciler) SetupWithManager(mgr ctrl.Manager, ctx context.Conte

func (r *HeatAPIReconciler) reconcileDelete(ctx context.Context, instance *heatv1beta1.HeatAPI, helper *helper.Helper) (ctrl.Result, error) {
log := GetLog(ctx, "HeatAPI")
l.Info("Reconciling API Delete")
log.Info("Reconciling API Delete")

for _, ksSvc := range keystoneServices {
keystoneEndpoint, err := keystonev1.GetKeystoneEndpointWithName(ctx, helper, ksSvc["name"], instance.Namespace)
Expand All @@ -248,7 +248,7 @@ func (r *HeatAPIReconciler) reconcileDelete(ctx context.Context, instance *heatv
if err = helper.GetClient().Update(ctx, keystoneEndpoint); err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
l.Info("Removed finalizer from KeystoneEndpoint", "KeystoneEndpoint", instance)
log.Info("Removed finalizer from KeystoneEndpoint", "KeystoneEndpoint", instance)
}

keystoneService, err := keystonev1.GetKeystoneServiceWithName(ctx, helper, ksSvc["name"], instance.Namespace)
Expand All @@ -260,13 +260,13 @@ func (r *HeatAPIReconciler) reconcileDelete(ctx context.Context, instance *heatv
if err = helper.GetClient().Update(ctx, keystoneService); err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
l.Info("Removed finalizer from our KeystoneService", "KeystoneService", instance)
log.Info("Removed finalizer from our KeystoneService", "KeystoneService", instance)
}
}

// Service is deleted so remove the finalizer.
controllerutil.RemoveFinalizer(instance, helper.GetFinalizer())
l.Info("Reconciled API delete successfully")
log.Info("Reconciled API delete successfully")

return ctrl.Result{}, nil
}
Expand All @@ -278,7 +278,7 @@ func (r *HeatAPIReconciler) reconcileInit(
serviceLabels map[string]string,
) (ctrl.Result, error) {
log := GetLog(ctx, "HeatAPI")
l.Info("Reconciling API init")
log.Info("Reconciling API init")

//
// expose the service (create service, route and return the created endpoint URLs)
Expand Down Expand Up @@ -385,13 +385,13 @@ func (r *HeatAPIReconciler) reconcileInit(
}
}

l.Info("Reconciled API init successfully")
log.Info("Reconciled API init successfully")
return ctrl.Result{}, nil
}

func (r *HeatAPIReconciler) reconcileNormal(ctx context.Context, instance *heatv1beta1.HeatAPI, helper *helper.Helper) (ctrl.Result, error) {
log := GetLog(ctx, "HeatAPI")
l.Info("Reconciling Service")
log.Info("Reconciling Service")

// ConfigMap
configMapVars := make(map[string]env.Setter)
Expand Down Expand Up @@ -575,29 +575,29 @@ func (r *HeatAPIReconciler) reconcileNormal(ctx context.Context, instance *heatv
}
// create Deployment - end

l.Info("Reconciled API successfully")
log.Info("Reconciled API successfully")
return ctrl.Result{}, nil
}

func (r *HeatAPIReconciler) reconcileUpdate(ctx context.Context, instance *heatv1beta1.HeatAPI, helper *helper.Helper) (ctrl.Result, error) {
log := GetLog(ctx, "HeatAPI")
l.Info("Reconciling API update")
log.Info("Reconciling API update")

// TODO: should have minor update tasks if required
// - delete dbsync hash from status to rerun it?

l.Info("Reconciled API update successfully")
log.Info("Reconciled API update successfully")
return ctrl.Result{}, nil
}

func (r *HeatAPIReconciler) reconcileUpgrade(ctx context.Context, instance *heatv1beta1.HeatAPI, helper *helper.Helper) (ctrl.Result, error) {
log := GetLog(ctx, "HeatAPI")
l.Info("Reconciling API upgrade")
log.Info("Reconciling API upgrade")

// TODO: should have major version upgrade tasks
// -delete dbsync hash from status to rerun it?

l.Info("Reconciled API upgrade successfully")
log.Info("Reconciled API upgrade successfully")
return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -649,6 +649,8 @@ func (r *HeatAPIReconciler) createHashOfInputHashes(
instance *heatv1beta1.HeatAPI,
envVars map[string]env.Setter,
) (string, error) {
log := GetLog(ctx, "HeatAPI")

mergedMapVars := env.MergeEnvs([]corev1.EnvVar{}, envVars)
hash, err := util.ObjectHash(mergedMapVars)
if err != nil {
Expand All @@ -659,7 +661,7 @@ func (r *HeatAPIReconciler) createHashOfInputHashes(
if err := r.Client.Status().Update(ctx, instance); err != nil {
return hash, err
}
GetLog(ctx).Info("Input maps", common.InputHashName, "hash", hash)
log.Info("Input maps", common.InputHashName, "hash", hash)
}
return hash, nil
}

0 comments on commit 5c9afe7

Please sign in to comment.