Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have Sidecar reuse the same HTTP client and discard request body #2213

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions sidecar/pkg/sidecar/webhook_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package sidecar
import (
"crypto/tls"
"fmt"
"io"
"net/http"
"time"

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

// we do insecure skip verify because we are checking against the local instance and don't care for the certificate
var probeHTTPClient = &http.Client{
Timeout: time.Millisecond * 500,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}

func readinessHandler(tenantTLS bool) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
schema := "https"
Expand All @@ -92,21 +101,13 @@ func readinessHandler(tenantTLS bool) func(w http.ResponseWriter, r *http.Reques
return
}

// we do insecure skip verify because we are checking against the local instance and don't care for the
// certificate
client := &http.Client{
Timeout: time.Millisecond * 500,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}

response, err := client.Do(request)
response, err := probeHTTPClient.Do(request)
if err != nil {
http.Error(w, fmt.Sprintf("HTTP request failed: %s", err), http.StatusInternalServerError)
return
}
defer response.Body.Close()
_, _ = io.Copy(io.Discard, response.Body) // Discard body to enable connection reuse

if response.StatusCode == 403 {
fmt.Fprintln(w, "Readiness probe succeeded.")
Expand Down
Loading