Skip to content

Commit

Permalink
Align NewConfig with AddFlags defaults
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Siarkowicz <siarkowicz@google.com>
  • Loading branch information
serathius committed Jan 22, 2025
1 parent 8c1547b commit f011488
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
33 changes: 21 additions & 12 deletions server/embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,25 +578,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: 1,
TlsMinVersion: string(tlsutil.TLSVersion12),

PreVote: true,

loggerMu: new(sync.RWMutex),
logger: nil,
Logger: "zap",
LogFormat: "json",
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: true,
ExperimentalDistributedTracingAddress: "localhost:4317",
ExperimentalDistributedTracingServiceName: "etcd",

CompactHashCheckTime: DefaultCompactHashCheckTime,
// TODO: delete in v3.7
Expand All @@ -611,14 +617,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: "0",
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

0 comments on commit f011488

Please sign in to comment.