Skip to content

Commit

Permalink
Introduced feature gate for etcd druid and added 'UseEtcdWrapper' fea…
Browse files Browse the repository at this point in the history
…ture gate
  • Loading branch information
aaronfern committed Jul 19, 2023
1 parent 95e07f8 commit 1e7a80f
Show file tree
Hide file tree
Showing 19 changed files with 230 additions and 128 deletions.
11 changes: 0 additions & 11 deletions charts/images-copy.yaml

This file was deleted.

8 changes: 4 additions & 4 deletions charts/images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ images:
name: 'etcdbrctl'
sourceRepository: github.com/gardener/etcd-backup-restore
repository: eu.gcr.io/gardener-project/gardener/etcdbrctl
tag: "v0.25.0"
tag: "v0.24.2"
- name: etcd
sourceRepository: github.com/gardener/etcd-wrapper
repository: eu.gcr.io/gardener-project/gardener/etcd-wrapper
tag: "v0.1.0"
sourceRepository: github.com/gardener/etcd-custom-image
repository: aaronfernandes/etcd-custom
tag: "bootstrap-entrypoint-1"
16 changes: 15 additions & 1 deletion controllers/compaction/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@
package compaction

import (
"flag"
"time"

"github.com/gardener/etcd-druid/controllers/utils"
"github.com/gardener/etcd-druid/pkg/features"
flag "github.com/spf13/pflag"
"k8s.io/component-base/featuregate"
)

// relevantFeatures holds the feature flag names that are relevant for the Compaction Controller.
var relevantFeatures = []featuregate.Feature{
features.UseEtcdWrapper,
}

const (
enableBackupCompactionFlagName = "enable-backup-compaction"
workersFlagName = "compaction-workers"
Expand All @@ -43,6 +50,8 @@ type Config struct {
EventsThreshold int64
// ActiveDeadlineDuration is the duration after which a running compaction job will be killed.
ActiveDeadlineDuration time.Duration
// FeatureGates contains the feature flags to be used by Compaction Controller.
FeatureGates map[string]bool
}

// InitFromFlags initializes the compaction controller config from the provided CLI flag set.
Expand Down Expand Up @@ -70,3 +79,8 @@ func (cfg *Config) Validate() error {
}
return nil
}

// GetRelevantFeatures returns feature gates relevant to the Compaction controller
func (cfg *Config) GetRelevantFeatures() []featuregate.Feature {
return relevantFeatures
}
3 changes: 2 additions & 1 deletion controllers/compaction/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

