Merge pull request #989 from mac-chaffee/no-cache-secrets
Disable caching of secrets and configmaps
This commit is contained in:
commit
5984c8182d
|
@ -25,3 +25,5 @@ Features:
|
||||||
* makes the artifacts available in-cluster to interested 3rd parties
|
* makes the artifacts available in-cluster to interested 3rd parties
|
||||||
* notifies interested 3rd parties of source changes and availability (status conditions, events, hooks)
|
* notifies interested 3rd parties of source changes and availability (status conditions, events, hooks)
|
||||||
* reacts to Git push and Helm chart upload events (via [notification-controller](https://github.com/fluxcd/notification-controller))
|
* reacts to Git push and Helm chart upload events (via [notification-controller](https://github.com/fluxcd/notification-controller))
|
||||||
|
|
||||||
|
See [the docs folder](docs/spec/README.md) for more information.
|
||||||
|
|
|
@ -29,15 +29,23 @@ const (
|
||||||
// the last revision is still the same at the target repository,
|
// the last revision is still the same at the target repository,
|
||||||
// and if that is so, skips the reconciliation.
|
// and if that is so, skips the reconciliation.
|
||||||
OptimizedGitClones = "OptimizedGitClones"
|
OptimizedGitClones = "OptimizedGitClones"
|
||||||
|
// CacheSecretsAndConfigMaps controls whether secrets and configmaps should be cached.
|
||||||
|
//
|
||||||
|
// When enabled, it will cache both object types, resulting in increased memory usage
|
||||||
|
// and cluster-wide RBAC permissions (list and watch).
|
||||||
|
CacheSecretsAndConfigMaps = "CacheSecretsAndConfigMaps"
|
||||||
)
|
)
|
||||||
|
|
||||||
var features = map[string]bool{
|
var features = map[string]bool{
|
||||||
// OptimizedGitClones
|
// OptimizedGitClones
|
||||||
// opt-out from v0.25
|
// opt-out from v0.25
|
||||||
OptimizedGitClones: true,
|
OptimizedGitClones: true,
|
||||||
|
// CacheSecretsAndConfigMaps
|
||||||
|
// opt-in from v0.34
|
||||||
|
CacheSecretsAndConfigMaps: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultFeatureGates contains a list of all supported feature gates and
|
// FeatureGates contains a list of all supported feature gates and
|
||||||
// their default values.
|
// their default values.
|
||||||
func FeatureGates() map[string]bool {
|
func FeatureGates() map[string]bool {
|
||||||
return features
|
return features
|
||||||
|
|
13
main.go
13
main.go
|
@ -27,11 +27,13 @@ import (
|
||||||
"github.com/go-logr/logr"
|
"github.com/go-logr/logr"
|
||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
"helm.sh/helm/v3/pkg/getter"
|
"helm.sh/helm/v3/pkg/getter"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
||||||
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
|
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
|
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
|
|
||||||
"github.com/fluxcd/pkg/git"
|
"github.com/fluxcd/pkg/git"
|
||||||
"github.com/fluxcd/pkg/runtime/client"
|
"github.com/fluxcd/pkg/runtime/client"
|
||||||
|
@ -167,6 +169,16 @@ func main() {
|
||||||
watchNamespace = os.Getenv("RUNTIME_NAMESPACE")
|
watchNamespace = os.Getenv("RUNTIME_NAMESPACE")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disableCacheFor := []ctrlclient.Object{}
|
||||||
|
shouldCache, err := features.Enabled(features.CacheSecretsAndConfigMaps)
|
||||||
|
if err != nil {
|
||||||
|
setupLog.Error(err, "unable to check feature gate "+features.CacheSecretsAndConfigMaps)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if !shouldCache {
|
||||||
|
disableCacheFor = append(disableCacheFor, &corev1.Secret{}, &corev1.ConfigMap{})
|
||||||
|
}
|
||||||
|
|
||||||
restConfig := client.GetConfigOrDie(clientOptions)
|
restConfig := client.GetConfigOrDie(clientOptions)
|
||||||
mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
|
mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
|
||||||
Scheme: scheme,
|
Scheme: scheme,
|
||||||
|
@ -181,6 +193,7 @@ func main() {
|
||||||
LeaderElectionID: fmt.Sprintf("%s-leader-election", controllerName),
|
LeaderElectionID: fmt.Sprintf("%s-leader-election", controllerName),
|
||||||
Namespace: watchNamespace,
|
Namespace: watchNamespace,
|
||||||
Logger: ctrl.Log,
|
Logger: ctrl.Log,
|
||||||
|
ClientDisableCacheFor: disableCacheFor,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
setupLog.Error(err, "unable to start manager")
|
setupLog.Error(err, "unable to start manager")
|
||||||
|
|
Loading…
Reference in New Issue