Merge pull request #2056 from CharlesQQ/leader-elect
feat: add leader election options
This commit is contained in:
commit
a3e6a39b8f
|
@ -147,6 +147,9 @@ func run(ctx context.Context, karmadaConfig karmadactl.KarmadaConfig, opts *opti
|
|||
LeaderElectionID: fmt.Sprintf("karmada-agent-%s", opts.ClusterName),
|
||||
LeaderElectionNamespace: opts.LeaderElection.ResourceNamespace,
|
||||
LeaderElectionResourceLock: opts.LeaderElection.ResourceLock,
|
||||
LeaseDuration: &opts.LeaderElection.LeaseDuration.Duration,
|
||||
RenewDeadline: &opts.LeaderElection.RenewDeadline.Duration,
|
||||
RetryPeriod: &opts.LeaderElection.RetryPeriod.Duration,
|
||||
HealthProbeBindAddress: net.JoinHostPort(opts.BindAddress, strconv.Itoa(opts.SecurePort)),
|
||||
LivenessEndpointName: "/healthz",
|
||||
MetricsBindAddress: opts.MetricsBindAddress,
|
||||
|
|
|
@ -21,6 +21,12 @@ const (
|
|||
defaultPort = 10357
|
||||
)
|
||||
|
||||
var (
|
||||
defaultElectionLeaseDuration = metav1.Duration{Duration: 15 * time.Second}
|
||||
defaultElectionRenewDeadline = metav1.Duration{Duration: 10 * time.Second}
|
||||
defaultElectionRetryPeriod = metav1.Duration{Duration: 2 * time.Second}
|
||||
)
|
||||
|
||||
// Options contains everything necessary to create and run controller-manager.
|
||||
type Options struct {
|
||||
// Controllers contains all controller names.
|
||||
|
@ -111,6 +117,19 @@ func (o *Options) AddFlags(fs *pflag.FlagSet, allControllers []string) {
|
|||
"The secure port on which to serve HTTPS.")
|
||||
fs.BoolVar(&o.LeaderElection.LeaderElect, "leader-elect", true, "Start a leader election client and gain leadership before executing the main loop. Enable this when running replicated components for high availability.")
|
||||
fs.StringVar(&o.LeaderElection.ResourceNamespace, "leader-elect-resource-namespace", util.NamespaceKarmadaSystem, "The namespace of resource object that is used for locking during leader election.")
|
||||
fs.DurationVar(&o.LeaderElection.LeaseDuration.Duration, "leader-elect-lease-duration", defaultElectionLeaseDuration.Duration, ""+
|
||||
"The duration that non-leader candidates will wait after observing a leadership "+
|
||||
"renewal until attempting to acquire leadership of a led but unrenewed leader "+
|
||||
"slot. This is effectively the maximum duration that a leader can be stopped "+
|
||||
"before it is replaced by another candidate. This is only applicable if leader "+
|
||||
"election is enabled.")
|
||||
fs.DurationVar(&o.LeaderElection.RenewDeadline.Duration, "leader-elect-renew-deadline", defaultElectionRenewDeadline.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. "+
|
||||
"This is only applicable if leader election is enabled.")
|
||||
fs.DurationVar(&o.LeaderElection.RetryPeriod.Duration, "leader-elect-retry-period", defaultElectionRetryPeriod.Duration, ""+
|
||||
"The duration the clients should wait between attempting acquisition and renewal "+
|
||||
"of a leadership. This is only applicable if leader election is enabled.")
|
||||
fs.StringVar(&o.KarmadaKubeConfig, "karmada-kubeconfig", o.KarmadaKubeConfig, "Path to karmada control plane kubeconfig file.")
|
||||
fs.StringVar(&o.KarmadaContext, "karmada-context", "", "Name of the cluster context in karmada control plane kubeconfig file.")
|
||||
fs.StringVar(&o.ClusterName, "cluster-name", o.ClusterName, "Name of member cluster that the agent serves for.")
|
||||
|
|
|
@ -109,6 +109,9 @@ func Run(ctx context.Context, opts *options.Options) error {
|
|||
LeaderElection: opts.LeaderElection.LeaderElect,
|
||||
LeaderElectionID: opts.LeaderElection.ResourceName,
|
||||
LeaderElectionNamespace: opts.LeaderElection.ResourceNamespace,
|
||||
LeaseDuration: &opts.LeaderElection.LeaseDuration.Duration,
|
||||
RenewDeadline: &opts.LeaderElection.RenewDeadline.Duration,
|
||||
RetryPeriod: &opts.LeaderElection.RetryPeriod.Duration,
|
||||
LeaderElectionResourceLock: opts.LeaderElection.ResourceLock,
|
||||
HealthProbeBindAddress: net.JoinHostPort(opts.BindAddress, strconv.Itoa(opts.SecurePort)),
|
||||
LivenessEndpointName: "/healthz",
|
||||
|
|
|
@ -20,6 +20,12 @@ const (
|
|||
defaultPort = 10357
|
||||
)
|
||||
|
||||
var (
|
||||
defaultElectionLeaseDuration = metav1.Duration{Duration: 15 * time.Second}
|
||||
defaultElectionRenewDeadline = metav1.Duration{Duration: 10 * time.Second}
|
||||
defaultElectionRetryPeriod = metav1.Duration{Duration: 2 * time.Second}
|
||||
)
|
||||
|
||||
// Options contains everything necessary to create and run controller-manager.
|
||||
type Options struct {
|
||||
// Controllers is the list of controllers to enable or disable
|
||||
|
@ -134,6 +140,19 @@ func (o *Options) AddFlags(flags *pflag.FlagSet, allControllers, disabledByDefau
|
|||
"Specifies how often karmada-controller-manager posts cluster status to karmada-apiserver.")
|
||||
flags.BoolVar(&o.LeaderElection.LeaderElect, "leader-elect", true, "Start a leader election client and gain leadership before executing the main loop. Enable this when running replicated components for high availability.")
|
||||
flags.StringVar(&o.LeaderElection.ResourceNamespace, "leader-elect-resource-namespace", util.NamespaceKarmadaSystem, "The namespace of resource object that is used for locking during leader election.")
|
||||
flags.DurationVar(&o.LeaderElection.LeaseDuration.Duration, "leader-elect-lease-duration", defaultElectionLeaseDuration.Duration, ""+
|
||||
"The duration that non-leader candidates will wait after observing a leadership "+
|
||||
"renewal until attempting to acquire leadership of a led but unrenewed leader "+
|
||||
"slot. This is effectively the maximum duration that a leader can be stopped "+
|
||||
"before it is replaced by another candidate. This is only applicable if leader "+
|
||||
"election is enabled.")
|
||||
flags.DurationVar(&o.LeaderElection.RenewDeadline.Duration, "leader-elect-renew-deadline", defaultElectionRenewDeadline.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. "+
|
||||
"This is only applicable if leader election is enabled.")
|
||||
flags.DurationVar(&o.LeaderElection.RetryPeriod.Duration, "leader-elect-retry-period", defaultElectionRetryPeriod.Duration, ""+
|
||||
"The duration the clients should wait between attempting acquisition and renewal "+
|
||||
"of a leadership. This is only applicable if leader election is enabled.")
|
||||
flags.DurationVar(&o.ClusterLeaseDuration.Duration, "cluster-lease-duration", 40*time.Second,
|
||||
"Specifies the expiration period of a cluster lease.")
|
||||
flags.Float64Var(&o.ClusterLeaseRenewIntervalFraction, "cluster-lease-renew-interval-fraction", 0.25,
|
||||
|
|
Loading…
Reference in New Issue