Skip to content

Commit 3e8321f

Browse files
dvaldiviapjuarezd
andauthored
Have Sidecar reuse the same HTTP client and discard request body (#2213)
Signed-off-by: Daniel Valdivia <[email protected]> Co-authored-by: pjuarezd <[email protected]>
1 parent 334c691 commit 3e8321f

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

sidecar/pkg/sidecar/webhook_server.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package sidecar
1919
import (
2020
"crypto/tls"
2121
"fmt"
22+
"io"
2223
"net/http"
2324
"time"
2425

@@ -78,6 +79,14 @@ func configureProbesServer(c *Controller, tenantTLS bool) *http.Server {
7879
return s
7980
}
8081

82+
// we do insecure skip verify because we are checking against the local instance and don't care for the certificate
83+
var probeHTTPClient = &http.Client{
84+
Timeout: time.Millisecond * 500,
85+
Transport: &http.Transport{
86+
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
87+
},
88+
}
89+
8190
func readinessHandler(tenantTLS bool) func(w http.ResponseWriter, r *http.Request) {
8291
return func(w http.ResponseWriter, r *http.Request) {
8392
schema := "https"
@@ -92,21 +101,13 @@ func readinessHandler(tenantTLS bool) func(w http.ResponseWriter, r *http.Reques
92101
return
93102
}
94103

95-
// we do insecure skip verify because we are checking against the local instance and don't care for the
96-
// certificate
97-
client := &http.Client{
98-
Timeout: time.Millisecond * 500,
99-
Transport: &http.Transport{
100-
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
101-
},
102-
}
103-
104-
response, err := client.Do(request)
104+
response, err := probeHTTPClient.Do(request)
105105
if err != nil {
106106
http.Error(w, fmt.Sprintf("HTTP request failed: %s", err), http.StatusInternalServerError)
107107
return
108108
}
109109
defer response.Body.Close()
110+
_, _ = io.Copy(io.Discard, response.Body) // Discard body to enable connection reuse
110111

111112
if response.StatusCode == 403 {
112113
fmt.Fprintln(w, "Readiness probe succeeded.")

0 commit comments

Comments
 (0)