Skip to content

Commit fd49ea7

Browse files
committed
FF
1 parent aaa14fb commit fd49ea7

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

main.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
2929
"github.com/spf13/pflag"
3030
colfeaturegate "go.opentelemetry.io/collector/featuregate"
31+
appsv1 "k8s.io/api/apps/v1"
32+
v1 "k8s.io/api/batch/v1"
3133
networkingv1 "k8s.io/api/networking/v1"
3234
"k8s.io/apimachinery/pkg/labels"
3335
k8sruntime "k8s.io/apimachinery/pkg/runtime"
@@ -39,6 +41,7 @@ import (
3941
k8sapiflag "k8s.io/component-base/cli/flag"
4042
ctrl "sigs.k8s.io/controller-runtime"
4143
"sigs.k8s.io/controller-runtime/pkg/cache"
44+
"sigs.k8s.io/controller-runtime/pkg/client"
4245
"sigs.k8s.io/controller-runtime/pkg/healthz"
4346
"sigs.k8s.io/controller-runtime/pkg/log/zap"
4447
"sigs.k8s.io/controller-runtime/pkg/manager"
@@ -274,12 +277,24 @@ func main() {
274277
Port: webhookPort,
275278
TLSOpts: optionsTlSOptsFuncs,
276279
}),
277-
Cache: cache.Options{
280+
}
281+
282+
if featuregate.EnableCacheOptions.IsEnabled() {
283+
mgrOptions.Cache = cache.Options{
278284
DefaultNamespaces: namespaces,
279285
DefaultLabelSelector: labels.SelectorFromSet(map[string]string{
280286
"app.kubernetes.io/managed-by": "opentelemetry-operator",
281287
}),
282-
},
288+
ByObject: map[client.Object]cache.ByObject{
289+
&otelv1alpha1.OpenTelemetryCollector{}: {},
290+
&otelv1alpha1.OpAMPBridge{}: {},
291+
&otelv1alpha1.Instrumentation{}: {},
292+
&v1.Job{}: {},
293+
&appsv1.Deployment{}: {},
294+
&appsv1.DaemonSet{}: {},
295+
&appsv1.StatefulSet{}: {},
296+
},
297+
}
283298
}
284299

285300
mgr, err := ctrl.NewManager(restConfig, mgrOptions)

pkg/featuregate/featuregate.go

+8
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ var (
6060
featuregate.WithRegisterDescription("enables features associated to the Prometheus Operator"),
6161
featuregate.WithRegisterFromVersion("v0.82.0"),
6262
)
63+
64+
// EnableCacheOptions is the feature gate that sets a cache label selector to improve operator performance.
65+
EnableCacheOptions = featuregate.GlobalRegistry().MustRegister(
66+
"operator.cache.selector",
67+
featuregate.StageBeta, // TODO: this is temporary and will be reverted prior to an e2e run
68+
featuregate.WithRegisterDescription("enables the operator's cache to only select a subset of objects"),
69+
featuregate.WithRegisterFromVersion("v0.98.0"),
70+
)
6371
)
6472

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

0 commit comments

Comments
 (0)