@@ -20,8 +20,11 @@ import (
2020 "context"
2121 "crypto/tls"
2222 "flag"
23+ "fmt"
2324 "os"
25+ "strconv"
2426 "strings"
27+ "time"
2528
2629 // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2730 // to ensure that exec-entrypoint and run can make use of them.
@@ -97,7 +100,7 @@ func main() {
97100 c .NextProtos = []string {"http/1.1" }
98101 }
99102
100- mgr , err := ctrl . NewManager ( ctrl . GetConfigOrDie (), ctrl.Options {
103+ options := ctrl.Options {
101104 Scheme : scheme ,
102105 Metrics : metricsserver.Options {
103106 BindAddress : metricsAddr ,
@@ -110,7 +113,24 @@ func main() {
110113 Port : 9443 ,
111114 TLSOpts : []func (config * tls.Config ){disableHTTP2 },
112115 }),
113- })
116+ }
117+
118+ if leaseDuration := getEnvInDuration ("LEASE_DURATION" ); leaseDuration != 0 {
119+ setupLog .Info ("manager configured with lease duration" , "seconds" , int (leaseDuration .Seconds ()))
120+ options .LeaseDuration = & leaseDuration
121+ }
122+
123+ if renewDeadline := getEnvInDuration ("RENEW_DEADLINE" ); renewDeadline != 0 {
124+ setupLog .Info ("manager configured with renew deadline" , "seconds" , int (renewDeadline .Seconds ()))
125+ options .RenewDeadline = & renewDeadline
126+ }
127+
128+ if retryPeriod := getEnvInDuration ("RETRY_PERIOD" ); retryPeriod != 0 {
129+ setupLog .Info ("manager configured with retry period" , "seconds" , int (retryPeriod .Seconds ()))
130+ options .RetryPeriod = & retryPeriod
131+ }
132+
133+ mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), options )
114134 if err != nil {
115135 setupLog .Error (err , "unable to start manager" )
116136 os .Exit (1 )
@@ -199,3 +219,15 @@ func main() {
199219 os .Exit (1 )
200220 }
201221}
222+
223+ func getEnvInDuration (envName string ) time.Duration {
224+ var durationInt int64
225+ if durationStr := os .Getenv (envName ); durationStr != "" {
226+ var err error
227+ if durationInt , err = strconv .ParseInt (durationStr , 10 , 64 ); err != nil {
228+ setupLog .Error (err , fmt .Sprintf ("unable to parse provided '%s'" , envName ))
229+ os .Exit (1 )
230+ }
231+ }
232+ return time .Duration (durationInt ) * time .Second
233+ }
0 commit comments