Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced feature gates in etcd druid and added UseEtcdWrapper feature gate #646

Merged
merged 8 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions charts/images-wrapper.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
images:
- name: etcd-backup-restore
resourceId:
name: 'etcdbrctl'
sourceRepository: github.com/gardener/etcd-backup-restore
repository: eu.gcr.io/gardener-project/gardener/etcdbrctl
tag: "v0.25.0"
- name: etcd
sourceRepository: github.com/gardener/etcd-wrapper
repository: eu.gcr.io/gardener-project/gardener/etcd-wrapper
tag: "v0.1.0"
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
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
tag: "bootstrap-entrypoint-1"
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
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{
unmarshall marked this conversation as resolved.
Show resolved Hide resolved
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 {
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
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
62 changes: 60 additions & 2 deletions controllers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
package controllers

import (
"flag"
"fmt"

"github.com/gardener/etcd-druid/pkg/features"
flag "github.com/spf13/pflag"
"k8s.io/component-base/featuregate"
unmarshall marked this conversation as resolved.
Show resolved Hide resolved

"github.com/gardener/etcd-druid/controllers/compaction"
"github.com/gardener/etcd-druid/controllers/custodian"
Expand Down Expand Up @@ -61,6 +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 gates to be used by etcd-druid.
FeatureFlags featuregate.MutableFeatureGate
unmarshall marked this conversation as resolved.
Show resolved Hide resolved
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
// EtcdControllerConfig is the configuration required for etcd controller.
EtcdControllerConfig *etcd.Config
// CustodianControllerConfig is the configuration required for custodian controller.
Expand All @@ -74,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 {
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
flag.StringVar(&cfg.MetricsAddr, metricsAddrFlagName, defaultMetricsAddr, ""+
"The address the metric endpoint binds to.")
flag.BoolVar(&cfg.EnableLeaderElection, enableLeaderElectionFlagName, defaultEnableLeaderElection,
Expand All @@ -88,6 +94,10 @@ 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.")

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

cfg.EtcdControllerConfig = &etcd.Config{}
etcd.InitFromFlags(fs, cfg.EtcdControllerConfig)

Expand All @@ -102,6 +112,54 @@ func InitFromFlags(fs *flag.FlagSet, cfg *ManagerConfig) {

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

return nil
}

// InitFeatureGates initializes feature gates from the provided CLI flag set.
func InitFeatureGates(fs *flag.FlagSet, featureFlags *featuregate.MutableFeatureGate) error {
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
*featureFlags = featuregate.NewFeatureGate()
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
if err := (*featureFlags).Add(features.GetDefaultFeatures()); err != nil {
return fmt.Errorf("error adding features to the featuregate: %v", err)
}
(*featureFlags).AddFlag(fs)

return nil
}

// PopulateControllerFeatureGates adds relevant feature gates to every controller configuration
func PopulateControllerFeatureGates(config *ManagerConfig) {
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved

// Add etcd controller feature flags
config.EtcdControllerConfig.FeatureGates = make(map[string]bool)
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
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
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
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)
}

}

// Validate validates the controller manager config.
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{}
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved

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
}
16 changes: 15 additions & 1 deletion controllers/etcd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
package etcd

import (
"flag"
flag "github.com/spf13/pflag"
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
"k8s.io/component-base/featuregate"

"github.com/gardener/etcd-druid/controllers/utils"
"github.com/gardener/etcd-druid/pkg/features"
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
)

const (
Expand All @@ -28,12 +30,19 @@ const (
defaultDisableEtcdServiceAccountAutomount = false
)

// 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.
type Config struct {
// Workers is the number of workers concurrently processing reconciliation requests.
Workers int
// DisableEtcdServiceAccountAutomount controls the auto-mounting of service account token for etcd statefulsets.
DisableEtcdServiceAccountAutomount 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 @@ -51,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
}
14 changes: 14 additions & 0 deletions controllers/etcd/etcd_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2023 SAP SE or an SAP affiliate company
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package etcd

import (
Expand Down
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
3 changes: 3 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 Expand Up @@ -82,6 +84,7 @@ func registerControllersWithManager(mgr ctrl.Manager, config *ManagerConfig) err
var err error

// Add etcd reconciler to the manager
// TODO: opt2: easiest place to set controller-specific featureFlags
shreyas-s-rao marked this conversation as resolved.
Show resolved Hide resolved
etcdReconciler, err := etcd.NewReconciler(mgr, config.EtcdControllerConfig)
if err != nil {
return err
Expand Down
Loading