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

server/config: address golangci var-naming issues #17854

Merged
Merged
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
49 changes: 40 additions & 9 deletions server/config/v2_deprecation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,48 @@ type V2DeprecationEnum string

const (
// No longer supported in v3.6
V2_DEPR_0_NOT_YET = V2DeprecationEnum("not-yet")
V2Depr0NotYet = V2DeprecationEnum("not-yet")
// No longer supported in v3.6
//
// Deprecated: Please use V2Depr0NotYet.
//revive:disable-next-line:var-naming
V2_DEPR_0_NOT_YET = V2Depr0NotYet
// Default in v3.6. Meaningful v2 state is not allowed.
// The V2 files are maintained for v3.5 rollback.
V2_DEPR_1_WRITE_ONLY = V2DeprecationEnum("write-only")

V2Depr1WriteOnly = V2DeprecationEnum("write-only")
// Default in v3.6. Meaningful v2 state is not allowed.
// The V2 files are maintained for v3.5 rollback.
//
// Deprecated: Please use V2Depr1WriteOnly.
//revive:disable-next-line:var-naming
V2_DEPR_1_WRITE_ONLY = V2Depr1WriteOnly

// V2store is WIPED if found !!!
V2_DEPR_1_WRITE_ONLY_DROP = V2DeprecationEnum("write-only-drop-data")
V2Depr1WriteOnlyDrop = V2DeprecationEnum("write-only-drop-data")
// V2store is WIPED if found !!!
//
// Deprecated: Pleae use V2Depr1WriteOnlyDrop.
//revive:disable-next-line:var-naming
V2_DEPR_1_WRITE_ONLY_DROP = V2Depr1WriteOnlyDrop

// V2store is neither written nor read. Usage of this configuration is blocking
// ability to rollback to etcd v3.5.
V2Depr2Gone = V2DeprecationEnum("gone")
// V2store is neither written nor read. Usage of this configuration is blocking
// ability to rollback to etcd v3.5.
V2_DEPR_2_GONE = V2DeprecationEnum("gone")
//
// Deprecated: Please use V2Depr2Gone
//revive:disable-next-line:var-naming
V2_DEPR_2_GONE = V2Depr2Gone

V2_DEPR_DEFAULT = V2_DEPR_1_WRITE_ONLY
// Default deprecation level.
V2DeprDefault = V2Depr1WriteOnly
// Default deprecation level.
//
// Deprecated: Please use V2DeprDefault.
//revive:disable-next-line:var-naming
V2_DEPR_DEFAULT = V2DeprDefault
)

