Browse Source

chore: Cleanup flags (#5845)

Co-authored-by: Gergely Bräutigam <skarlso777@gmail.com>
Jean-Philippe Evrard 4 months ago
parent
commit
1483117fce
2 changed files with 25 additions and 28 deletions
  1. 1 12
      providers/v1/aws/auth/auth.go
  2. 24 16
      providers/v1/doppler/provider.go

+ 1 - 12
providers/v1/aws/auth/auth.go

@@ -29,7 +29,6 @@ import (
 	"github.com/aws/aws-sdk-go-v2/credentials/stscreds"
 	"github.com/aws/aws-sdk-go-v2/service/sts"
 	stsTypes "github.com/aws/aws-sdk-go-v2/service/sts/types"
-	"github.com/spf13/pflag"
 	v1 "k8s.io/api/core/v1"
 	"k8s.io/apimachinery/pkg/types"
 	"k8s.io/client-go/kubernetes"
@@ -40,7 +39,6 @@ import (
 	esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
 	awsutil "github.com/external-secrets/external-secrets/providers/v1/aws/util"
 	"github.com/external-secrets/external-secrets/runtime/esutils/resolvers"
-	"github.com/external-secrets/external-secrets/runtime/feature"
 )
 
 // Config contains configuration to create a new AWS provider.
@@ -51,8 +49,7 @@ type Config struct {
 }
 
 var (
-	log                = ctrl.Log.WithName("provider").WithName("aws")
-	enableSessionCache bool
+	log = ctrl.Log.WithName("provider").WithName("aws")
 )
 
 const (
@@ -65,14 +62,6 @@ const (
 	errFetchSTSecret   = "could not fetch SessionToken secret: %w"
 )
 
-func init() {
-	fs := pflag.NewFlagSet("aws-auth", pflag.ExitOnError)
-	fs.BoolVar(&enableSessionCache, "experimental-enable-aws-session-cache", false, "DEPRECATED: this flag is no longer used and will be removed since aws sdk v2 has its own session cache.")
-	feature.Register(feature.Feature{
-		Flags: fs,
-	})
-}
-
 // Opts define options for New function.
 type Opts struct {
 	Store       esv1.GenericStore

+ 24 - 16
providers/v1/doppler/provider.go

@@ -50,33 +50,41 @@ var _ esv1.SecretsClient = &Client{}
 var _ esv1.Provider = &Provider{}
 
 var (
+	enableCache      bool
 	oidcClientCache  *cache.Cache[esv1.SecretsClient]
 	defaultCacheSize = 2 << 17
 )
 
+func init() {
+	var dopplerOIDCCacheSize int
+	fs := pflag.NewFlagSet("doppler", pflag.ExitOnError)
+	fs.BoolVar(
+		&enableCache,
+		"experimental-enable-doppler-oidc-cache",
+		false,
+		"Enable experimental Doppler OIDC provider cache.",
+	)
+	fs.IntVar(
+		&dopplerOIDCCacheSize,
+		"experimental-doppler-oidc-cache-size",
+		defaultCacheSize,
+		"Maximum size of Doppler OIDC provider cache. Set to 0 to disable caching. Only used if --experimental-enable-doppler-oidc-cache is set.")
+
+	feature.Register(feature.Feature{
+		Flags:      fs,
+		Initialize: func() { initCache(dopplerOIDCCacheSize) },
+	})
+}
+
+// Gating on enableCache to not enable cache out of the blue for new releases.
 func initCache(cacheSize int) {
-	if oidcClientCache == nil && cacheSize > 0 {
+	if oidcClientCache == nil && cacheSize > 0 && enableCache {
 		oidcClientCache = cache.Must(cacheSize, func(_ esv1.SecretsClient) {
 			// No cleanup is needed when evicting OIDC clients from cache
 		})
 	}
 }
 
-// InitializeFlags registers Doppler-specific flags with the feature system.
-func InitializeFlags() *feature.Feature {
-	var dopplerOIDCCacheSize int
-	fs := pflag.NewFlagSet("doppler", pflag.ExitOnError)
-	fs.IntVar(&dopplerOIDCCacheSize, "doppler-oidc-cache-size", defaultCacheSize,
-		"Maximum size of Doppler OIDC provider cache. Set to 0 to disable caching.")
-
-	return &feature.Feature{
-		Flags: fs,
-		Initialize: func() {
-			initCache(dopplerOIDCCacheSize)
-		},
-	}
-}
-
 // Capabilities returns the provider's supported capabilities.
 func (p *Provider) Capabilities() esv1.SecretStoreCapabilities {
 	return esv1.SecretStoreReadOnly