mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
add options for name and namespace of leaderelection object
Change-Id: Iaa62f5f1c3b24a4cc567a840707d9eba7cf901b8
This commit is contained in:
parent
1871f75b32
commit
ee6e28b5cf
@ -186,8 +186,8 @@ func Run(c *cloudcontrollerconfig.CompletedConfig, stopCh <-chan struct{}) error
|
|||||||
|
|
||||||
// Lock required for leader election
|
// Lock required for leader election
|
||||||
rl, err := resourcelock.New(c.ComponentConfig.Generic.LeaderElection.ResourceLock,
|
rl, err := resourcelock.New(c.ComponentConfig.Generic.LeaderElection.ResourceLock,
|
||||||
"kube-system",
|
c.ComponentConfig.Generic.LeaderElection.ResourceNamespace,
|
||||||
"cloud-controller-manager",
|
c.ComponentConfig.Generic.LeaderElection.ResourceName,
|
||||||
c.LeaderElectionClient.CoreV1(),
|
c.LeaderElectionClient.CoreV1(),
|
||||||
c.LeaderElectionClient.CoordinationV1(),
|
c.LeaderElectionClient.CoordinationV1(),
|
||||||
resourcelock.ResourceLockConfig{
|
resourcelock.ResourceLockConfig{
|
||||||
|
@ -107,6 +107,9 @@ func NewCloudControllerManagerOptions() (*CloudControllerManagerOptions, error)
|
|||||||
s.SecureServing.ServerCert.PairName = "cloud-controller-manager"
|
s.SecureServing.ServerCert.PairName = "cloud-controller-manager"
|
||||||
s.SecureServing.BindPort = ports.CloudControllerManagerPort
|
s.SecureServing.BindPort = ports.CloudControllerManagerPort
|
||||||
|
|
||||||
|
s.Generic.LeaderElection.ResourceName = "cloud-controller-manager"
|
||||||
|
s.Generic.LeaderElection.ResourceNamespace = "kube-system"
|
||||||
|
|
||||||
return &s, nil
|
return &s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,11 +49,13 @@ func TestDefaultFlags(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ControllerStartInterval: metav1.Duration{Duration: 0},
|
ControllerStartInterval: metav1.Duration{Duration: 0},
|
||||||
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
||||||
ResourceLock: "endpoints",
|
ResourceLock: "endpoints",
|
||||||
LeaderElect: true,
|
LeaderElect: true,
|
||||||
LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
|
LeaseDuration: metav1.Duration{Duration: 15 * time.Second},
|
||||||
RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
|
RenewDeadline: metav1.Duration{Duration: 10 * time.Second},
|
||||||
RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
|
RetryPeriod: metav1.Duration{Duration: 2 * time.Second},
|
||||||
|
ResourceName: "cloud-controller-manager",
|
||||||
|
ResourceNamespace: "kube-system",
|
||||||
},
|
},
|
||||||
Controllers: []string{"*"},
|
Controllers: []string{"*"},
|
||||||
},
|
},
|
||||||
@ -178,11 +180,13 @@ func TestAddFlags(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ControllerStartInterval: metav1.Duration{Duration: 2 * time.Minute},
|
ControllerStartInterval: metav1.Duration{Duration: 2 * time.Minute},
|
||||||
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
||||||
ResourceLock: "configmap",
|
ResourceLock: "configmap",
|
||||||
LeaderElect: false,
|
LeaderElect: false,
|
||||||
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},
|
||||||
RetryPeriod: metav1.Duration{Duration: 5 * time.Second},
|
RetryPeriod: metav1.Duration{Duration: 5 * time.Second},
|
||||||
|
ResourceName: "cloud-controller-manager",
|
||||||
|
ResourceNamespace: "kube-system",
|
||||||
},
|
},
|
||||||
Controllers: []string{"foo", "bar"},
|
Controllers: []string{"foo", "bar"},
|
||||||
},
|
},
|
||||||
|
@ -257,9 +257,10 @@ func Run(c *config.CompletedConfig, stopCh <-chan struct{}) error {
|
|||||||
|
|
||||||
// add a uniquifier so that two processes on the same host don't accidentally both become active
|
// add a uniquifier so that two processes on the same host don't accidentally both become active
|
||||||
id = id + "_" + string(uuid.NewUUID())
|
id = id + "_" + string(uuid.NewUUID())
|
||||||
|
|
||||||
rl, err := resourcelock.New(c.ComponentConfig.Generic.LeaderElection.ResourceLock,
|
rl, err := resourcelock.New(c.ComponentConfig.Generic.LeaderElection.ResourceLock,
|
||||||
"kube-system",
|
c.ComponentConfig.Generic.LeaderElection.ResourceNamespace,
|
||||||
"kube-controller-manager",
|
c.ComponentConfig.Generic.LeaderElection.ResourceName,
|
||||||
c.LeaderElectionClient.CoreV1(),
|
c.LeaderElectionClient.CoreV1(),
|
||||||
c.LeaderElectionClient.CoordinationV1(),
|
c.LeaderElectionClient.CoordinationV1(),
|
||||||
resourcelock.ResourceLockConfig{
|
resourcelock.ResourceLockConfig{
|
||||||
|
@ -184,6 +184,8 @@ func NewKubeControllerManagerOptions() (*KubeControllerManagerOptions, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
s.GarbageCollectorController.GCIgnoredResources = gcIgnoredResources
|
s.GarbageCollectorController.GCIgnoredResources = gcIgnoredResources
|
||||||
|
s.Generic.LeaderElection.ResourceName = "kube-controller-manager"
|
||||||
|
s.Generic.LeaderElection.ResourceNamespace = "kube-system"
|
||||||
|
|
||||||
return &s, nil
|
return &s, nil
|
||||||
}
|
}
|
||||||
|
@ -154,11 +154,13 @@ func TestAddFlags(t *testing.T) {
|
|||||||
},
|
},
|
||||||
ControllerStartInterval: metav1.Duration{Duration: 2 * time.Minute},
|
ControllerStartInterval: metav1.Duration{Duration: 2 * time.Minute},
|
||||||
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
|
||||||
ResourceLock: "configmap",
|
ResourceLock: "configmap",
|
||||||
LeaderElect: false,
|
LeaderElect: false,
|
||||||
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},
|
||||||
RetryPeriod: metav1.Duration{Duration: 5 * time.Second},
|
RetryPeriod: metav1.Duration{Duration: 5 * time.Second},
|
||||||
|
ResourceName: "kube-controller-manager",
|
||||||
|
ResourceNamespace: "kube-system",
|
||||||
},
|
},
|
||||||
Controllers: []string{"foo", "bar"},
|
Controllers: []string{"foo", "bar"},
|
||||||
},
|
},
|
||||||
|
@ -43,4 +43,10 @@ func BindFlags(l *componentbaseconfig.LeaderElectionConfiguration, fs *pflag.Fla
|
|||||||
fs.StringVar(&l.ResourceLock, "leader-elect-resource-lock", l.ResourceLock, ""+
|
fs.StringVar(&l.ResourceLock, "leader-elect-resource-lock", l.ResourceLock, ""+
|
||||||
"The type of resource object that is used for locking during "+
|
"The type of resource object that is used for locking during "+
|
||||||
"leader election. Supported options are `endpoints` (default) and `configmaps`.")
|
"leader election. Supported options are `endpoints` (default) and `configmaps`.")
|
||||||
|
fs.StringVar(&l.ResourceName, "leader-elect-resource-name", l.ResourceName, ""+
|
||||||
|
"The name of resource object that is used for locking during "+
|
||||||
|
"leader election.")
|
||||||
|
fs.StringVar(&l.ResourceNamespace, "leader-elect-resource-namespace", l.ResourceNamespace, ""+
|
||||||
|
"The namespace of resource object that is used for locking during "+
|
||||||
|
"leader election.")
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,12 @@ type LeaderElectionConfiguration struct {
|
|||||||
// resourceLock indicates the resource object type that will be used to lock
|
// resourceLock indicates the resource object type that will be used to lock
|
||||||
// during leader election cycles.
|
// during leader election cycles.
|
||||||
ResourceLock string
|
ResourceLock string
|
||||||
|
// resourceName indicates the name of resource object that will be used to lock
|
||||||
|
// during leader election cycles.
|
||||||
|
ResourceName string
|
||||||
|
// resourceName indicates the namespace of resource object that will be used to lock
|
||||||
|
// during leader election cycles.
|
||||||
|
ResourceNamespace string
|
||||||
}
|
}
|
||||||
|
|
||||||
// DebuggingConfiguration holds configuration for Debugging related features.
|
// DebuggingConfiguration holds configuration for Debugging related features.
|
||||||
|
@ -48,6 +48,12 @@ type LeaderElectionConfiguration struct {
|
|||||||
// resourceLock indicates the resource object type that will be used to lock
|
// resourceLock indicates the resource object type that will be used to lock
|
||||||
// during leader election cycles.
|
// during leader election cycles.
|
||||||
ResourceLock string `json:"resourceLock"`
|
ResourceLock string `json:"resourceLock"`
|
||||||
|
// resourceName indicates the name of resource object that will be used to lock
|
||||||
|
// during leader election cycles.
|
||||||
|
ResourceName string `json:"resourceName"`
|
||||||
|
// resourceName indicates the namespace of resource object that will be used to lock
|
||||||
|
// during leader election cycles.
|
||||||
|
ResourceNamespace string `json:"resourceNamespace"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DebuggingConfiguration holds configuration for Debugging related features.
|
// DebuggingConfiguration holds configuration for Debugging related features.
|
||||||
|
@ -135,6 +135,8 @@ func autoConvert_v1alpha1_LeaderElectionConfiguration_To_config_LeaderElectionCo
|
|||||||
out.RenewDeadline = in.RenewDeadline
|
out.RenewDeadline = in.RenewDeadline
|
||||||
out.RetryPeriod = in.RetryPeriod
|
out.RetryPeriod = in.RetryPeriod
|
||||||
out.ResourceLock = in.ResourceLock
|
out.ResourceLock = in.ResourceLock
|
||||||
|
out.ResourceName = in.ResourceName
|
||||||
|
out.ResourceNamespace = in.ResourceNamespace
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,5 +148,7 @@ func autoConvert_config_LeaderElectionConfiguration_To_v1alpha1_LeaderElectionCo
|
|||||||
out.RenewDeadline = in.RenewDeadline
|
out.RenewDeadline = in.RenewDeadline
|
||||||
out.RetryPeriod = in.RetryPeriod
|
out.RetryPeriod = in.RetryPeriod
|
||||||
out.ResourceLock = in.ResourceLock
|
out.ResourceLock = in.ResourceLock
|
||||||
|
out.ResourceName = in.ResourceName
|
||||||
|
out.ResourceNamespace = in.ResourceNamespace
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user