Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1980930: Update the default durations for MAO leader election operations #890

Merged
merged 1 commit into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 0 additions & 7 deletions cmd/machine-api-operator/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ import (
)

const (
// LeaseDuration is the default duration for the leader election lease.
LeaseDuration = 90 * time.Second
// RenewDeadline is the default duration for the leader renewal.
RenewDeadline = 60 * time.Second
// RetryPeriod is the default duration for the leader electrion retrial.
RetryPeriod = 30 * time.Second

minResyncPeriod = 10 * time.Minute
)

Expand Down
7 changes: 4 additions & 3 deletions cmd/machine-api-operator/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
osconfigv1 "github.com/openshift/api/config/v1"
"github.com/openshift/machine-api-operator/pkg/metrics"
"github.com/openshift/machine-api-operator/pkg/operator"
"github.com/openshift/machine-api-operator/pkg/util"
"github.com/openshift/machine-api-operator/pkg/version"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -73,9 +74,9 @@ func runStartCmd(cmd *cobra.Command, args []string) {

leaderelection.RunOrDie(context.TODO(), leaderelection.LeaderElectionConfig{
Lock: CreateResourceLock(cb, componentNamespace, componentName),
LeaseDuration: LeaseDuration,
RenewDeadline: RenewDeadline,
RetryPeriod: RetryPeriod,
LeaseDuration: util.LeaseDuration,
RenewDeadline: util.RenewDeadline,
RetryPeriod: util.RetryPeriod,
Callbacks: leaderelection.LeaderCallbacks{
OnStartedLeading: func(ctx context.Context) {
ctrlCtx := CreateControllerContext(cb, stopCh, componentNamespace)
Expand Down
16 changes: 4 additions & 12 deletions cmd/machine-healthcheck/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package main
import (
"flag"
"runtime"
"time"

"github.com/openshift/machine-api-operator/pkg/controller/machinehealthcheck"
"github.com/openshift/machine-api-operator/pkg/metrics"
"github.com/openshift/machine-api-operator/pkg/util"

mapiv1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
"github.com/openshift/machine-api-operator/pkg/controller"
Expand All @@ -19,13 +19,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
)

// The default durations for the leader electrion operations.
var (
leaseDuration = 120 * time.Second
renewDealine = 110 * time.Second
retryPeriod = 90 * time.Second
)

func printVersion() {
klog.Infof("Go Version: %s", runtime.Version())
klog.Infof("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
Expand Down Expand Up @@ -65,7 +58,7 @@ func main() {

leaderElectLeaseDuration := flag.Duration(
"leader-elect-lease-duration",
leaseDuration,
util.LeaseDuration,
"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.",
)

Expand All @@ -86,9 +79,8 @@ func main() {
LeaderElectionNamespace: *leaderElectResourceNamespace,
LeaderElectionID: "cluster-api-provider-healthcheck-leader",
LeaseDuration: leaderElectLeaseDuration,
// Slow the default retry and renew election rate to reduce etcd writes at idle: BZ 1858400
RetryPeriod: &retryPeriod,
RenewDeadline: &renewDealine,
RetryPeriod: util.TimeDuration(util.RetryPeriod),
RenewDeadline: util.TimeDuration(util.RenewDeadline),
}

if *watchNamespace != "" {
Expand Down
15 changes: 4 additions & 11 deletions cmd/machineset/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/openshift/machine-api-operator/pkg/controller"
"github.com/openshift/machine-api-operator/pkg/controller/machineset"
"github.com/openshift/machine-api-operator/pkg/metrics"
"github.com/openshift/machine-api-operator/pkg/util"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client/config"
Expand All @@ -39,13 +40,6 @@ const (
defaultWebhookCertdir = "/etc/machine-api-operator/tls"
)

// The default durations for the leader electrion operations.
var (
leaseDuration = 120 * time.Second
renewDealine = 110 * time.Second
retryPeriod = 90 * time.Second
)

func main() {
flag.Set("logtostderr", "true")
klog.InitFlags(nil)
Expand Down Expand Up @@ -82,7 +76,7 @@ func main() {

leaderElectLeaseDuration := flag.Duration(
"leader-elect-lease-duration",
leaseDuration,
util.LeaseDuration,
"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.",
)

Expand All @@ -109,9 +103,8 @@ func main() {
LeaderElectionNamespace: *leaderElectResourceNamespace,
LeaderElectionID: "cluster-api-provider-machineset-leader",
LeaseDuration: leaderElectLeaseDuration,
// Slow the default retry and renew election rate to reduce etcd writes at idle: BZ 1858400
RetryPeriod: &retryPeriod,
RenewDeadline: &renewDealine,
RetryPeriod: util.TimeDuration(util.RetryPeriod),
RenewDeadline: util.TimeDuration(util.RenewDeadline),
}

mgr, err := manager.New(cfg, opts)
Expand Down
16 changes: 4 additions & 12 deletions cmd/nodelink-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@ package main
import (
"flag"
"runtime"
"time"

mapiv1 "github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
"github.com/openshift/machine-api-operator/pkg/controller"
"github.com/openshift/machine-api-operator/pkg/controller/nodelink"
"github.com/openshift/machine-api-operator/pkg/util"
sdkVersion "github.com/operator-framework/operator-sdk/version"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
)

// The default durations for the leader electrion operations.
var (
leaseDuration = 120 * time.Second
renewDealine = 110 * time.Second
retryPeriod = 90 * time.Second
)

func printVersion() {
klog.Infof("Go Version: %s", runtime.Version())
klog.Infof("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
Expand Down Expand Up @@ -51,7 +44,7 @@ func main() {

leaderElectLeaseDuration := flag.Duration(
"leader-elect-lease-duration",
leaseDuration,
util.LeaseDuration,
"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.",
)

Expand All @@ -72,9 +65,8 @@ func main() {
LeaderElectionNamespace: *leaderElectResourceNamespace,
LeaderElectionID: "cluster-api-provider-nodelink-leader",
LeaseDuration: leaderElectLeaseDuration,
// Slow the default retry and renew election rate to reduce etcd writes at idle: BZ 1858400
RetryPeriod: &retryPeriod,
RenewDeadline: &renewDealine,
RetryPeriod: util.TimeDuration(util.RetryPeriod),
RenewDeadline: util.TimeDuration(util.RenewDeadline),
}
if *watchNamespace != "" {
opts.Namespace = *watchNamespace
Expand Down
15 changes: 4 additions & 11 deletions cmd/vsphere/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
machine "github.com/openshift/machine-api-operator/pkg/controller/vsphere"
machinesetcontroller "github.com/openshift/machine-api-operator/pkg/controller/vsphere/machineset"
"github.com/openshift/machine-api-operator/pkg/metrics"
"github.com/openshift/machine-api-operator/pkg/util"
"github.com/openshift/machine-api-operator/pkg/version"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
Expand All @@ -23,13 +24,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/manager"
)

// The default durations for the leader electrion operations.
var (
leaseDuration = 120 * time.Second
renewDealine = 110 * time.Second
retryPeriod = 90 * time.Second
)

func main() {
var printVersion bool
flag.BoolVar(&printVersion, "version", false, "print version and exit")
Expand All @@ -55,7 +49,7 @@ func main() {

leaderElectLeaseDuration := flag.Duration(
"leader-elect-lease-duration",
leaseDuration,
util.LeaseDuration,
"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.",
)

Expand Down Expand Up @@ -89,9 +83,8 @@ func main() {
LeaderElectionNamespace: *leaderElectResourceNamespace,
LeaderElectionID: "cluster-api-provider-vsphere-leader",
LeaseDuration: leaderElectLeaseDuration,
// Slow the default retry and renew election rate to reduce etcd writes at idle: BZ 1858400
RetryPeriod: &retryPeriod,
RenewDeadline: &renewDealine,
RetryPeriod: util.TimeDuration(util.RetryPeriod),
RenewDeadline: util.TimeDuration(util.RenewDeadline),
}

if *watchNamespace != "" {
Expand Down
36 changes: 36 additions & 0 deletions pkg/util/durations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2021 Red Hat.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package util

import (
"time"
)

// The default durations for the leader election operations.
const (
// LeaseDuration is the default duration for the leader election lease.
LeaseDuration = 137 * time.Second
// RenewDeadline is the default duration for the leader renewal.
RenewDeadline = 107 * time.Second
// RetryPeriod is the default duration for the leader election retrial.
RetryPeriod = 26 * time.Second
)

// TimeDuration returns a pointer to the time.Duration.
func TimeDuration(i time.Duration) *time.Duration {
return &i
}