Skip to content
This repository is currently being migrated. It's locked while the migration is in progress.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ const (
)

var (
scheme = runtime.NewScheme()
shutDownperiod = time.Second * 5
scheme = runtime.NewScheme()
shutDownperiod = time.Second * 5
leaderRetryDuration = 5 * time.Second
)

func init() {
Expand Down Expand Up @@ -118,12 +119,15 @@ func main() {
}
}()

var err error
var configFile string
flag.StringVar(&configFile, "config", "",
"The controller will load its initial configuration from this file. "+
"Omit this flag to use the default configuration values. "+
"Command-line flags override configuration from this file.")

var leaderRenewSeconds uint
flag.UintVar(&leaderRenewSeconds, "leader-renew-seconds", 10, "Leader renewal frequency")

flag.Parse()

verbosity := 3 // TODO make this configurable 1-5 (5 is a security risk)
Expand All @@ -144,6 +148,8 @@ func main() {
logger := ctrl.Log.WithName("portal_manager")
setupLogger := logger.WithName("setup")

var err error

currentNS := os.Getenv(podNamespace)
if len(currentNS) == 0 {
err = errors.New("current namespace not found")
Expand Down Expand Up @@ -214,9 +220,16 @@ func main() {
}
ctrlConfig.IOTCore = iotConfig

renewDeadline := time.Duration(leaderRenewSeconds) * time.Second
leaseDuration := time.Duration(int(1.2*float64(leaderRenewSeconds))) * time.Second

options := ctrl.Options{
Scheme: scheme,
LeaderElectionID: "storageos-portal-manager-leader",
Scheme: scheme,
LeaderElectionID: "storageos-portal-manager-leader",
LeaderElectionResourceLock: "leases",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I believe you can use the constant k8s.io/client-go/tools/leaderelection/resourcelock. LeasesResourceLock

RenewDeadline: &renewDeadline,
LeaseDuration: &leaseDuration,
RetryPeriod: &leaderRetryDuration,
}
if configFile != "" {
options, err = options.AndFrom(ctrl.ConfigFile().AtPath(configFile).OfKind(&ctrlConfig))
Expand Down