Skip to content

Commit 6901401

Browse files
authored
Update manager verbosity level to 2 and add debug logging for reconciliation events (#1146) (#1153)
Signed-off-by: Daniel Fan <[email protected]>
1 parent 8e3c41b commit 6901401

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

controllers/operandrequest/operandrequest_controller.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
8686
return ctrl.Result{}, client.IgnoreNotFound(err)
8787
}
8888

89+
klog.V(2).Infof("DEBUG: Starting reconciliation for OperandRequest: %s/%s", req.Namespace, req.Name)
8990
originalInstance := requestInstance.DeepCopy()
9091

9192
// Always attempt to patch the status after each reconciliation.
@@ -270,6 +271,7 @@ func (r *Reconciler) checkFinalizer(ctx context.Context, requestInstance *operat
270271
func (r *Reconciler) getRegistryToRequestMapper() handler.MapFunc {
271272
ctx := context.Background()
272273
return func(object client.Object) []ctrl.Request {
274+
klog.V(2).Infof("DEBUG: OperandRequest reconciliation triggered by OperandRegistry: %s/%s", object.GetNamespace(), object.GetName())
273275
requestList, _ := r.ListOperandRequestsByRegistry(ctx, types.NamespacedName{Namespace: object.GetNamespace(), Name: object.GetName()})
274276

275277
requests := []ctrl.Request{}
@@ -284,6 +286,7 @@ func (r *Reconciler) getRegistryToRequestMapper() handler.MapFunc {
284286

285287
func (r *Reconciler) getSubToRequestMapper() handler.MapFunc {
286288
return func(object client.Object) []ctrl.Request {
289+
klog.V(2).Infof("DEBUG: OperandRequest reconciliation triggered by Subscription: %s/%s", object.GetNamespace(), object.GetName())
287290
reg, _ := regexp.Compile(`^(.*)\.(.*)\.(.*)\/request`)
288291
annotations := object.GetAnnotations()
289292
var reqName, reqNamespace string
@@ -309,6 +312,7 @@ func (r *Reconciler) getSubToRequestMapper() handler.MapFunc {
309312
func (r *Reconciler) getConfigToRequestMapper() handler.MapFunc {
310313
ctx := context.Background()
311314
return func(object client.Object) []ctrl.Request {
315+
klog.V(2).Infof("DEBUG: OperandRequest reconciliation triggered by OperandConfig: %s/%s", object.GetNamespace(), object.GetName())
312316
requestList, _ := r.ListOperandRequestsByConfig(ctx, types.NamespacedName{Namespace: object.GetNamespace(), Name: object.GetName()})
313317

314318
requests := []ctrl.Request{}
@@ -324,6 +328,7 @@ func (r *Reconciler) getConfigToRequestMapper() handler.MapFunc {
324328
func (r *Reconciler) getReferenceToRequestMapper() handler.MapFunc {
325329
ctx := context.Background()
326330
return func(object client.Object) []ctrl.Request {
331+
klog.V(2).Infof("DEBUG: OperandRequest reconciliation potentially triggered by referenced object: %s/%s", object.GetNamespace(), object.GetName())
327332
annotations := object.GetAnnotations()
328333
if annotations == nil {
329334
return []ctrl.Request{}
@@ -364,34 +369,44 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
364369
ReferencePredicates := predicate.Funcs{
365370
CreateFunc: func(e event.CreateEvent) bool {
366371
labels := e.Object.GetLabels()
372+
result := false
367373
// only return true when both conditions are met at the same time:
368374
// 1. label contain key "constant.ODLMWatchedLabel" and value is true
369375
// 2. label does not contain key "constant.OpbiTypeLabel" with value "copy"
370376
if labels != nil {
371377
if labelValue, ok := labels[constant.ODLMWatchedLabel]; ok && labelValue == "true" {
372378
if labelValue, ok := labels[constant.OpbiTypeLabel]; ok && labelValue == "copy" {
373-
return false
379+
result = false
380+
} else {
381+
result = true
374382
}
375-
return true
376383
}
377384
}
378-
return false
385+
if result {
386+
klog.V(2).Infof("DEBUG: ReferencePredicates CreateFunc passed for: %s/%s", e.Object.GetNamespace(), e.Object.GetName())
387+
}
388+
return result
379389
},
380390
UpdateFunc: func(e event.UpdateEvent) bool {
381391
// If the object is not updated except the ODLMWatchedLabel label or ODLMReferenceAnnotation annotation, return false
382392
if !r.ObjectIsUpdatedWithException(&e.ObjectOld, &e.ObjectNew) {
383393
return false
384394
}
385395
labels := e.ObjectNew.GetLabels()
396+
result := false
386397
if labels != nil {
387398
if labelValue, ok := labels[constant.ODLMWatchedLabel]; ok && labelValue == "true" {
388399
if labelValue, ok := labels[constant.OpbiTypeLabel]; ok && labelValue == "copy" {
389-
return false
400+
result = false
401+
} else {
402+
result = true
390403
}
391-
return true
392404
}
393405
}
394-
return false
406+
if result {
407+
klog.V(2).Infof("DEBUG: ReferencePredicates UpdateFunc passed for: %s/%s", e.ObjectNew.GetNamespace(), e.ObjectNew.GetName())
408+
}
409+
return result
395410
},
396411
DeleteFunc: func(e event.DeleteEvent) bool {
397412
return true

0 commit comments

Comments
 (0)