mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 04:33:26 +00:00
Merge pull request #114055 from aimuz/fix-80289
kubernetes components using leader election to leases
This commit is contained in:
commit
eeaddd17c1
@ -42,6 +42,14 @@ func ValidateKubeSchedulerConfiguration(cc *config.KubeSchedulerConfiguration) u
|
|||||||
var errs []error
|
var errs []error
|
||||||
errs = append(errs, componentbasevalidation.ValidateClientConnectionConfiguration(&cc.ClientConnection, field.NewPath("clientConnection")).ToAggregate())
|
errs = append(errs, componentbasevalidation.ValidateClientConnectionConfiguration(&cc.ClientConnection, field.NewPath("clientConnection")).ToAggregate())
|
||||||
errs = append(errs, componentbasevalidation.ValidateLeaderElectionConfiguration(&cc.LeaderElection, field.NewPath("leaderElection")).ToAggregate())
|
errs = append(errs, componentbasevalidation.ValidateLeaderElectionConfiguration(&cc.LeaderElection, field.NewPath("leaderElection")).ToAggregate())
|
||||||
|
|
||||||
|
// TODO: This can be removed when ResourceLock is not available
|
||||||
|
// Only ResourceLock values with leases are allowed
|
||||||
|
if cc.LeaderElection.LeaderElect && cc.LeaderElection.ResourceLock != "leases" {
|
||||||
|
leaderElectionPath := field.NewPath("leaderElection")
|
||||||
|
errs = append(errs, field.Invalid(leaderElectionPath.Child("resourceLock"), cc.LeaderElection.ResourceLock, `resourceLock value must be "leases"`))
|
||||||
|
}
|
||||||
|
|
||||||
profilesPath := field.NewPath("profiles")
|
profilesPath := field.NewPath("profiles")
|
||||||
if cc.Parallelism <= 0 {
|
if cc.Parallelism <= 0 {
|
||||||
errs = append(errs, field.Invalid(field.NewPath("parallelism"), cc.Parallelism, "should be an integer value greater than zero"))
|
errs = append(errs, field.Invalid(field.NewPath("parallelism"), cc.Parallelism, "should be an integer value greater than zero"))
|
||||||
|
@ -46,7 +46,7 @@ func TestValidateKubeSchedulerConfigurationV1beta2(t *testing.T) {
|
|||||||
Burst: 10,
|
Burst: 10,
|
||||||
},
|
},
|
||||||
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
||||||
ResourceLock: "configmap",
|
ResourceLock: "leases",
|
||||||
LeaderElect: true,
|
LeaderElect: true,
|
||||||
LeaseDuration: metav1.Duration{Duration: 30 * time.Second},
|
LeaseDuration: metav1.Duration{Duration: 30 * time.Second},
|
||||||
RenewDeadline: metav1.Duration{Duration: 15 * time.Second},
|
RenewDeadline: metav1.Duration{Duration: 15 * time.Second},
|
||||||
@ -104,6 +104,9 @@ func TestValidateKubeSchedulerConfigurationV1beta2(t *testing.T) {
|
|||||||
resourceNamespaceNotSet := validConfig.DeepCopy()
|
resourceNamespaceNotSet := validConfig.DeepCopy()
|
||||||
resourceNamespaceNotSet.LeaderElection.ResourceNamespace = ""
|
resourceNamespaceNotSet.LeaderElection.ResourceNamespace = ""
|
||||||
|
|
||||||
|
resourceLockNotLeases := validConfig.DeepCopy()
|
||||||
|
resourceLockNotLeases.LeaderElection.ResourceLock = "configmap"
|
||||||
|
|
||||||
enableContentProfilingSetWithoutEnableProfiling := validConfig.DeepCopy()
|
enableContentProfilingSetWithoutEnableProfiling := validConfig.DeepCopy()
|
||||||
enableContentProfilingSetWithoutEnableProfiling.EnableProfiling = false
|
enableContentProfilingSetWithoutEnableProfiling.EnableProfiling = false
|
||||||
enableContentProfilingSetWithoutEnableProfiling.EnableContentionProfiling = true
|
enableContentProfilingSetWithoutEnableProfiling.EnableContentionProfiling = true
|
||||||
@ -248,6 +251,15 @@ func TestValidateKubeSchedulerConfigurationV1beta2(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"bad-resource-lock-not-leases": {
|
||||||
|
config: resourceLockNotLeases,
|
||||||
|
wantErrs: field.ErrorList{
|
||||||
|
&field.Error{
|
||||||
|
Type: field.ErrorTypeInvalid,
|
||||||
|
Field: "leaderElection.resourceLock",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
"non-empty-metrics-bind-addr": {
|
"non-empty-metrics-bind-addr": {
|
||||||
config: metricsBindAddrInvalid,
|
config: metricsBindAddrInvalid,
|
||||||
wantErrs: field.ErrorList{
|
wantErrs: field.ErrorList{
|
||||||
@ -432,7 +444,7 @@ func TestValidateKubeSchedulerConfigurationV1beta3(t *testing.T) {
|
|||||||
Burst: 10,
|
Burst: 10,
|
||||||
},
|
},
|
||||||
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
||||||
ResourceLock: "configmap",
|
ResourceLock: "leases",
|
||||||
LeaderElect: true,
|
LeaderElect: true,
|
||||||
LeaseDuration: metav1.Duration{Duration: 30 * time.Second},
|
LeaseDuration: metav1.Duration{Duration: 30 * time.Second},
|
||||||
RenewDeadline: metav1.Duration{Duration: 15 * time.Second},
|
RenewDeadline: metav1.Duration{Duration: 15 * time.Second},
|
||||||
@ -487,6 +499,9 @@ func TestValidateKubeSchedulerConfigurationV1beta3(t *testing.T) {
|
|||||||
resourceNameNotSet := validConfig.DeepCopy()
|
resourceNameNotSet := validConfig.DeepCopy()
|
||||||
resourceNameNotSet.LeaderElection.ResourceName = ""
|
resourceNameNotSet.LeaderElection.ResourceName = ""
|
||||||
|
|
||||||
|
resourceLockNotLeases := validConfig.DeepCopy()
|
||||||
|
resourceLockNotLeases.LeaderElection.ResourceLock = "configmap"
|
||||||
|
|
||||||
resourceNamespaceNotSet := validConfig.DeepCopy()
|
resourceNamespaceNotSet := validConfig.DeepCopy()
|
||||||
resourceNamespaceNotSet.LeaderElection.ResourceNamespace = ""
|
resourceNamespaceNotSet.LeaderElection.ResourceNamespace = ""
|
||||||
|
|
||||||
@ -631,6 +646,15 @@ func TestValidateKubeSchedulerConfigurationV1beta3(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"bad-resource-lock-not-leases": {
|
||||||
|
config: resourceLockNotLeases,
|
||||||
|
wantErrs: field.ErrorList{
|
||||||
|
&field.Error{
|
||||||
|
Type: field.ErrorTypeInvalid,
|
||||||
|
Field: "leaderElection.resourceLock",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
"bad-resource-namespace-not-set": {
|
"bad-resource-namespace-not-set": {
|
||||||
config: resourceNamespaceNotSet,
|
config: resourceNamespaceNotSet,
|
||||||
wantErrs: field.ErrorList{
|
wantErrs: field.ErrorList{
|
||||||
@ -824,7 +848,7 @@ func TestValidateKubeSchedulerConfigurationV1(t *testing.T) {
|
|||||||
Burst: 10,
|
Burst: 10,
|
||||||
},
|
},
|
||||||
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
||||||
ResourceLock: "configmap",
|
ResourceLock: "leases",
|
||||||
LeaderElect: true,
|
LeaderElect: true,
|
||||||
LeaseDuration: metav1.Duration{Duration: 30 * time.Second},
|
LeaseDuration: metav1.Duration{Duration: 30 * time.Second},
|
||||||
RenewDeadline: metav1.Duration{Duration: 15 * time.Second},
|
RenewDeadline: metav1.Duration{Duration: 15 * time.Second},
|
||||||
@ -883,6 +907,9 @@ func TestValidateKubeSchedulerConfigurationV1(t *testing.T) {
|
|||||||
resourceNamespaceNotSet := validConfig.DeepCopy()
|
resourceNamespaceNotSet := validConfig.DeepCopy()
|
||||||
resourceNamespaceNotSet.LeaderElection.ResourceNamespace = ""
|
resourceNamespaceNotSet.LeaderElection.ResourceNamespace = ""
|
||||||
|
|
||||||
|
resourceLockNotLeases := validConfig.DeepCopy()
|
||||||
|
resourceLockNotLeases.LeaderElection.ResourceLock = "configmap"
|
||||||
|
|
||||||
enableContentProfilingSetWithoutEnableProfiling := validConfig.DeepCopy()
|
enableContentProfilingSetWithoutEnableProfiling := validConfig.DeepCopy()
|
||||||
enableContentProfilingSetWithoutEnableProfiling.EnableProfiling = false
|
enableContentProfilingSetWithoutEnableProfiling.EnableProfiling = false
|
||||||
enableContentProfilingSetWithoutEnableProfiling.EnableContentionProfiling = true
|
enableContentProfilingSetWithoutEnableProfiling.EnableContentionProfiling = true
|
||||||
@ -1030,6 +1057,15 @@ func TestValidateKubeSchedulerConfigurationV1(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"bad-resource-lock-not-leases": {
|
||||||
|
config: resourceLockNotLeases,
|
||||||
|
wantErrs: field.ErrorList{
|
||||||
|
&field.Error{
|
||||||
|
Type: field.ErrorTypeInvalid,
|
||||||
|
Field: "leaderElection.resourceLock",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
"non-empty-metrics-bind-addr": {
|
"non-empty-metrics-bind-addr": {
|
||||||
config: metricsBindAddrInvalid,
|
config: metricsBindAddrInvalid,
|
||||||
wantErrs: field.ErrorList{
|
wantErrs: field.ErrorList{
|
||||||
|
@ -102,6 +102,12 @@ func (o *GenericControllerManagerConfigurationOptions) Validate(allControllers [
|
|||||||
errs := []error{}
|
errs := []error{}
|
||||||
errs = append(errs, o.Debugging.Validate()...)
|
errs = append(errs, o.Debugging.Validate()...)
|
||||||
|
|
||||||
|
// TODO: This can be removed when ResourceLock is not available
|
||||||
|
// Lock the ResourceLock using leases
|
||||||
|
if o.LeaderElection.LeaderElect && o.LeaderElection.ResourceLock != "leases" {
|
||||||
|
errs = append(errs, fmt.Errorf(`resourceLock value must be "leases"`))
|
||||||
|
}
|
||||||
|
|
||||||
allControllersSet := sets.NewString(allControllers...)
|
allControllersSet := sets.NewString(allControllers...)
|
||||||
for _, controller := range o.Controllers {
|
for _, controller := range o.Controllers {
|
||||||
if controller == "*" {
|
if controller == "*" {
|
||||||
|
Loading…
Reference in New Issue
Block a user