Skip to content

Commit 5984c81

Browse files
authored
Merge pull request #989 from mac-chaffee/no-cache-secrets
Disable caching of secrets and configmaps
2 parents 9dc4271 + f84afcb commit 5984c81

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![report](https://goreportcard.com/badge/github.com/fluxcd/source-controller)](https://goreportcard.com/report/github.com/fluxcd/source-controller)
66
[![license](https://img.shields.io/github/license/fluxcd/source-controller.svg)](https://github.com/fluxcd/source-controller/blob/main/LICENSE)
77
[![release](https://img.shields.io/github/release/fluxcd/source-controller/all.svg)](https://github.com/fluxcd/source-controller/releases)
8-
8+
99
The source-controller is a Kubernetes operator, specialised in artifacts acquisition
1010
from external sources such as Git, Helm repositories and S3 buckets.
1111
The source-controller implements the
@@ -25,3 +25,5 @@ Features:
2525
* makes the artifacts available in-cluster to interested 3rd parties
2626
* notifies interested 3rd parties of source changes and availability (status conditions, events, hooks)
2727
* reacts to Git push and Helm chart upload events (via [notification-controller](https://github.com/fluxcd/notification-controller))
28+
29+
See [the docs folder](docs/spec/README.md) for more information.

internal/features/features.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,23 @@ const (
2929
// the last revision is still the same at the target repository,
3030
// and if that is so, skips the reconciliation.
3131
OptimizedGitClones = "OptimizedGitClones"
32+
// CacheSecretsAndConfigMaps controls whether secrets and configmaps should be cached.
33+
//
34+
// When enabled, it will cache both object types, resulting in increased memory usage
35+
// and cluster-wide RBAC permissions (list and watch).
36+
CacheSecretsAndConfigMaps = "CacheSecretsAndConfigMaps"
3237
)
3338

3439
var features = map[string]bool{
3540
// OptimizedGitClones
3641
// opt-out from v0.25
3742
OptimizedGitClones: true,
43+
// CacheSecretsAndConfigMaps
44+
// opt-in from v0.34
45+
CacheSecretsAndConfigMaps: false,
3846
}
3947

40-
// DefaultFeatureGates contains a list of all supported feature gates and
48+
// FeatureGates contains a list of all supported feature gates and
4149
// their default values.
4250
func FeatureGates() map[string]bool {
4351
return features

main.go

+13
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ import (
2727
"github.com/go-logr/logr"
2828
flag "github.com/spf13/pflag"
2929
"helm.sh/helm/v3/pkg/getter"
30+
corev1 "k8s.io/api/core/v1"
3031
"k8s.io/apimachinery/pkg/runtime"
3132
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3233
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3334
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
3435
ctrl "sigs.k8s.io/controller-runtime"
36+
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
3537

3638
"github.com/fluxcd/pkg/git"
3739
"github.com/fluxcd/pkg/runtime/client"
@@ -167,6 +169,16 @@ func main() {
167169
watchNamespace = os.Getenv("RUNTIME_NAMESPACE")
168170
}
169171

172+
disableCacheFor := []ctrlclient.Object{}
173+
shouldCache, err := features.Enabled(features.CacheSecretsAndConfigMaps)
174+
if err != nil {
175+
setupLog.Error(err, "unable to check feature gate "+features.CacheSecretsAndConfigMaps)
176+
os.Exit(1)
177+
}
178+
if !shouldCache {
179+
disableCacheFor = append(disableCacheFor, &corev1.Secret{}, &corev1.ConfigMap{})
180+
}
181+
170182
restConfig := client.GetConfigOrDie(clientOptions)
171183
mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
172184
Scheme: scheme,
@@ -181,6 +193,7 @@ func main() {
181193
LeaderElectionID: fmt.Sprintf("%s-leader-election", controllerName),
182194
Namespace: watchNamespace,
183195
Logger: ctrl.Log,
196+
ClientDisableCacheFor: disableCacheFor,
184197
})
185198
if err != nil {
186199
setupLog.Error(err, "unable to start manager")

0 commit comments

Comments
 (0)