58 lines
2.0 KiB
Go
58 lines
2.0 KiB
Go
package options
|
|
|
|
import (
|
|
"time"
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/client-go/rest"
|
|
"k8s.io/client-go/tools/leaderelection/resourcelock"
|
|
componentbaseconfig "k8s.io/component-base/config"
|
|
"k8s.io/klog/v2"
|
|
)
|
|
|
|
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 {
|
|
KubeConfig *rest.Config
|
|
HostNamespace string
|
|
LeaderElection componentbaseconfig.LeaderElectionConfiguration
|
|
}
|
|
|
|
// NewOptions builds an empty options.
|
|
func NewOptions() *Options {
|
|
return &Options{}
|
|
}
|
|
|
|
// Complete fills in any fields not set that are required to have valid data. It's mutating the receiver.
|
|
func (o *Options) Complete() {
|
|
if len(o.HostNamespace) == 0 {
|
|
o.HostNamespace = "default"
|
|
klog.Infof("Set default value: Options.HostNamespace = %s", "default")
|
|
}
|
|
|
|
if len(o.LeaderElection.ResourceLock) == 0 {
|
|
o.LeaderElection.ResourceLock = resourcelock.EndpointsLeasesResourceLock
|
|
klog.Infof("Set default value: Options.LeaderElection.ResourceLock = %s", resourcelock.EndpointsLeasesResourceLock)
|
|
}
|
|
|
|
if o.LeaderElection.LeaseDuration.Duration.Seconds() == 0 {
|
|
o.LeaderElection.LeaseDuration = defaultElectionLeaseDuration
|
|
klog.Infof("Set default value: Options.LeaderElection.LeaseDuration = %s", defaultElectionLeaseDuration.Duration.String())
|
|
}
|
|
|
|
if o.LeaderElection.RenewDeadline.Duration.Seconds() == 0 {
|
|
o.LeaderElection.RenewDeadline = defaultElectionRenewDeadline
|
|
klog.Infof("Set default value: Options.LeaderElection.RenewDeadline = %s", defaultElectionRenewDeadline.Duration.String())
|
|
}
|
|
|
|
if o.LeaderElection.RetryPeriod.Duration.Seconds() == 0 {
|
|
o.LeaderElection.RetryPeriod = defaultElectionRetryPeriod
|
|
klog.Infof("Set default value: Options.LeaderElection.RetryPeriod = %s", defaultElectionRetryPeriod.Duration.String())
|
|
}
|
|
}
|