15
15
package flags
16
16
17
17
import (
18
+ "crypto/tls"
18
19
"runtime"
19
20
"time"
20
21
21
22
"github.com/spf13/pflag"
22
23
"k8s.io/client-go/tools/leaderelection/resourcelock"
23
24
"sigs.k8s.io/controller-runtime/pkg/manager"
25
+ "sigs.k8s.io/controller-runtime/pkg/webhook"
24
26
)
25
27
26
28
// Flags - Options to be used by an ansible operator
@@ -44,6 +46,8 @@ type Flags struct {
44
46
AnsibleArgs string
45
47
AnsibleLogEvents string
46
48
ProxyPort int
49
+ EnableHTTP2 bool
50
+ SecureMetrics bool
47
51
48
52
// Path to a controller-runtime componentconfig file.
49
53
// If this is empty, use default values.
@@ -197,6 +201,17 @@ func (f *Flags) AddTo(flagSet *pflag.FlagSet) {
197
201
8888 ,
198
202
"Ansible proxy server port. Defaults to 8888." ,
199
203
)
204
+ flagSet .BoolVar (& f .EnableHTTP2 ,
205
+ "enable-http2" ,
206
+ false ,
207
+ "enables HTTP/2 on the webhook and metrics servers" ,
208
+ )
209
+
210
+ flagSet .BoolVar (& f .SecureMetrics ,
211
+ "metrics-secure" ,
212
+ false ,
213
+ "enables secure serving of the metrics endpoint" ,
214
+ )
200
215
}
201
216
202
217
// ToManagerOptions uses the flag set in f to configure options.
@@ -241,5 +256,15 @@ func (f *Flags) ToManagerOptions(options manager.Options) manager.Options {
241
256
options .GracefulShutdownTimeout = & f .GracefulShutdownTimeout
242
257
}
243
258
259
+ disableHTTP2 := func (c * tls.Config ) {
260
+ c .NextProtos = []string {"http/1.1" }
261
+ }
262
+ if ! f .EnableHTTP2 {
263
+ options .WebhookServer = webhook .NewServer (webhook.Options {
264
+ TLSOpts : []func (* tls.Config ){disableHTTP2 },
265
+ })
266
+ options .Metrics .TLSOpts = append (options .Metrics .TLSOpts , disableHTTP2 )
267
+ }
268
+ options .Metrics .SecureServing = f .SecureMetrics
244
269
return options
245
270
}
0 commit comments