File tree 2 files changed +27
-10
lines changed
2 files changed +27
-10
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,6 @@ import (
38
38
"k8s.io/client-go/kubernetes"
39
39
kclientcmd "k8s.io/client-go/tools/clientcmd"
40
40
"k8s.io/klog/v2"
41
- "net/http"
42
41
"os"
43
42
"strings"
44
43
"sync"
@@ -316,14 +315,15 @@ func main() {
316
315
}
317
316
318
317
if cfg .Prometheus .Url != "" {
319
- var basicAuthTransport http. RoundTripper
318
+ basicAuthTransport := & com. BasicAuthTransport {}
320
319
321
- if cfg .Prometheus .Username != "" && cfg .Prometheus .Password != "" {
322
- basicAuthTransport = & com.BasicAuthTransport {
323
- RoundTripper : http .DefaultTransport ,
324
- Username : cfg .Prometheus .Username ,
325
- Password : cfg .Prometheus .Password ,
326
- }
320
+ if cfg .Prometheus .Insecure == "true" {
321
+ basicAuthTransport .Insecure = true
322
+ }
323
+
324
+ if cfg .Prometheus .Username != "" {
325
+ basicAuthTransport .Username = cfg .Prometheus .Username
326
+ basicAuthTransport .Password = cfg .Prometheus .Password
327
327
}
328
328
329
329
promClient , err := promapi .NewClient (promapi.Config {
Original file line number Diff line number Diff line change 1
1
package com
2
2
3
3
import (
4
+ "crypto/tls"
4
5
"net/http"
5
6
)
6
7
@@ -9,11 +10,27 @@ type BasicAuthTransport struct {
9
10
http.RoundTripper
10
11
Username string
11
12
Password string
13
+ Insecure bool
12
14
}
13
15
14
16
// RoundTrip executes a single HTTP transaction with the basic auth credentials.
15
17
func (t * BasicAuthTransport ) RoundTrip (req * http.Request ) (* http.Response , error ) {
16
- req .SetBasicAuth (t .Username , t .Password )
18
+ if t .Username != "" {
19
+ req .SetBasicAuth (t .Username , t .Password )
20
+ }
17
21
18
- return t .RoundTripper .RoundTrip (req )
22
+ rt := t .RoundTripper
23
+ if rt == nil {
24
+ rt = http .DefaultTransport
25
+ }
26
+
27
+ if t .Insecure {
28
+ if transport , ok := rt .(* http.Transport ); ok {
29
+ transportCopy := transport .Clone ()
30
+ transportCopy .TLSClientConfig = & tls.Config {InsecureSkipVerify : true }
31
+ rt = transportCopy
32
+ }
33
+ }
34
+
35
+ return rt .RoundTrip (req )
19
36
}
You can’t perform that action at this time.
0 commit comments