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 1 commit
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
19 changes: 17 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ 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"
Expand All @@ -39,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 @@ -274,12 +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