Skip to content

Commit

Permalink
Disable HTTP2 in webhooks
Browse files Browse the repository at this point in the history
Jira: OSPRH-468
  • Loading branch information
dprince authored and openshift-merge-bot[bot] committed Nov 8, 2023
1 parent 2ab8917 commit 482a242
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package main

import (
"crypto/tls"
"flag"
"os"
"strings"
Expand Down Expand Up @@ -62,6 +63,8 @@ func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var enableHTTP2 bool
flag.BoolVar(&enableHTTP2, "enable-http2", enableHTTP2, "If HTTP/2 should be enabled for the metrics and webhook servers.")
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
Expand All @@ -76,6 +79,13 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

disableHTTP2 := func(c *tls.Config) {
if enableHTTP2 {
return
}
c.NextProtos = []string{"http/1.1"}
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Expand Down Expand Up @@ -116,6 +126,10 @@ func main() {
checker := healthz.Ping
// Setup webhooks if requested
if strings.ToLower(os.Getenv("ENABLE_WEBHOOKS")) != "false" {
// overriding the default values
srv := mgr.GetWebhookServer()
srv.TLSOpts = []func(config *tls.Config){disableHTTP2}

if err = (&placementv1.PlacementAPI{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "PlacementAPI")
os.Exit(1)
Expand Down

0 comments on commit 482a242

Please sign in to comment.