Use global HTTP client whenever applicable (#2682)

This commit is contained in:
Harshavardhana
2023-02-27 17:19:56 -08:00
committed by GitHub
parent 372852ee86
commit dd913decc6
9 changed files with 40 additions and 58 deletions

View File

@@ -32,6 +32,7 @@ import (
"github.com/minio/console/operatorapi/operations"
"github.com/minio/console/operatorapi/operations/operator_api"
"github.com/minio/console/pkg"
"github.com/minio/console/restapi"
errors "github.com/minio/console/restapi"
"github.com/minio/pkg/env"
corev1 "k8s.io/api/core/v1"
@@ -147,7 +148,8 @@ func makePostRequestToMP(url, email string) error {
if err != nil {
return err
}
client := &http.Client{Timeout: 3 * time.Second}
client := restapi.GetConsoleHTTPClient("")
client.Timeout = 3 * time.Second
if res, err := client.Do(request); err != nil {
return err
} else if res.StatusCode >= http.StatusBadRequest {

View File

@@ -19,7 +19,6 @@ package operatorapi
import (
"bytes"
"crypto/sha1"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
@@ -38,6 +37,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/minio/console/cluster"
"github.com/minio/console/restapi"
"github.com/minio/console/pkg/auth"
)
@@ -148,12 +148,8 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
}
loginReq.Header.Add("Content-Type", "application/json")
// FIXME: in the future we should use restapi.GetConsoleHTTPClient()
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
// use localhost to ensure 'InsecureSkipVerify'
client := restapi.GetConsoleHTTPClient("http://127.0.0.1")
loginResp, err := client.Do(loginReq)
if err != nil {
log.Println(err)
@@ -222,16 +218,11 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
}
func handleHTTPRequest(responseWriter http.ResponseWriter, req *http.Request, proxyCookieJar *cookiejar.Jar, tenantBase string, targetURL *url2.URL) {
tr := &http.Transport{
// FIXME: use restapi.GetConsoleHTTPClient()
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{
Transport: tr,
Jar: proxyCookieJar,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
// use localhost to ensure 'InsecureSkipVerify'
client := restapi.GetConsoleHTTPClient("http://127.0.0.1")
client.Jar = proxyCookieJar
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}
// are we proxying something with cp=y? (console proxy) then add cpb (console proxy base) so the console

View File

@@ -26,7 +26,6 @@ import (
"errors"
"fmt"
"net"
"net/http"
"sort"
"strconv"
"strings"
@@ -1440,10 +1439,10 @@ func getUpdateTenantResponse(session *models.Principal, params operator_api.Upda
opClient := &operatorClient{
client: opClientClientSet,
}
client := restapi.GetConsoleHTTPClient("")
client.Timeout = 4 * time.Second
httpC := &utils2.Client{
Client: &http.Client{
Timeout: 4 * time.Second,
},
Client: client,
}
if err := updateTenantAction(ctx, opClient, k8sClient, httpC, params.Namespace, params); err != nil {
return restapi.ErrorWithContext(ctx, err, errors.New("unable to update tenant"))