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

24 changes: 19 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"go.uber.org/zap/zapcore"
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/tools/leaderelection/resourcelock"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -75,8 +76,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 +120,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 +149,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 +221,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: resourcelock.LeasesResourceLock,
RenewDeadline: &renewDeadline,
LeaseDuration: &leaseDuration,
RetryPeriod: &leaderRetryDuration,
}
if configFile != "" {
options, err = options.AndFrom(ctrl.ConfigFile().AtPath(configFile).OfKind(&ctrlConfig))
Expand Down