@@ -29,10 +29,7 @@ func main() {
29
29
keyPath : env ("TLS_KEY" ),
30
30
}
31
31
32
- port , err := port ("HTTPS_PORT" )
33
- if err != nil {
34
- panic (err )
35
- }
32
+ port := env_int ("HTTPS_PORT" , 443 )
36
33
37
34
if err = webhook .start (port , tlsConfig , nil ); err != nil {
38
35
panic (err )
@@ -83,19 +80,38 @@ func createKubeClient() (*kubeClient, error) {
83
80
return nil , err
84
81
}
85
82
83
+ config .QPS = env_float ("QPS" , rest .DefaultQPS )
84
+ config .Burst = env_int ("BURST" , rest .DefaultBurst )
85
+ logrus .Infof ("QPS: %f, Burst: %d" , config .QPS , config .Burst )
86
+
86
87
return newKubeClient (config )
87
88
}
88
89
90
+ func env_float (key string , defaultFloat float32 ) float32 {
91
+ if v , found := os .LookupEnv (key ); found {
92
+ if i , err := strconv .ParseFloat (v , 32 ); err != nil {
93
+ return float32 (i )
94
+ }
95
+ logrus .Warningf ("unable to parse environment variable %s; using default value %f" , key , defaultFloat )
96
+ }
97
+
98
+ return defaultFloat
99
+ }
100
+
101
+ func env_int (key string , defaultInt int ) int {
102
+ if v , found := os .LookupEnv (key ); found {
103
+ if i , err := strconv .Atoi (v ); err != nil {
104
+ return i
105
+ }
106
+ logrus .Warningf ("unable to parse environment variable %s; using default value %d" , key , defaultInt )
107
+ }
108
+
109
+ return defaultInt
110
+ }
111
+
89
112
func env (key string ) string {
90
113
if value , found := os .LookupEnv (key ); found {
91
114
return value
92
115
}
93
116
panic (fmt .Errorf ("%s env var not found" , key ))
94
117
}
95
-
96
- func port (key string ) (int , error ) {
97
- if port , found := os .LookupEnv (key ); found {
98
- return strconv .Atoi (port )
99
- }
100
- return 443 , nil
101
- }
0 commit comments