Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cmd/machine-api-operator/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ func runStartCmd(cmd *cobra.Command, args []string) {
}
stopCh := make(chan struct{})

le := util.GetLeaderElectionConfig(cb.config, osconfigv1.LeaderElection{})

leaderelection.RunOrDie(context.TODO(), leaderelection.LeaderElectionConfig{
Lock: CreateResourceLock(cb, componentNamespace, componentName),
LeaseDuration: util.LeaseDuration,
RenewDeadline: util.RenewDeadline,
RetryPeriod: util.RetryPeriod,
RenewDeadline: le.RenewDeadline.Duration,
RetryPeriod: le.RetryPeriod.Duration,
LeaseDuration: le.LeaseDuration.Duration,
Callbacks: leaderelection.LeaderCallbacks{
OnStartedLeading: func(ctx context.Context) {
ctrlCtx := CreateControllerContext(cb, stopCh, componentNamespace)
Expand Down
26 changes: 21 additions & 5 deletions cmd/machine-healthcheck/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ package main

import (
"flag"
"fmt"
"runtime"

"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"

osconfigv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/api/machine/v1beta1"
"github.com/openshift/library-go/pkg/config/leaderelection"

"github.com/openshift/machine-api-operator/pkg/controller"
sdkVersion "github.com/operator-framework/operator-sdk/version"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client/config"
Expand All @@ -27,6 +31,12 @@ func printVersion() {
}

func main() {
// Used to get the default values for leader election from library-go
defaultLeaderElectionValues := leaderelection.LeaderElectionDefaulting(
osconfigv1.LeaderElection{},
"", "",
)

watchNamespace := flag.String(
"namespace",
"",
Expand Down Expand Up @@ -57,10 +67,11 @@ func main() {
"Start a leader election client and gain leadership before executing the main loop. Enable this when running replicated components for high availability.",
)

// Default values are printed for the user to see, but zero is set as the default to distinguish user intent from default value for topology aware leader election
leaderElectLeaseDuration := flag.Duration(
"leader-elect-lease-duration",
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.",
0,
fmt.Sprintf("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. Default: (%s)", defaultLeaderElectionValues.LeaseDuration.Duration),
)

klog.InitFlags(nil)
Expand All @@ -73,15 +84,20 @@ func main() {
klog.Fatal(err)
}

le := util.GetLeaderElectionConfig(cfg, osconfigv1.LeaderElection{
Disable: !*leaderElect,
LeaseDuration: metav1.Duration{Duration: *leaderElectLeaseDuration},
})

opts := manager.Options{
MetricsBindAddress: *metricsAddress,
HealthProbeBindAddress: *healthAddr,
LeaderElection: *leaderElect,
LeaderElectionNamespace: *leaderElectResourceNamespace,
LeaderElectionID: "cluster-api-provider-healthcheck-leader",
LeaseDuration: leaderElectLeaseDuration,
RetryPeriod: util.TimeDuration(util.RetryPeriod),
RenewDeadline: util.TimeDuration(util.RenewDeadline),
LeaseDuration: &le.LeaseDuration.Duration,
RetryPeriod: &le.RetryPeriod.Duration,
RenewDeadline: &le.RenewDeadline.Duration,
}

if *watchNamespace != "" {
Expand Down
26 changes: 21 additions & 5 deletions cmd/machineset/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@ package main

import (
"flag"
"fmt"
"log"
"time"

osconfigv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/api/machine/v1beta1"
"github.com/openshift/library-go/pkg/config/leaderelection"
"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"
mapiwebhooks "github.com/openshift/machine-api-operator/pkg/webhooks"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client/config"
Expand All @@ -42,6 +46,12 @@ const (
)

func main() {
// Used to get the default values for leader election from library-go
defaultLeaderElectionValues := leaderelection.LeaderElectionDefaulting(
osconfigv1.LeaderElection{},
"", "",
)

flag.Set("logtostderr", "true")
klog.InitFlags(nil)
watchNamespace := flag.String("namespace", "",
Expand Down Expand Up @@ -75,10 +85,11 @@ func main() {
"Start a leader election client and gain leadership before executing the main loop. Enable this when running replicated components for high availability.",
)

// Default values are printed for the user to see, but zero is set as the default to distinguish user intent from default value for topology aware leader election
leaderElectLeaseDuration := flag.Duration(
"leader-elect-lease-duration",
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.",
0,
fmt.Sprintf("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. Default: (%s)", defaultLeaderElectionValues.LeaseDuration.Duration),
)

flag.Parse()
Expand All @@ -93,6 +104,11 @@ func main() {
log.Fatal(err)
}

le := util.GetLeaderElectionConfig(cfg, osconfigv1.LeaderElection{
Disable: !*leaderElect,
LeaseDuration: metav1.Duration{Duration: *leaderElectLeaseDuration},
})

// Create a new Cmd to provide shared dependencies and start components
syncPeriod := 10 * time.Minute
opts := manager.Options{
Expand All @@ -103,9 +119,9 @@ func main() {
LeaderElection: *leaderElect,
LeaderElectionNamespace: *leaderElectResourceNamespace,
LeaderElectionID: "cluster-api-provider-machineset-leader",
LeaseDuration: leaderElectLeaseDuration,
RetryPeriod: util.TimeDuration(util.RetryPeriod),
RenewDeadline: util.TimeDuration(util.RenewDeadline),
LeaseDuration: &le.LeaseDuration.Duration,
RetryPeriod: &le.RetryPeriod.Duration,
RenewDeadline: &le.RenewDeadline.Duration,
}

mgr, err := manager.New(cfg, opts)
Expand Down
26 changes: 21 additions & 5 deletions cmd/nodelink-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package main

import (
"flag"
"fmt"
"runtime"

osconfigv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/api/machine/v1beta1"
"github.com/openshift/library-go/pkg/config/leaderelection"
"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"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand All @@ -24,6 +28,12 @@ func printVersion() {
func main() {
printVersion()

// Used to get the default values for leader election from library-go
defaultLeaderElectionValues := leaderelection.LeaderElectionDefaulting(
osconfigv1.LeaderElection{},
"", "",
)

watchNamespace := flag.String(
"namespace",
"",
Expand All @@ -42,10 +52,11 @@ func main() {
"Start a leader election client and gain leadership before executing the main loop. Enable this when running replicated components for high availability.",
)

// Default values are printed for the user to see, but zero is set as the default to distinguish user intent from default value for topology aware leader election
leaderElectLeaseDuration := flag.Duration(
"leader-elect-lease-duration",
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.",
0,
fmt.Sprintf("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. Default: (%s)", defaultLeaderElectionValues.LeaseDuration.Duration),
)

klog.InitFlags(nil)
Expand All @@ -58,15 +69,20 @@ func main() {
klog.Fatal(err)
}

le := util.GetLeaderElectionConfig(cfg, osconfigv1.LeaderElection{
Disable: !*leaderElect,
LeaseDuration: metav1.Duration{Duration: *leaderElectLeaseDuration},
})

opts := manager.Options{
// Disable metrics serving
MetricsBindAddress: "0",
LeaderElection: *leaderElect,
LeaderElectionNamespace: *leaderElectResourceNamespace,
LeaderElectionID: "cluster-api-provider-nodelink-leader",
LeaseDuration: leaderElectLeaseDuration,
RetryPeriod: util.TimeDuration(util.RetryPeriod),
RenewDeadline: util.TimeDuration(util.RenewDeadline),
LeaseDuration: &le.LeaseDuration.Duration,
RetryPeriod: &le.RetryPeriod.Duration,
RenewDeadline: &le.RenewDeadline.Duration,
}
if *watchNamespace != "" {
opts.Namespace = *watchNamespace
Expand Down
24 changes: 19 additions & 5 deletions cmd/vsphere/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (

configv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/api/machine/v1beta1"
"github.com/openshift/library-go/pkg/config/leaderelection"
capimachine "github.com/openshift/machine-api-operator/pkg/controller/machine"
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"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -27,6 +29,12 @@ func main() {
var printVersion bool
flag.BoolVar(&printVersion, "version", false, "print version and exit")

// Used to get the default values for leader election from library-go
defaultLeaderElectionValues := leaderelection.LeaderElectionDefaulting(
configv1.LeaderElection{},
"", "",
)

klog.InitFlags(nil)
watchNamespace := flag.String(
"namespace",
Expand All @@ -46,10 +54,11 @@ func main() {
"Start a leader election client and gain leadership before executing the main loop. Enable this when running replicated components for high availability.",
)

// Default values are printed for the user to see, but zero is set as the default to distinguish user intent from default value for topology aware leader election
leaderElectLeaseDuration := flag.Duration(
"leader-elect-lease-duration",
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.",
0,
fmt.Sprintf("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. Default: (%s)", defaultLeaderElectionValues.LeaseDuration.Duration),
)

metricsAddress := flag.String(
Expand All @@ -74,16 +83,21 @@ func main() {
cfg := config.GetConfigOrDie()
syncPeriod := 10 * time.Minute

le := util.GetLeaderElectionConfig(cfg, configv1.LeaderElection{
Disable: !*leaderElect,
LeaseDuration: metav1.Duration{Duration: *leaderElectLeaseDuration},
})

opts := manager.Options{
MetricsBindAddress: *metricsAddress,
HealthProbeBindAddress: *healthAddr,
SyncPeriod: &syncPeriod,
LeaderElection: *leaderElect,
LeaderElectionNamespace: *leaderElectResourceNamespace,
LeaderElectionID: "cluster-api-provider-vsphere-leader",
LeaseDuration: leaderElectLeaseDuration,
RetryPeriod: util.TimeDuration(util.RetryPeriod),
RenewDeadline: util.TimeDuration(util.RenewDeadline),
LeaseDuration: &le.LeaseDuration.Duration,
RetryPeriod: &le.RetryPeriod.Duration,
RenewDeadline: &le.RenewDeadline.Duration,
}

if *watchNamespace != "" {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/onsi/gomega v1.17.0
github.com/openshift/api v0.0.0-20211215120111-7c47a5f63470
github.com/openshift/client-go v0.0.0-20211209144617-7385dd6338e3
github.com/openshift/library-go v0.0.0-20211214183058-58531ccbde67
github.com/openshift/library-go v0.0.0-20211220195323-eca2c467c492
github.com/operator-framework/operator-sdk v0.5.1-0.20190301204940-c2efe6f74e7b
github.com/prometheus/client_golang v1.11.0
github.com/spf13/cobra v1.2.1
Expand Down Expand Up @@ -98,7 +98,7 @@ require (
k8s.io/component-base v0.23.0 // indirect
k8s.io/kube-aggregator v0.23.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/kube-storage-version-migrator v0.0.4 // indirect
sigs.k8s.io/kustomize/api v0.10.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.0 // indirect
Expand Down
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/RangelReale/osincli v0.0.0-20160924135400-fababb0555f2/go.mod h1:XyjUkMA8GN+tOOPXvnbi3XuRxWFvTJntqvTFnjmhzbk=
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down Expand Up @@ -537,12 +538,11 @@ github.com/openshift/api v0.0.0-20211209135129-c58d9f695577/go.mod h1:DoslCwtqUp
github.com/openshift/api v0.0.0-20211215120111-7c47a5f63470 h1:kYVTSbYsfLxSBnK8Z2ZN+qgAdclXAf2mYVDyHDfxTZ0=
github.com/openshift/api v0.0.0-20211215120111-7c47a5f63470/go.mod h1:F/eU6jgr6Q2VhMu1mSpMmygxAELd7+BUxs3NHZ25jV4=
github.com/openshift/build-machinery-go v0.0.0-20210712174854-1bb7fd1518d3/go.mod h1:b1BuldmJlbA/xYtdZvKi+7j5YGB44qJUJDZ9zwiNCfE=
github.com/openshift/build-machinery-go v0.0.0-20210806203541-4ea9b6da3a37/go.mod h1:b1BuldmJlbA/xYtdZvKi+7j5YGB44qJUJDZ9zwiNCfE=
github.com/openshift/build-machinery-go v0.0.0-20211213093930-7e33a7eb4ce3/go.mod h1:b1BuldmJlbA/xYtdZvKi+7j5YGB44qJUJDZ9zwiNCfE=
github.com/openshift/client-go v0.0.0-20211209144617-7385dd6338e3 h1:SG1aqwleU6bGD0X4mhkTNupjVnByMYYuW4XbnCPavQU=
github.com/openshift/client-go v0.0.0-20211209144617-7385dd6338e3/go.mod h1:cwhyki5lqBmrT0m8Im+9I7PGFaraOzcYPtEz93RcsGY=
github.com/openshift/library-go v0.0.0-20211214183058-58531ccbde67 h1:wNd5jvgf9kXsyT+z11aBlh5spqKPNwsQKplrJRx4nsc=
github.com/openshift/library-go v0.0.0-20211214183058-58531ccbde67/go.mod h1:M/Gi/GUUrMdSS07nrYtTiK43J6/VUAyk/+IfN4ZqUY4=
github.com/openshift/library-go v0.0.0-20211220195323-eca2c467c492 h1:oj/rSQqVWVj6YJUydZwLz2frrJreiyI4oa9g/YPgMsM=
github.com/openshift/library-go v0.0.0-20211220195323-eca2c467c492/go.mod h1:4UQ9snU1vg53fyTpHQw3vLPiAxI8ub5xrc+y8KPQQFs=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/operator-framework/operator-sdk v0.5.1-0.20190301204940-c2efe6f74e7b h1:Q1q8w51pAZdx6LEkaYdSbUaaEOHXTyTXLhtGgIiKaiA=
github.com/operator-framework/operator-sdk v0.5.1-0.20190301204940-c2efe6f74e7b/go.mod h1:iVyukRkam5JZa8AnjYf+/G3rk7JI1+M6GsU0sq0B9NA=
Expand Down Expand Up @@ -1271,9 +1271,8 @@ sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.25/go.mod h1:Mlj9PN
sigs.k8s.io/controller-runtime v0.11.0 h1:DqO+c8mywcZLFJWILq4iktoECTyn30Bkj0CwgqMpZWQ=
sigs.k8s.io/controller-runtime v0.11.0/go.mod h1:KKwLiTooNGu+JmLZGn9Sl3Gjmfj66eMbCQznLP5zcqA=
sigs.k8s.io/controller-tools v0.2.8/go.mod h1:9VKHPszmf2DHz/QmHkcfZoewO6BL7pPs9uAiBVsaJSE=
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 h1:fD1pz4yfdADVNfFmcP2aBEtudwUQ1AlLnRBALr33v3s=
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6/go.mod h1:p4QtZmO4uMYipTQNzagwnNoseA6OxSUutVw05NhYDRs=
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 h1:kDi4JBNAsJWfz1aEXhO8Jg87JJaPNLh5tIzYHgStQ9Y=
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2/go.mod h1:B+TnT182UBxE84DiCz4CVE26eOSDAeYCpfDnC2kdKMY=
sigs.k8s.io/kube-storage-version-migrator v0.0.4 h1:qsCecgZHgdismlTt8xCmS/3numvpxrj58RWJeIg76wc=
sigs.k8s.io/kube-storage-version-migrator v0.0.4/go.mod h1:mXfSLkx9xbJHQsgNDDUZK/iQTs2tMbx/hsJlWe6Fthw=
sigs.k8s.io/kustomize/api v0.10.1 h1:KgU7hfYoscuqag84kxtzKdEC3mKMb99DPI3a0eaV1d0=
Expand Down
36 changes: 0 additions & 36 deletions pkg/util/durations.go

This file was deleted.

Loading