Skip to content

Commit c54b947

Browse files
author
Sara Wei
committed
add multiple connections and support protobuf
1 parent 5084b23 commit c54b947

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

request/client.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package request
22

33
import (
44
"math"
5+
"net/http"
56

67
"k8s.io/client-go/rest"
78
"k8s.io/client-go/tools/clientcmd"
@@ -17,20 +18,30 @@ import (
1718
// 3. Support Protobuf as accepted content
1819
func NewClients(kubeCfgPath string, num int, userAgent string, qps int) ([]rest.Interface, error) {
1920
restCfg, err := clientcmd.BuildConfigFromFlags("", kubeCfgPath)
21+
2022
if err != nil {
2123
return nil, err
2224
}
2325

2426
if qps == 0 {
2527
qps = math.MaxInt32
2628
}
29+
2730
restCfg.QPS = float32(qps)
2831
restCfg.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
2932

3033
restCfg.UserAgent = userAgent
34+
3135
if restCfg.UserAgent == "" {
3236
restCfg.UserAgent = rest.DefaultKubernetesUserAgent()
3337
}
38+
//set number of connections per host
39+
restCfg.Transport = &http.Transport{
40+
MaxConnsPerHost: num,
41+
}
42+
43+
//set Protobuf as accepted content
44+
restCfg.ContentType = "application/vnd.kubernetes.protobuf"
3445

3546
restClients := make([]rest.Interface, 0, num)
3647
for i := 0; i < num; i++ {

0 commit comments

Comments
 (0)