Skip to content

Commit

Permalink
Improve log message (#56)
Browse files Browse the repository at this point in the history
* improve logging

* cleanup makefile
  • Loading branch information
RalfHammer authored Jul 18, 2024
1 parent 0480ba7 commit 09db991
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 40 deletions.
8 changes: 4 additions & 4 deletions api/v1alpha1/clusterspace_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ webhook.Defaulter = &ClusterSpace{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (r *ClusterSpace) Default() {
clusterspacelog.Info("default", "name", r.Name)
clusterspacelog.V(2).Info("Default", "name", r.Name)

if r.Spec.Guid == "" && r.Spec.Name == "" {
r.Spec.Name = r.Name
Expand All @@ -43,7 +43,7 @@ var _ webhook.Validator = &ClusterSpace{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *ClusterSpace) ValidateCreate() (admission.Warnings, error) {
clusterspacelog.Info("validate create", "name", r.Name)
clusterspacelog.V(2).Info("Validate create", "name", r.Name)
// Call the defaulting logic again (because defaulting might be incomplete in case of generateName usage)
if r.Name == "" && r.GenerateName != "" {
r.Name = r.GenerateName + "xxxxx"
Expand All @@ -60,7 +60,7 @@ func (r *ClusterSpace) ValidateCreate() (admission.Warnings, error) {

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *ClusterSpace) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
clusterspacelog.Info("validate update", "name", r.Name)
clusterspacelog.V(2).Info("Validate update", "name", r.Name)
s := old.(*ClusterSpace)
// Call the defaulting webhook logic for the old object (because defaulting through the webhook might be incomplete in case of generateName usage)
s.Name = r.Name
Expand All @@ -84,7 +84,7 @@ func (r *ClusterSpace) ValidateUpdate(old runtime.Object) (admission.Warnings, e

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *ClusterSpace) ValidateDelete() (admission.Warnings, error) {
clusterspacelog.Info("validate delete", "name", r.Name)
clusterspacelog.V(2).Info("Validate delete", "name", r.Name)

return nil, nil
}
8 changes: 4 additions & 4 deletions api/v1alpha1/servicebinding_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ webhook.Defaulter = &ServiceBinding{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (r *ServiceBinding) Default() {
servicebindinglog.Info("default", "name", r.Name)
servicebindinglog.V(2).Info("Default", "name", r.Name)

if r.Labels == nil {
r.Labels = make(map[string]string)
Expand All @@ -51,14 +51,14 @@ var _ webhook.Validator = &ServiceBinding{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *ServiceBinding) ValidateCreate() (admission.Warnings, error) {
servicebindinglog.Info("validate create", "name", r.Name)
servicebindinglog.V(2).Info("Validate create", "name", r.Name)

return nil, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *ServiceBinding) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
servicebindinglog.Info("validate update", "name", r.Name)
servicebindinglog.V(2).Info("Validate update", "name", r.Name)
s := old.(*ServiceBinding)
// Call the defaulting webhook logic for the old object (because defaulting through the webhook might be incomplete in case of generateName usage)
s.Name = r.Name
Expand All @@ -78,7 +78,7 @@ func (r *ServiceBinding) ValidateUpdate(old runtime.Object) (admission.Warnings,

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *ServiceBinding) ValidateDelete() (admission.Warnings, error) {
servicebindinglog.Info("validate delete", "name", r.Name)
servicebindinglog.V(2).Info("Validate delete", "name", r.Name)

return nil, nil
}
8 changes: 4 additions & 4 deletions api/v1alpha1/serviceinstance_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ webhook.Defaulter = &ServiceInstance{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (r *ServiceInstance) Default() {
serviceinstancelog.Info("default", "name", r.Name)
serviceinstancelog.V(2).Info("Default", "name", r.Name)

if r.Labels == nil {
r.Labels = make(map[string]string)
Expand All @@ -53,7 +53,7 @@ var _ webhook.Validator = &ServiceInstance{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *ServiceInstance) ValidateCreate() (admission.Warnings, error) {
serviceinstancelog.Info("validate create", "name", r.Name)
serviceinstancelog.V(2).Info("Validate create", "name", r.Name)

if !(r.Spec.SpaceName != "" && r.Spec.ClusterSpaceName == "" ||
r.Spec.SpaceName == "" && r.Spec.ClusterSpaceName != "") {
Expand All @@ -70,7 +70,7 @@ func (r *ServiceInstance) ValidateCreate() (admission.Warnings, error) {

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *ServiceInstance) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
serviceinstancelog.Info("validate update", "name", r.Name)
serviceinstancelog.V(2).Info("Validate update", "name", r.Name)
s := old.(*ServiceInstance)
// Call the defaulting webhook logic for the old object (because defaulting through the webhook might be incomplete in case of generateName usage)
s.Name = r.Name
Expand Down Expand Up @@ -106,7 +106,7 @@ func (r *ServiceInstance) ValidateUpdate(old runtime.Object) (admission.Warnings

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *ServiceInstance) ValidateDelete() (admission.Warnings, error) {
serviceinstancelog.Info("validate delete", "name", r.Name)
serviceinstancelog.V(2).Info("Validate delete", "name", r.Name)

return nil, nil
}
8 changes: 4 additions & 4 deletions api/v1alpha1/space_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var _ webhook.Defaulter = &Space{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (r *Space) Default() {
spacelog.Info("default", "name", r.Name)
spacelog.V(2).Info("Default", "name", r.Name)

if r.Spec.Guid == "" && r.Spec.Name == "" {
r.Spec.Name = r.Name
Expand All @@ -43,7 +43,7 @@ var _ webhook.Validator = &Space{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *Space) ValidateCreate() (admission.Warnings, error) {
spacelog.Info("validate create", "name", r.Name)
spacelog.V(2).Info("Validate create", "name", r.Name)
// Call the defaulting logic again (because defaulting might be incomplete in case of generateName usage)
if r.Name == "" && r.GenerateName != "" {
r.Name = r.GenerateName + "xxxxx"
Expand All @@ -60,7 +60,7 @@ func (r *Space) ValidateCreate() (admission.Warnings, error) {

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *Space) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
spacelog.Info("validate update", "name", r.Name)
spacelog.V(2).Info("Validate update", "name", r.Name)
s := old.(*Space)
// Call the defaulting webhook logic for the old object (because defaulting through the webhook might be incomplete in case of generateName usage)
s.Name = r.Name
Expand All @@ -84,7 +84,7 @@ func (r *Space) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *Space) ValidateDelete() (admission.Warnings, error) {
spacelog.Info("validate delete", "name", r.Name)
spacelog.V(2).Info("Validate delete", "name", r.Name)

return nil, nil
}
18 changes: 10 additions & 8 deletions internal/controllers/servicebinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ type ServiceBindingReconciler struct {

func (r *ServiceBindingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error) {
log := ctrl.LoggerFrom(ctx)
log.V(1).Info("running reconcile")
log.V(2).Info("Running reconcile")

// Retrieve target service binding
serviceBinding := &cfv1alpha1.ServiceBinding{}
if err := r.Get(ctx, req.NamespacedName, serviceBinding); err != nil {
if err := client.IgnoreNotFound(err); err != nil {
return ctrl.Result{}, errors.Wrap(err, "unexpected get error")
}
log.Info("not found; ignoring")
log.V(1).Info("Not found; ignoring")
return ctrl.Result{}, nil
}
// Call the defaulting webhook logic also here (because defaulting through the webhook might be incomplete in case of generateName usage)
Expand Down Expand Up @@ -178,6 +178,7 @@ func (r *ServiceBindingReconciler) Reconcile(ctx context.Context, req ctrl.Reque
var cfbinding *facade.Binding
bindingOpts := map[string]string{"name": "", "owner": string(serviceBinding.UID)}
if client != nil {
log.V(1).Info("Retrieving binding by owner")
cfbinding, err = client.GetBinding(ctx, bindingOpts)
if err != nil {
return ctrl.Result{}, err
Expand All @@ -186,6 +187,7 @@ func (r *ServiceBindingReconciler) Reconcile(ctx context.Context, req ctrl.Reque
if exists && cfbinding == nil && orphan == "adopt" {
// find orphaned binding by name
bindingOpts["name"] = serviceBinding.Name
log.V(1).Info("Retrieving binding by name")
cfbinding, err = client.GetBinding(ctx, bindingOpts)
if err != nil {
return ctrl.Result{}, err
Expand All @@ -202,7 +204,7 @@ func (r *ServiceBindingReconciler) Reconcile(ctx context.Context, req ctrl.Reque
return ctrl.Result{}, errors.Wrap(err, "failed to unmarshal/merge parameters")
}
// update the orphaned cloud foundry service binding
log.V(1).Info("triggering update")
log.V(1).Info("Updating binding")
if err := client.UpdateBinding(
ctx,
cfbinding.Guid,
Expand Down Expand Up @@ -274,7 +276,7 @@ func (r *ServiceBindingReconciler) Reconcile(ctx context.Context, req ctrl.Reque
inRecreation := false

if cfbinding == nil {
log.V(1).Info("triggering creation")
log.V(1).Info("Creating binding")
if err := client.CreateBinding(
ctx,
spec.Name,
Expand All @@ -293,7 +295,7 @@ func (r *ServiceBindingReconciler) Reconcile(ctx context.Context, req ctrl.Reque
(recreateOnInstanceChange && status.ServiceInstanceDigest != serviceInstance.Status.ServiceInstanceDigest) ||
cfbinding.State == facade.BindingStateCreatedFailed || cfbinding.State == facade.BindingStateDeleteFailed {
// Re-create binding (unfortunately, cloud foundry does not support binding updates, other than metadata)
log.V(1).Info("triggering re-creation")
log.V(1).Info("Deleting binding for later re-creation")
if err := client.DeleteBinding(ctx, cfbinding.Guid); err != nil {
return ctrl.Result{}, err
}
Expand All @@ -303,8 +305,7 @@ func (r *ServiceBindingReconciler) Reconcile(ctx context.Context, req ctrl.Reque
cfbinding = nil
} else if cfbinding.Generation < serviceBinding.Generation {
// metadata updates (such as updating the generation here) are possible with service bindings
log.V(1).Info("triggering update")

log.V(1).Info("Updating binding")
if err := client.UpdateBinding(
ctx,
cfbinding.Guid,
Expand All @@ -323,6 +324,7 @@ func (r *ServiceBindingReconciler) Reconcile(ctx context.Context, req ctrl.Reque

if cfbinding == nil {
// Re-retrieve cloud foundry binding by UID; this happens exactly if the binding was created or updated above
log.V(1).Info("Retrieving binding")
cfbinding, err = client.GetBinding(ctx, bindingOpts)
if err != nil {
return ctrl.Result{}, err
Expand Down Expand Up @@ -399,7 +401,7 @@ func (r *ServiceBindingReconciler) Reconcile(ctx context.Context, req ctrl.Reque
return ctrl.Result{}, nil
} else {
if cfbinding.State != facade.BindingStateDeleting {
log.V(1).Info("triggering deletion")
log.V(1).Info("Deleting binding")
if err := client.DeleteBinding(ctx, cfbinding.Guid); err != nil {
return ctrl.Result{}, err
}
Expand Down
20 changes: 12 additions & 8 deletions internal/controllers/serviceinstance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ var RetryError = errors.New("retry")

func (r *ServiceInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error) {
log := ctrl.LoggerFrom(ctx)
log.V(1).Info("running reconcile")
log.V(2).Info("Running reconcile")

// Retrieve target service instance
serviceInstance := &cfv1alpha1.ServiceInstance{}
if err := r.Get(ctx, req.NamespacedName, serviceInstance); err != nil {
if err := client.IgnoreNotFound(err); err != nil {
return ctrl.Result{}, errors.Wrap(err, "unexpected get error")
}
log.Info("not found; ignoring")
log.V(1).Info("Not found; ignoring")
return ctrl.Result{}, nil
}
// Call the defaulting webhook logic also here (because defaulting through the webhook might be incomplete in case of generateName usage)
Expand Down Expand Up @@ -192,6 +192,7 @@ func (r *ServiceInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Requ
var cfinstance *facade.Instance
instanceOpts := map[string]string{"name": "", "owner": string(serviceInstance.UID)}
if client != nil {
log.V(1).Info("Retrieving instance by owner")
cfinstance, err = client.GetInstance(ctx, instanceOpts)
if err != nil {
return ctrl.Result{}, err
Expand All @@ -200,6 +201,7 @@ func (r *ServiceInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Requ
if exists && cfinstance == nil && orphan == "adopt" {
// find orphaned instance by name
instanceOpts["name"] = serviceInstance.Name
log.V(1).Info("Retrieving instance by name")
cfinstance, err = client.GetInstance(ctx, instanceOpts)
if err != nil {
return ctrl.Result{}, err
Expand All @@ -216,7 +218,7 @@ func (r *ServiceInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{}, errors.Wrap(err, "failed to unmarshal/merge parameters")
}
// update the orphaned cloud foundry instance
log.V(1).Info("triggering update")
log.V(1).Info("Updating instance")
if err := client.UpdateInstance(
ctx,
cfinstance.Guid,
Expand Down Expand Up @@ -246,6 +248,7 @@ func (r *ServiceInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Requ

servicePlanGuid := spec.ServicePlanGuid
if servicePlanGuid == "" {
log.V(1).Info("Searching service plan")
servicePlanGuid, err = client.FindServicePlan(ctx, spec.ServiceOfferingName, spec.ServicePlanName, spaceGuid)
if err != nil {
return ctrl.Result{}, err
Expand Down Expand Up @@ -291,7 +294,7 @@ func (r *ServiceInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Requ
inRecreation := false

if cfinstance == nil {
log.V(1).Info("triggering creation")
log.V(1).Info("Creating instance")
if err := client.CreateInstance(
ctx,
spec.Name,
Expand All @@ -309,7 +312,7 @@ func (r *ServiceInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Requ
// This is the re-creation case; nothing to, we just wait until it is gone
} else if recreateOnCreationFailure && (cfinstance.State == facade.InstanceStateCreatedFailed || cfinstance.State == facade.InstanceStateDeleteFailed) {
// Re-create instance
log.V(1).Info("triggering re-creation")
log.V(1).Info("Deleting instance for later re-creation")
if err := client.DeleteInstance(ctx, cfinstance.Guid); err != nil {
return ctrl.Result{}, RetryError
}
Expand All @@ -319,7 +322,7 @@ func (r *ServiceInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Requ
cfinstance = nil
} else if cfinstance.Generation < serviceInstance.Generation || cfinstance.ParameterHash != facade.ObjectHash(parameters) ||
cfinstance.State == facade.InstanceStateCreatedFailed || cfinstance.State == facade.InstanceStateUpdateFailed {
log.V(1).Info("triggering update")
log.V(1).Info("Updating instance")
updateName := spec.Name
if updateName == cfinstance.Name {
updateName = ""
Expand Down Expand Up @@ -362,6 +365,7 @@ func (r *ServiceInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Requ

if cfinstance == nil {
// Re-retrieve cloud foundry instance by UID; this happens exactly if the instance was created or updated above
log.V(1).Info("Retrieving instance")
cfinstance, err = client.GetInstance(ctx, instanceOpts)
if err != nil {
return ctrl.Result{}, err
Expand Down Expand Up @@ -418,7 +422,7 @@ func (r *ServiceInstanceReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{}, nil
} else {
if cfinstance.State != facade.InstanceStateDeleting {
log.V(1).Info("triggering deletion")
log.V(1).Info("Deleting instance")
if err := client.DeleteInstance(ctx, cfinstance.Guid); err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -476,7 +480,7 @@ func (r *ServiceInstanceReconciler) HandleError(ctx context.Context, serviceInst
requeueAfter = serviceInstanceDefaultMaxRetryInterval
}

log.V(1).Info("***Retry after interval", "RequeueAfter", requeueAfter.String())
log.V(1).Info("Scheduling next reconcile", "RequeueAfter", requeueAfter.String())

serviceInstance.SetReadyCondition(cfv1alpha1.ConditionUnknown, serviceInstanceReadyConditionReasonError, issue.Error())
return ctrl.Result{RequeueAfter: requeueAfter}, nil
Expand Down
Loading

0 comments on commit 09db991

Please sign in to comment.