druidv1alpha1 "github.com/gardener/etcd-druid/api/v1alpha1"
ctrlutils "github.com/gardener/etcd-druid/controllers/utils"
"github.com/gardener/etcd-druid/pkg/features"
druidmetrics "github.com/gardener/etcd-druid/pkg/metrics"
"github.com/gardener/etcd-druid/pkg/utils"
"github.com/gardener/gardener/pkg/utils/imagevector"
Expand Down Expand Up @@ -56,7 +57,7 @@ type Reconciler struct {

// NewReconciler creates a new reconciler for Compaction
func NewReconciler(mgr manager.Manager, config *Config) (*Reconciler, error) {
imageVector, err := ctrlutils.CreateImageVector()
imageVector, err := ctrlutils.CreateImageVector(config.FeatureGates[string(features.UseEtcdWrapper)])
if err != nil {
return nil, err
}
Expand Down
65 changes: 51 additions & 14 deletions controllers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package controllers

import (
"flag"
"fmt"

"github.com/gardener/etcd-druid/pkg/features"
flag "github.com/spf13/pflag"
"k8s.io/component-base/featuregate"

"github.com/gardener/etcd-druid/controllers/compaction"
Expand Down Expand Up @@ -63,8 +65,8 @@ type ManagerConfig struct {
DisableLeaseCache bool
// IgnoreOperationAnnotation specifies whether to ignore or honour the operation annotation on resources to be reconciled.
IgnoreOperationAnnotation bool
// FeatureFlags contains the feature flags to be used by etcd-druid.
FeatureFlags map[string]bool
// FeatureFlags contains the feature gates to be used by etcd-druid.
FeatureFlags featuregate.MutableFeatureGate
// EtcdControllerConfig is the configuration required for etcd controller.
EtcdControllerConfig *etcd.Config
// CustodianControllerConfig is the configuration required for custodian controller.
Expand All @@ -78,7 +80,7 @@ type ManagerConfig struct {
}

// InitFromFlags initializes the controller manager config from the provided CLI flag set.
func InitFromFlags(fs *flag.FlagSet, cfg *ManagerConfig) {
func InitFromFlags(fs *flag.FlagSet, cfg *ManagerConfig) error {
flag.StringVar(&cfg.MetricsAddr, metricsAddrFlagName, defaultMetricsAddr, ""+
"The address the metric endpoint binds to.")
flag.BoolVar(&cfg.EnableLeaderElection, enableLeaderElectionFlagName, defaultEnableLeaderElection,
Expand All @@ -92,8 +94,9 @@ func InitFromFlags(fs *flag.FlagSet, cfg *ManagerConfig) {
flag.BoolVar(&cfg.IgnoreOperationAnnotation, ignoreOperationAnnotationFlagName, defaultIgnoreOperationAnnotation,
"Specifies whether to ignore or honour the operation annotation on resources to be reconciled.")

cfg.FeatureFlags = features.GetDefaultFeatureFlags()
InitFeatureFlags(fs, cfg.FeatureFlags)
if err := InitFeatureGates(fs, &cfg.FeatureFlags); err != nil {
return err
}

cfg.EtcdControllerConfig = &etcd.Config{}
etcd.InitFromFlags(fs, cfg.EtcdControllerConfig)
Expand All @@ -109,19 +112,53 @@ func InitFromFlags(fs *flag.FlagSet, cfg *ManagerConfig) {

cfg.SecretControllerConfig = &secret.Config{}
secret.InitFromFlags(fs, cfg.SecretControllerConfig)

return nil
}

// InitFeatureFlags initializes the features flags from the provided CLI flag set.
// TODO: passing by value and not by reference, will this work?
func InitFeatureFlags(fs *flag.FlagSet, featureFlags map[string]bool) {
for feature, value := range featureFlags {
fs.BoolVar(&value, feature, value, features.FeatureDescriptions[featuregate.Feature(feature)])
// InitFeatureGates initializes feature gates from the provided CLI flag set.
func InitFeatureGates(fs *flag.FlagSet, featureFlags *featuregate.MutableFeatureGate) error {
*featureFlags = featuregate.NewFeatureGate()
if err := (*featureFlags).Add(features.GetDefaultFeatures()); err != nil {
return fmt.Errorf("error adding features to the featuregate: %v", err)
}
(*featureFlags).AddFlag(fs)

return nil
}

// PopulateControllerFeatureFlags
// TODO: opt1
func PopulateControllerFeatureFlags() {
// PopulateControllerFeatureFlags adds relevant feature gates to every controller configuration
func PopulateControllerFeatureGates(config *ManagerConfig) {

// Add etcd controller feature flags
config.EtcdControllerConfig.FeatureGates = make(map[string]bool)
for _, feature := range config.EtcdControllerConfig.GetRelevantFeatures() {
config.EtcdControllerConfig.FeatureGates[string(feature)] = config.FeatureFlags.Enabled(feature)
}

// Add custodian controller feature flags
config.CustodianControllerConfig.FeatureGates = make(map[string]bool)
for _, feature := range config.CustodianControllerConfig.GetRelevantFeatures() {
config.CustodianControllerConfig.FeatureGates[string(feature)] = config.FeatureFlags.Enabled(feature)
}

// Add compaction controller feature flags
config.CompactionControllerConfig.FeatureGates = make(map[string]bool)
for _, feature := range config.CompactionControllerConfig.GetRelevantFeatures() {
config.CompactionControllerConfig.FeatureGates[string(feature)] = config.FeatureFlags.Enabled(feature)
}

// Add etcdcopybackuptask controller feature flags
config.EtcdCopyBackupsTaskControllerConfig.FeatureGates = make(map[string]bool)
for _, feature := range config.EtcdCopyBackupsTaskControllerConfig.GetRelevantFeatures() {
config.EtcdCopyBackupsTaskControllerConfig.FeatureGates[string(feature)] = config.FeatureFlags.Enabled(feature)
}

// Add secret controller feature flags
config.SecretControllerConfig.FeatureGates = make(map[string]bool)
for _, feature := range config.SecretControllerConfig.GetRelevantFeatures() {
config.SecretControllerConfig.FeatureGates[string(feature)] = config.FeatureFlags.Enabled(feature)
}

}

Expand Down
13 changes: 12 additions & 1 deletion controllers/custodian/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
package custodian

import (
"flag"
"time"

"github.com/gardener/etcd-druid/controllers/utils"
flag "github.com/spf13/pflag"
"k8s.io/component-base/featuregate"
)

// relevantFeatures holds the feature flag names that are relevant for the Custodian Controller.
var relevantFeatures = []featuregate.Feature{}

const (
workersFlagName = "custodian-workers"
syncPeriodFlagName = "custodian-sync-period"
Expand All @@ -41,6 +45,8 @@ type Config struct {
SyncPeriod time.Duration
// EtcdMember holds configuration related to etcd members.
EtcdMember EtcdMemberConfig
// FeatureGates contains the feature flags to be used by Custodian Controller.
FeatureGates map[string]bool
}

// EtcdMemberConfig holds configuration related to etcd members.
Expand Down Expand Up @@ -79,3 +85,8 @@ func (cfg *Config) Validate() error {
}
return nil
}

// GetRelevantFeatures returns feature gates relevant to the Custodian controller
func (cfg *Config) GetRelevantFeatures() []featuregate.Feature {
return relevantFeatures
}
21 changes: 12 additions & 9 deletions controllers/etcd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
package etcd

import (
"flag"
flag "github.com/spf13/pflag"
"k8s.io/component-base/featuregate"

"github.com/gardener/etcd-druid/controllers/utils"
"github.com/gardener/etcd-druid/pkg/features"
Expand All @@ -29,11 +30,9 @@ const (
defaultDisableEtcdServiceAccountAutomount = false
)

// RelevantFeatures holds the feature flag names that are relevant for the Etcd Controller.
// TODO: come up with better name for this variable
// TODO: write getter method on Config struct for this var
var RelevantFeatures = []string{
string(features.UseEtcdWrapper),
// relevantFeatures holds the feature flag names that are relevant for the Etcd Controller.
var relevantFeatures = []featuregate.Feature{
features.UseEtcdWrapper,
}

// Config defines the configuration for the Etcd Controller.
Expand All @@ -42,9 +41,8 @@ type Config struct {
Workers int
// DisableEtcdServiceAccountAutomount controls the auto-mounting of service account token for etcd statefulsets.
DisableEtcdServiceAccountAutomount bool
// FeatureFlags contains the feature flags to be used by Etcd Controller.
// TODO: set this from managerConfig (filtered using RelevantFeatures) before running the reconciler
FeatureFlags map[string]bool
// FeatureGates contains the feature flags to be used by Etcd Controller.
FeatureGates map[string]bool
}

// InitFromFlags initializes the config from the provided CLI flag set.
Expand All @@ -62,3 +60,8 @@ func (cfg *Config) Validate() error {
}
return nil
}

// GetRelevantFeatures returns feature gates relevant to the Etcd controller
func (cfg *Config) GetRelevantFeatures() []featuregate.Feature {
return relevantFeatures
}
10 changes: 7 additions & 3 deletions controllers/etcd/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
componentservice "github.com/gardener/etcd-druid/pkg/component/etcd/service"
componentserviceaccount "github.com/gardener/etcd-druid/pkg/component/etcd/serviceaccount"
componentsts "github.com/gardener/etcd-druid/pkg/component/etcd/statefulset"
"github.com/gardener/etcd-druid/pkg/features"
druidutils "github.com/gardener/etcd-druid/pkg/utils"

v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
Expand Down Expand Up @@ -76,7 +77,7 @@ type Reconciler struct {

// NewReconciler creates a new reconciler for Etcd.
func NewReconciler(mgr manager.Manager, config *Config) (*Reconciler, error) {
imageVector, err := utils.CreateImageVector()
imageVector, err := utils.CreateImageVector(config.FeatureGates[string(features.UseEtcdWrapper)])
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -367,15 +368,18 @@ func (r *Reconciler) reconcileEtcd(ctx context.Context, logger logr.Logger, etcd
}

peerUrlTLSChangedToEnabled := isPeerTLSChangedToEnabled(peerTLSEnabled, configMapValues)
statefulSetValues := componentsts.GenerateValues(etcd,
statefulSetValues := componentsts.GenerateValues(
etcd,
&serviceValues.ClientPort,
&serviceValues.PeerPort,
&serviceValues.BackupPort,
*etcdImage,
*etcdBackupImage,
map[string]string{
"checksum/etcd-configmap": configMapValues.ConfigMapChecksum,
}, peerUrlTLSChangedToEnabled)
}, peerUrlTLSChangedToEnabled,
r.config.FeatureGates[string(features.UseEtcdWrapper)],
)

// Create an OpWaiter because after the deployment we want to wait until the StatefulSet is ready.
var (
Expand Down
17 changes: 15 additions & 2 deletions controllers/etcdcopybackupstask/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
package etcdcopybackupstask

import (
"flag"

"github.com/gardener/etcd-druid/controllers/utils"
"github.com/gardener/etcd-druid/pkg/features"
flag "github.com/spf13/pflag"
"k8s.io/component-base/featuregate"
)

// relevantFeatures holds the feature flag names that are relevant for the EtcdCopyBackupTask Controller.
var relevantFeatures = []featuregate.Feature{
features.UseEtcdWrapper,
}

const (
workersFlagName = "etcd-copy-backups-task-workers"

Expand All @@ -30,6 +36,8 @@ const (
type Config struct {
// Workers is the number of workers concurrently processing reconciliation requests.
Workers int
// FeatureGates contains the feature flags to be used by EtcdCopyBackupTask Controller.
FeatureGates map[string]bool
}

// InitFromFlags initializes the config from the provided CLI flag set.
Expand All @@ -45,3 +53,8 @@ func (cfg *Config) Validate() error {
}
return nil
}

// GetRelevantFeatures returns feature gates relevant to the EtcdCopyBackupTask controller
func (cfg *Config) GetRelevantFeatures() []featuregate.Feature {
return relevantFeatures
}
3 changes: 2 additions & 1 deletion controllers/etcdcopybackupstask/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
druidv1alpha1 "github.com/gardener/etcd-druid/api/v1alpha1"
"github.com/gardener/etcd-druid/controllers/utils"
"github.com/gardener/etcd-druid/pkg/common"
"github.com/gardener/etcd-druid/pkg/features"
druidutils "github.com/gardener/etcd-druid/pkg/utils"
v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
"github.com/gardener/gardener/pkg/controllerutils"
Expand Down Expand Up @@ -60,7 +61,7 @@ type Reconciler struct {

// NewReconciler creates a new reconciler for EtcdCopyBackupsTask.
func NewReconciler(mgr manager.Manager, config *Config) (*Reconciler, error) {
imageVector, err := utils.CreateImageVector()
imageVector, err := utils.CreateImageVector(config.FeatureGates[string(features.UseEtcdWrapper)])
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions controllers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ func CreateManagerWithControllers(config *ManagerConfig) (ctrl.Manager, error) {
mgr ctrl.Manager
)

PopulateControllerFeatureGates(config)

if mgr, err = createManager(config); err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 1e7a80f

Please sign in to comment.