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

Align NewConfig with AddFlags defaults #19254

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
48 changes: 32 additions & 16 deletions server/embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,18 @@ const (
DefaultGRPCKeepAliveTimeout = 20 * time.Second
DefaultDowngradeCheckTime = 5 * time.Second
DefaultAutoCompactionMode = "periodic"
DefaultAutoCompactionRetention = "0"
DefaultAuthToken = "simple"
DefaultCompactHashCheckTime = time.Minute
DefaultLoggingFormat = "json"

DefaultDiscoveryDialTimeout = 2 * time.Second
DefaultDiscoveryRequestTimeOut = 5 * time.Second
DefaultDiscoveryKeepAliveTime = 2 * time.Second
DefaultDiscoveryKeepAliveTimeOut = 6 * time.Second
DefaultDiscoveryDialTimeout = 2 * time.Second
DefaultDiscoveryRequestTimeOut = 5 * time.Second
DefaultDiscoveryKeepAliveTime = 2 * time.Second
DefaultDiscoveryKeepAliveTimeOut = 6 * time.Second
DefaultDiscoveryInsecureTransport = true
DefaultSelfSignedCertValidity = 1
DefaultTLSMinVersion = string(tlsutil.TLSVersion12)

DefaultListenPeerURLs = "http://localhost:2380"
DefaultListenClientURLs = "http://localhost:2379"
Expand All @@ -101,6 +106,8 @@ const (
// ExperimentalDistributedTracingServiceName is the default etcd service name.
ExperimentalDistributedTracingServiceName = "etcd"

ExperimentalTxnModeWriteWithSharedBuffer = true

// DefaultStrictReconfigCheck is the default value for "--strict-reconfig-check" flag.
// It's enabled by default.
DefaultStrictReconfigCheck = true
Expand Down Expand Up @@ -578,25 +585,31 @@ func NewConfig() *Config {
CORS: map[string]struct{}{"*": {}},
HostWhitelist: map[string]struct{}{"*": {}},

AuthToken: DefaultAuthToken,
BcryptCost: uint(bcrypt.DefaultCost),
AuthTokenTTL: 300,
AuthToken: DefaultAuthToken,
BcryptCost: uint(bcrypt.DefaultCost),
AuthTokenTTL: 300,
SelfSignedCertValidity: DefaultSelfSignedCertValidity,
TlsMinVersion: DefaultTLSMinVersion,

PreVote: true,

loggerMu: new(sync.RWMutex),
logger: nil,
Logger: "zap",
LogFormat: DefaultLoggingFormat,
LogOutputs: []string{DefaultLogOutput},
LogLevel: logutil.DefaultLogLevel,
EnableLogRotation: false,
LogRotationConfigJSON: DefaultLogRotationConfig,
EnableGRPCGateway: true,

ExperimentalDowngradeCheckTime: DefaultDowngradeCheckTime,
ExperimentalMemoryMlock: false,
ExperimentalStopGRPCServiceOnDefrag: false,
ExperimentalMaxLearners: membership.DefaultMaxLearners,
ExperimentalDowngradeCheckTime: DefaultDowngradeCheckTime,
ExperimentalMemoryMlock: false,
ExperimentalStopGRPCServiceOnDefrag: false,
ExperimentalMaxLearners: membership.DefaultMaxLearners,
ExperimentalTxnModeWriteWithSharedBuffer: ExperimentalTxnModeWriteWithSharedBuffer,
ExperimentalDistributedTracingAddress: ExperimentalDistributedTracingAddress,
ExperimentalDistributedTracingServiceName: ExperimentalDistributedTracingServiceName,

CompactHashCheckTime: DefaultCompactHashCheckTime,
// TODO: delete in v3.7
Expand All @@ -611,14 +624,17 @@ func NewConfig() *Config {
KeepAliveTime: DefaultDiscoveryKeepAliveTime,
KeepAliveTimeout: DefaultDiscoveryKeepAliveTimeOut,

Secure: &clientv3.SecureConfig{},
Auth: &clientv3.AuthConfig{},
Secure: &clientv3.SecureConfig{
InsecureTransport: true,
},
Auth: &clientv3.AuthConfig{},
},
},

AutoCompactionMode: DefaultAutoCompactionMode,
ServerFeatureGate: features.NewDefaultServerFeatureGate(DefaultName, nil),
FlagsExplicitlySet: map[string]bool{},
AutoCompactionMode: DefaultAutoCompactionMode,
AutoCompactionRetention: DefaultAutoCompactionRetention,
ServerFeatureGate: features.NewDefaultServerFeatureGate(DefaultName, nil),
FlagsExplicitlySet: map[string]bool{},
}
cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name)
return cfg
Expand Down
14 changes: 1 addition & 13 deletions server/embed/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"sigs.k8s.io/yaml"

"go.etcd.io/etcd/client/pkg/v3/srv"
"go.etcd.io/etcd/client/pkg/v3/tlsutil"
"go.etcd.io/etcd/client/pkg/v3/transport"
"go.etcd.io/etcd/client/pkg/v3/types"
"go.etcd.io/etcd/pkg/v3/featuregate"
Expand Down Expand Up @@ -1051,19 +1050,8 @@ func TestMatchNewConfigAddFlags(t *testing.T) {
fs := flag.NewFlagSet("etcd", flag.ContinueOnError)
cfg.AddFlags(fs)
require.NoError(t, fs.Parse(nil))

newConfig := NewConfig()
// TODO: Remove the following assigments when both match.
newConfig.SelfSignedCertValidity = 1
newConfig.TlsMinVersion = string(tlsutil.TLSVersion12)
newConfig.DiscoveryCfg.Secure.InsecureTransport = true
newConfig.AutoCompactionRetention = "0"
newConfig.ExperimentalDistributedTracingAddress = "localhost:4317"
newConfig.ExperimentalDistributedTracingServiceName = "etcd"
newConfig.LogFormat = "json"
newConfig.ExperimentalTxnModeWriteWithSharedBuffer = true
// TODO: Reduce number of unexported fields set in config
if diff := cmp.Diff(newConfig, cfg, cmpopts.IgnoreUnexported(transport.TLSInfo{}, Config{}), cmp.Comparer(func(a, b featuregate.FeatureGate) bool {
if diff := cmp.Diff(NewConfig(), cfg, cmpopts.IgnoreUnexported(transport.TLSInfo{}, Config{}), cmp.Comparer(func(a, b featuregate.FeatureGate) bool {
return a.String() == b.String()
})); diff != "" {
t.Errorf("Diff: %s", diff)
Expand Down
Loading