mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-05-21 08:33:49 +00:00
make LeaseDuration/RenewDeadline/RetryPeriod configuable (#306)
Signed-off-by: ldpliu <daliu@redhat.com>
This commit is contained in:
2
go.mod
2
go.mod
@@ -8,7 +8,7 @@ require (
|
||||
github.com/onsi/gomega v1.27.4
|
||||
github.com/openshift/api v0.0.0-20230223193310-d964c7a58d75
|
||||
github.com/openshift/build-machinery-go v0.0.0-20230306181456-d321ffa04533
|
||||
github.com/openshift/library-go v0.0.0-20230308200407-f3277c772011
|
||||
github.com/openshift/library-go v0.0.0-20230321160537-6ac65c5454f9
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/spf13/cobra v1.6.1
|
||||
github.com/spf13/pflag v1.0.5
|
||||
|
||||
4
go.sum
4
go.sum
@@ -429,8 +429,8 @@ github.com/openshift/build-machinery-go v0.0.0-20230306181456-d321ffa04533 h1:mh
|
||||
github.com/openshift/build-machinery-go v0.0.0-20230306181456-d321ffa04533/go.mod h1:b1BuldmJlbA/xYtdZvKi+7j5YGB44qJUJDZ9zwiNCfE=
|
||||
github.com/openshift/client-go v0.0.0-20230120202327-72f107311084 h1:66uaqNwA+qYyQDwsMWUfjjau8ezmg1dzCqub13KZOcE=
|
||||
github.com/openshift/client-go v0.0.0-20230120202327-72f107311084/go.mod h1:M3h9m001PWac3eAudGG3isUud6yBjr5XpzLYLLTlHKo=
|
||||
github.com/openshift/library-go v0.0.0-20230308200407-f3277c772011 h1:RL6hf0cNc9uVZXQkU74a/J91XEo5iip2mWvJTwKgMg4=
|
||||
github.com/openshift/library-go v0.0.0-20230308200407-f3277c772011/go.mod h1:OspkL5FZZapzNcka6UkNMFD7ifLT/dWUNvtwErpRK9k=
|
||||
github.com/openshift/library-go v0.0.0-20230321160537-6ac65c5454f9 h1:rvW82DYmdWlJa64YYSj7Fm/xFP07Pztr9GSQekWeoMo=
|
||||
github.com/openshift/library-go v0.0.0-20230321160537-6ac65c5454f9/go.mod h1:OspkL5FZZapzNcka6UkNMFD7ifLT/dWUNvtwErpRK9k=
|
||||
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package hub
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/openshift/library-go/pkg/controller/controllercmd"
|
||||
@@ -11,13 +13,28 @@ import (
|
||||
)
|
||||
|
||||
func NewController() *cobra.Command {
|
||||
cmd := controllercmd.
|
||||
NewControllerCommandConfig("registration-controller", version.Get(), hub.RunControllerManager).
|
||||
NewCommand()
|
||||
cmdConfig := controllercmd.
|
||||
NewControllerCommandConfig("registration-controller", version.Get(), hub.RunControllerManager)
|
||||
cmd := cmdConfig.NewCommand()
|
||||
cmd.Use = "controller"
|
||||
cmd.Short = "Start the Cluster Registration Controller"
|
||||
|
||||
flags := cmd.Flags()
|
||||
|
||||
flags.DurationVar(&cmdConfig.LeaseDuration.Duration, "leader-election-lease-duration", 137*time.Second, ""+
|
||||
"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(&cmdConfig.RenewDeadline.Duration, "leader-election-renew-deadline", 107*time.Second, ""+
|
||||
"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(&cmdConfig.RetryPeriod.Duration, "leader-election-retry-period", 26*time.Second, ""+
|
||||
"The duration the clients should wait between attempting acquisition and renewal "+
|
||||
"of a leadership. This is only applicable if leader election is enabled.")
|
||||
|
||||
features.DefaultHubMutableFeatureGate.AddFlag(flags)
|
||||
|
||||
return cmd
|
||||
|
||||
11
vendor/github.com/openshift/library-go/pkg/config/leaderelection/leaderelection.go
generated
vendored
11
vendor/github.com/openshift/library-go/pkg/config/leaderelection/leaderelection.go
generated
vendored
@@ -3,6 +3,7 @@ package leaderelection
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -116,6 +117,16 @@ func LeaderElectionDefaulting(config configv1.LeaderElection, defaultNamespace,
|
||||
if ret.RetryPeriod.Duration == 0 {
|
||||
ret.RetryPeriod.Duration = 26 * time.Second
|
||||
}
|
||||
|
||||
retryTimes := int(math.Floor(float64(ret.RenewDeadline.Duration / ret.RetryPeriod.Duration)))
|
||||
klog.Infof("The leader election gives %v retries and allows for %v of clock skew. The kube-apiserver downtime tolerance is %vs. Worst non-graceful lease acquisition is %v. Worst graceful lease acquisition is %v.",
|
||||
retryTimes,
|
||||
ret.LeaseDuration.Duration-ret.RenewDeadline.Duration,
|
||||
(retryTimes-1)*(int(ret.RetryPeriod.Duration.Seconds())),
|
||||
ret.LeaseDuration.Duration+ret.RetryPeriod.Duration,
|
||||
ret.RetryPeriod,
|
||||
)
|
||||
|
||||
if len(ret.Namespace) == 0 {
|
||||
if len(defaultNamespace) > 0 {
|
||||
ret.Namespace = defaultNamespace
|
||||
|
||||
17
vendor/github.com/openshift/library-go/pkg/controller/controllercmd/cmd.go
generated
vendored
17
vendor/github.com/openshift/library-go/pkg/controller/controllercmd/cmd.go
generated
vendored
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
@@ -46,6 +47,19 @@ type ControllerCommandConfig struct {
|
||||
// DisableLeaderElection allows leader election to be suspended
|
||||
DisableLeaderElection bool
|
||||
|
||||
// LeaseDuration is the duration that non-leader candidates will
|
||||
// wait to force acquire leadership. This is measured against time of
|
||||
// last observed ack.
|
||||
LeaseDuration metav1.Duration
|
||||
|
||||
// RenewDeadline is the duration that the acting controlplane will retry
|
||||
// refreshing leadership before giving up.
|
||||
RenewDeadline metav1.Duration
|
||||
|
||||
// RetryPeriod is the duration the LeaderElector clients should wait
|
||||
// between tries of actions.
|
||||
RetryPeriod metav1.Duration
|
||||
|
||||
ComponentOwnerReference *corev1.ObjectReference
|
||||
}
|
||||
|
||||
@@ -277,6 +291,9 @@ func (c *ControllerCommandConfig) StartController(ctx context.Context) error {
|
||||
}()
|
||||
|
||||
config.LeaderElection.Disable = c.DisableLeaderElection
|
||||
config.LeaderElection.LeaseDuration = c.LeaseDuration
|
||||
config.LeaderElection.RenewDeadline = c.RenewDeadline
|
||||
config.LeaderElection.RetryPeriod = c.RetryPeriod
|
||||
|
||||
builder := NewController(c.componentName, c.startFunc).
|
||||
WithKubeConfigFile(c.basicFlags.KubeConfigFile, nil).
|
||||
|
||||
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@@ -286,7 +286,7 @@ github.com/openshift/client-go/config/applyconfigurations/config/v1
|
||||
github.com/openshift/client-go/config/applyconfigurations/internal
|
||||
github.com/openshift/client-go/config/clientset/versioned/scheme
|
||||
github.com/openshift/client-go/config/clientset/versioned/typed/config/v1
|
||||
# github.com/openshift/library-go v0.0.0-20230308200407-f3277c772011
|
||||
# github.com/openshift/library-go v0.0.0-20230321160537-6ac65c5454f9
|
||||
## explicit; go 1.19
|
||||
github.com/openshift/library-go/pkg/assets
|
||||
github.com/openshift/library-go/pkg/authorization/hardcodedauthorizer
|
||||
|
||||
Reference in New Issue
Block a user