Skip to content

Commit ea2e19f

Browse files
SataQiuk8s-publishing-bot
authored andcommitted
make the validation logic about LeaderElectionConfiguration consistent between component-base and client-go
Kubernetes-commit: 5d7d288c044dc802a07e57b17a194da4694f2bcd
1 parent bd3841a commit ea2e19f

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Diff for: config/options/leaderelectionconfig.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func BindLeaderElectionFlags(l *config.LeaderElectionConfiguration, fs *pflag.Fl
3535
"election is enabled.")
3636
fs.DurationVar(&l.RenewDeadline.Duration, "leader-elect-renew-deadline", l.RenewDeadline.Duration, ""+
3737
"The interval between attempts by the acting master to renew a leadership slot "+
38-
"before it stops leading. This must be less than or equal to the lease duration. "+
38+
"before it stops leading. This must be less than the lease duration. "+
3939
"This is only applicable if leader election is enabled.")
4040
fs.DurationVar(&l.RetryPeriod.Duration, "leader-elect-retry-period", l.RetryPeriod.Duration, ""+
4141
"The duration the clients should wait between attempting acquisition and renewal "+

Diff for: config/validation/validation.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func ValidateLeaderElectionConfiguration(cc *config.LeaderElectionConfiguration,
4545
if cc.RetryPeriod.Duration <= 0 {
4646
allErrs = append(allErrs, field.Invalid(fldPath.Child("retryPeriod"), cc.RetryPeriod, "must be greater than zero"))
4747
}
48-
if cc.LeaseDuration.Duration < cc.RenewDeadline.Duration {
48+
if cc.LeaseDuration.Duration <= cc.RenewDeadline.Duration {
4949
allErrs = append(allErrs, field.Invalid(fldPath.Child("leaseDuration"), cc.RenewDeadline, "LeaseDuration must be greater than RenewDeadline"))
5050
}
5151
if len(cc.ResourceLock) == 0 {

Diff for: config/validation/validation_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ func TestValidateLeaderElectionConfiguration(t *testing.T) {
7979
ResourceName: "name",
8080
}
8181

82+
renewDeadlineEqualToLeaseDuration := validConfig.DeepCopy()
83+
renewDeadlineEqualToLeaseDuration.RenewDeadline = metav1.Duration{Duration: 30 * time.Second}
84+
8285
renewDeadlineExceedsLeaseDuration := validConfig.DeepCopy()
8386
renewDeadlineExceedsLeaseDuration.RenewDeadline = metav1.Duration{Duration: 45 * time.Second}
8487

@@ -122,6 +125,10 @@ func TestValidateLeaderElectionConfiguration(t *testing.T) {
122125
expectedToFail: false,
123126
config: LeaderElectButLeaderElectNotEnabled,
124127
},
128+
"bad-renew-deadline-equal-to-lease-duration": {
129+
expectedToFail: true,
130+
config: renewDeadlineEqualToLeaseDuration,
131+
},
125132
"bad-renew-deadline-exceeds-lease-duration": {
126133
expectedToFail: true,
127134
config: renewDeadlineExceedsLeaseDuration,

0 commit comments

Comments
 (0)