mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
Merge pull request #111758 from SataQiu/fix-leaderelection-20220809
Make the validation logic about LeaderElectionConfiguration consistent between component-base and client-go
This commit is contained in:
commit
0ac9784985
@ -35,7 +35,7 @@ func BindLeaderElectionFlags(l *config.LeaderElectionConfiguration, fs *pflag.Fl
|
||||
"election is enabled.")
|
||||
fs.DurationVar(&l.RenewDeadline.Duration, "leader-elect-renew-deadline", l.RenewDeadline.Duration, ""+
|
||||
"The interval between attempts by the acting master to renew a leadership slot "+
|
||||
"before it stops leading. This must be less than or equal to the lease duration. "+
|
||||
"before it stops leading. This must be less than the lease duration. "+
|
||||
"This is only applicable if leader election is enabled.")
|
||||
fs.DurationVar(&l.RetryPeriod.Duration, "leader-elect-retry-period", l.RetryPeriod.Duration, ""+
|
||||
"The duration the clients should wait between attempting acquisition and renewal "+
|
||||
|
@ -45,7 +45,7 @@ func ValidateLeaderElectionConfiguration(cc *config.LeaderElectionConfiguration,
|
||||
if cc.RetryPeriod.Duration <= 0 {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("retryPeriod"), cc.RetryPeriod, "must be greater than zero"))
|
||||
}
|
||||
if cc.LeaseDuration.Duration < cc.RenewDeadline.Duration {
|
||||
if cc.LeaseDuration.Duration <= cc.RenewDeadline.Duration {
|
||||
allErrs = append(allErrs, field.Invalid(fldPath.Child("leaseDuration"), cc.RenewDeadline, "LeaseDuration must be greater than RenewDeadline"))
|
||||
}
|
||||
if len(cc.ResourceLock) == 0 {
|
||||
|
@ -79,6 +79,9 @@ func TestValidateLeaderElectionConfiguration(t *testing.T) {
|
||||
ResourceName: "name",
|
||||
}
|
||||
|
||||
renewDeadlineEqualToLeaseDuration := validConfig.DeepCopy()
|
||||
renewDeadlineEqualToLeaseDuration.RenewDeadline = metav1.Duration{Duration: 30 * time.Second}
|
||||
|
||||
renewDeadlineExceedsLeaseDuration := validConfig.DeepCopy()
|
||||
renewDeadlineExceedsLeaseDuration.RenewDeadline = metav1.Duration{Duration: 45 * time.Second}
|
||||
|
||||
@ -122,6 +125,10 @@ func TestValidateLeaderElectionConfiguration(t *testing.T) {
|
||||
expectedToFail: false,
|
||||
config: LeaderElectButLeaderElectNotEnabled,
|
||||
},
|
||||
"bad-renew-deadline-equal-to-lease-duration": {
|
||||
expectedToFail: true,
|
||||
config: renewDeadlineEqualToLeaseDuration,
|
||||
},
|
||||
"bad-renew-deadline-exceeds-lease-duration": {
|
||||
expectedToFail: true,
|
||||
config: renewDeadlineExceedsLeaseDuration,
|
||||
|
Loading…
Reference in New Issue
Block a user