func (e V2DeprecationEnum) IsAtLeast(v2d V2DeprecationEnum) bool {
Expand All @@ -37,13 +68,13 @@ func (e V2DeprecationEnum) IsAtLeast(v2d V2DeprecationEnum) bool {

func (e V2DeprecationEnum) level() int {
switch e {
case V2_DEPR_0_NOT_YET:
case V2Depr0NotYet:
return 0
case V2_DEPR_1_WRITE_ONLY:
case V2Depr1WriteOnly:
return 1
case V2_DEPR_1_WRITE_ONLY_DROP:
case V2Depr1WriteOnlyDrop:
return 2
case V2_DEPR_2_GONE:
case V2Depr2Gone:
return 3
}
panic("Unknown V2DeprecationEnum: " + e)
Expand Down
16 changes: 8 additions & 8 deletions server/config/v2_deprecation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ func TestV2DeprecationEnum_IsAtLeast(t *testing.T) {
v2d V2DeprecationEnum
want bool
}{
{V2_DEPR_0_NOT_YET, V2_DEPR_0_NOT_YET, true},
{V2_DEPR_0_NOT_YET, V2_DEPR_1_WRITE_ONLY_DROP, false},
{V2_DEPR_0_NOT_YET, V2_DEPR_2_GONE, false},
{V2_DEPR_2_GONE, V2_DEPR_1_WRITE_ONLY_DROP, true},
{V2_DEPR_2_GONE, V2_DEPR_0_NOT_YET, true},
{V2_DEPR_2_GONE, V2_DEPR_2_GONE, true},
{V2_DEPR_1_WRITE_ONLY, V2_DEPR_1_WRITE_ONLY_DROP, false},
{V2_DEPR_1_WRITE_ONLY_DROP, V2_DEPR_1_WRITE_ONLY, true},
{V2Depr0NotYet, V2Depr0NotYet, true},
{V2Depr0NotYet, V2Depr1WriteOnlyDrop, false},
{V2Depr0NotYet, V2Depr2Gone, false},
{V2Depr2Gone, V2Depr1WriteOnlyDrop, true},
{V2Depr2Gone, V2Depr0NotYet, true},
{V2Depr2Gone, V2Depr2Gone, true},
{V2Depr1WriteOnly, V2Depr1WriteOnlyDrop, false},
{V2Depr1WriteOnlyDrop, V2Depr1WriteOnly, true},
}
for _, tt := range tests {
t.Run(string(tt.e)+" >= "+string(tt.v2d), func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions server/embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ func NewConfig() *Config {
ExperimentalCompactHashCheckEnabled: false,
ExperimentalCompactHashCheckTime: DefaultExperimentalCompactHashCheckTime,

V2Deprecation: config.V2_DEPR_DEFAULT,
V2Deprecation: config.V2DeprDefault,

DiscoveryCfg: v3discovery.DiscoveryConfig{
ConfigSpec: clientv3.ConfigSpec{
Expand Down Expand Up @@ -1149,7 +1149,7 @@ func (cfg *Config) ElectionTicks() int { return int(cfg.ElectionMs / cfg.TickMs)

func (cfg *Config) V2DeprecationEffective() config.V2DeprecationEnum {
if cfg.V2Deprecation == "" {
return config.V2_DEPR_DEFAULT
return config.V2DeprDefault
}
return cfg.V2Deprecation
}
Expand Down
8 changes: 4 additions & 4 deletions server/etcdmain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ func newConfig() *config {
fallbackFlagProxy,
),
v2deprecation: flags.NewSelectiveStringsValue(
string(cconfig.V2_DEPR_1_WRITE_ONLY),
string(cconfig.V2_DEPR_1_WRITE_ONLY_DROP),
string(cconfig.V2_DEPR_2_GONE)),
string(cconfig.V2Depr1WriteOnly),
string(cconfig.V2Depr1WriteOnlyDrop),
string(cconfig.V2Depr2Gone)),
}
fs := cfg.cf.flagSet
fs.Usage = func() {
Expand Down Expand Up @@ -157,7 +157,7 @@ func (cfg *config) parse(arguments []string) error {
}

if cfg.ec.V2Deprecation == "" {
cfg.ec.V2Deprecation = cconfig.V2_DEPR_DEFAULT
cfg.ec.V2Deprecation = cconfig.V2DeprDefault
}

cfg.ec.WarningUnaryRequestDuration, perr = cfg.parseWarningUnaryRequestDuration()
Expand Down
2 changes: 1 addition & 1 deletion server/etcdmain/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Clustering:
Auto compaction retention length. 0 means disable auto compaction.
--auto-compaction-mode 'periodic'
Interpret 'auto-compaction-retention' one of: periodic|revision. 'periodic' for duration based retention, defaulting to hours if no time unit is provided (e.g. '5m'). 'revision' for revision number based retention.
--v2-deprecation '` + string(cconfig.V2_DEPR_DEFAULT) + `'
--v2-deprecation '` + string(cconfig.V2DeprDefault) + `'
Phase of v2store deprecation. Allows to opt-in for higher compatibility mode.
Supported values:
'not-yet' // Issues a warning if v2store have meaningful content (default in v3.5)
Expand Down
2 changes: 1 addition & 1 deletion server/storage/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func AssertNoV2StoreContent(lg *zap.Logger, st v2store.Store, deprecationStage c
if metaOnly {
return nil
}
if deprecationStage.IsAtLeast(config.V2_DEPR_1_WRITE_ONLY) {
if deprecationStage.IsAtLeast(config.V2Depr1WriteOnly) {
return fmt.Errorf("detected disallowed custom content in v2store for stage --v2-deprecation=%s", deprecationStage)
}
lg.Warn("detected custom v2store content. Etcd v3.5 is the last version allowing to access it using API v2. Please remove the content.")
Expand Down
Loading