Skip to content

Commit cb4622b

Browse files
committed
kstatus: allow disabling of caching cluster reader
This commit allows the disabling of the caching cluster reader used by the status poller while waiting and/or checking the health of resources. Potentially reducing the memory usage of the controller on large scale clusters, at the cost of an increase in direct API calls. The feature can be enabled using `--feature-gates=DisableStatusPollerCache=true`. Signed-off-by: Hidde Beydals <hidde@hhh.computer>
1 parent 11f5fbb commit cb4622b

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

internal/features/features.go

+11
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,23 @@ const (
2727
// When enabled, it will cache both object types, resulting in increased
2828
// memory usage and cluster-wide RBAC permissions (list and watch).
2929
CacheSecretsAndConfigMaps = "CacheSecretsAndConfigMaps"
30+
31+
// DisableStatusPollerCache controls whether the status polling cache
32+
// should be disabled.
33+
//
34+
// This may be useful when the controller is running in a cluster with a
35+
// large number of resources, as it will potentially reduce the amount of
36+
// memory used by the controller.
37+
DisableStatusPollerCache = "DisableStatusPollerCache"
3038
)
3139

3240
var features = map[string]bool{
3341
// CacheSecretsAndConfigMaps
3442
// opt-in from v0.33
3543
CacheSecretsAndConfigMaps: false,
44+
// DisableStatusPollerCache
45+
// opt-in from v0.35
46+
DisableStatusPollerCache: false,
3647
}
3748

3849
// FeatureGates contains a list of all supported feature gates and

main.go

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
_ "k8s.io/client-go/plugin/pkg/client/auth/azure"
2929
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
3030
"sigs.k8s.io/cli-utils/pkg/kstatus/polling"
31+
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/clusterreader"
3132
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/engine"
3233
ctrl "sigs.k8s.io/controller-runtime"
3334
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
@@ -165,6 +166,9 @@ func main() {
165166
pollingOpts := polling.Options{
166167
CustomStatusReaders: []engine.StatusReader{jobStatusReader},
167168
}
169+
if ok, _ := features.Enabled(features.DisableStatusPollerCache); ok {
170+
pollingOpts.ClusterReaderFactory = engine.ClusterReaderFactoryFunc(clusterreader.NewDirectClusterReader)
171+
}
168172
if err = (&controllers.KustomizationReconciler{
169173
ControllerName: controllerName,
170174
DefaultServiceAccount: defaultServiceAccount,

0 commit comments

Comments
 (0)