Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set watch option #2822

Closed
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/set-cache-watch-option.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
component: collector

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Adds a label selector to the operator's informer cache to only select resources with the label selector

# One or more tracking issues related to the change
issues: [2822]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
23 changes: 21 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ import (
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"github.com/spf13/pflag"
colfeaturegate "go.opentelemetry.io/collector/featuregate"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/batch/v1"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/labels"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/kubernetes"
Expand All @@ -38,6 +41,7 @@ import (
k8sapiflag "k8s.io/component-base/cli/flag"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -273,9 +277,24 @@ func main() {
Port: webhookPort,
TLSOpts: optionsTlSOptsFuncs,
}),
Cache: cache.Options{
}

if featuregate.EnableCacheOptions.IsEnabled() {
mgrOptions.Cache = cache.Options{
DefaultNamespaces: namespaces,
},
DefaultLabelSelector: labels.SelectorFromSet(map[string]string{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the docs from the operator-sdk but they're out of date after this release kubernetes-sigs/controller-runtime#2300. This is the best way going forward!

"app.kubernetes.io/managed-by": "opentelemetry-operator",
}),
ByObject: map[client.Object]cache.ByObject{
&otelv1alpha1.OpenTelemetryCollector{}: {},
&otelv1alpha1.OpAMPBridge{}: {},
&otelv1alpha1.Instrumentation{}: {},
&v1.Job{}: {},
&appsv1.Deployment{}: {},
&appsv1.DaemonSet{}: {},
&appsv1.StatefulSet{}: {},
Copy link
Contributor

@swiatekm swiatekm Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need ReplicaSet and CronJob here as well. Or maybe just Job, ReplicaSet and DaemonSet (the immediate Pod owners) are sufficient? Both are probably worth testing.

},
}
}

mgr, err := ctrl.NewManager(restConfig, mgrOptions)
Expand Down
8 changes: 8 additions & 0 deletions pkg/featuregate/featuregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ var (
featuregate.WithRegisterDescription("enables features associated to the Prometheus Operator"),
featuregate.WithRegisterFromVersion("v0.82.0"),
)

// EnableCacheOptions is the feature gate that sets a cache label selector to improve operator performance.
EnableCacheOptions = featuregate.GlobalRegistry().MustRegister(
"operator.cache.selector",
featuregate.StageBeta, // TODO: this is temporary and will be reverted prior to an e2e run
featuregate.WithRegisterDescription("enables the operator's cache to only select a subset of objects"),
featuregate.WithRegisterFromVersion("v0.98.0"),
)
)

// Flags creates a new FlagSet that represents the available featuregate flags using the supplied featuregate registry.
Expand Down
Loading