Skip to content

Commit 7e8d77c

Browse files
controller: add more logging to labelling
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
1 parent 91b5762 commit 7e8d77c

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

pkg/controller/operators/catalog/operator.go

+3
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
399399
idx = 0
400400
complete[gvr] = []bool{false}
401401
}
402+
logger := op.logger.WithFields(logrus.Fields{"gvr": gvr.String(), "index": idx})
403+
logger.Info("registering labeller")
402404

403405
queue := workqueue.NewRateLimitingQueueWithConfig(workqueue.DefaultControllerRateLimiter(), workqueue.RateLimitingQueueConfig{
404406
Name: gvr.String(),
@@ -415,6 +417,7 @@ func NewOperator(ctx context.Context, kubeconfigPath string, clock utilclock.Clo
415417
// when every action we know about has been completed, we re-start the process to allow the future
416418
// invocation of this process to filter informers (canFilter = true) and elide all this logic
417419
completeLock.Lock()
420+
logger.Info("labeller complete")
418421
complete[gvr][idx] = true
419422
allDone := true
420423
for _, items := range complete {

pkg/controller/operators/labeller/labels.go

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func ObjectLabeler[T metav1.Object, A ApplyConfig[A]](
7878
return nil
7979
}
8080

81+
logger.WithFields(logrus.Fields{"namespace": cast.GetNamespace(), "name": cast.GetName()}).Info("applying ownership label")
8182
cfg := applyConfigFor(cast.GetName(), cast.GetNamespace())
8283
cfg.WithLabels(map[string]string{
8384
install.OLMManagedLabelKey: install.OLMManagedLabelValue,
@@ -159,6 +160,7 @@ func ObjectPatchLabeler(
159160
return fmt.Errorf("failed to Marshal old data for %s/%s: %w", updated.GetNamespace(), updated.GetName(), err)
160161
}
161162

163+
logger.WithFields(logrus.Fields{"namespace": cast.GetNamespace(), "name": cast.GetName()}).Info("patching ownership label")
162164
patchBytes, err := jsonpatch.CreateMergePatch(oldData, newData)
163165
if err != nil {
164166
return fmt.Errorf("failed to create patch for %s/%s: %w", cast.GetNamespace(), cast.GetName(), err)

pkg/controller/operators/labeller/rbac.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/operator-framework/api/pkg/operators/v1alpha1"
98
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver"
10-
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
119
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/queueinformer"
1210
"github.com/sirupsen/logrus"
1311
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -37,7 +35,7 @@ func ContentHashLabeler[T metav1.Object, A ApplyConfig[A]](
3735
return fmt.Errorf("casting failed: %w", err)
3836
}
3937

40-
if _, _, ok := ownerutil.GetOwnerByKindLabel(cast, v1alpha1.ClusterServiceVersionKind); !ok {
38+
if !check(cast) || hasHashLabel(cast) {
4139
// if the object we're processing does not need us to label it, it's possible that every object that requires
4240
// the label already has it; in which case we should exit the process, so the Pod that succeeds us can filter
4341
// the informers used to drive the controller and stop having to track extraneous objects
@@ -60,15 +58,12 @@ func ContentHashLabeler[T metav1.Object, A ApplyConfig[A]](
6058
return nil
6159
}
6260

63-
if !check(cast) || hasHashLabel(cast) {
64-
return nil
65-
}
66-
6761
hash, err := hasher(cast)
6862
if err != nil {
6963
return fmt.Errorf("failed to calculate hash: %w", err)
7064
}
7165

66+
logger.WithFields(logrus.Fields{"namespace": cast.GetNamespace(), "name": cast.GetName()}).Info("applying content hash label")
7267
cfg := applyConfigFor(cast.GetName(), cast.GetNamespace())
7368
cfg.WithLabels(map[string]string{
7469
resolver.ContentHashLabelKey: hash,

pkg/controller/operators/olm/operator.go

+4
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
515515
idx = 0
516516
complete[gvr] = []bool{false}
517517
}
518+
logger := op.logger.WithFields(logrus.Fields{"gvr": gvr.String(), "index": idx})
519+
logger.Info("registering labeller")
520+
518521
queue := workqueue.NewRateLimitingQueueWithConfig(workqueue.DefaultControllerRateLimiter(), workqueue.RateLimitingQueueConfig{
519522
Name: gvr.String(),
520523
})
@@ -530,6 +533,7 @@ func newOperatorWithConfig(ctx context.Context, config *operatorConfig) (*Operat
530533
// when every action we know about has been completed, we re-start the process to allow the future
531534
// invocation of this process to filter informers (canFilter = true) and elide all this logic
532535
completeLock.Lock()
536+
logger.Info("labeller complete")
533537
complete[gvr][idx] = true
534538
allDone := true
535539
for _, items := range complete {

0 commit comments

Comments
 (0)