Skip to content

Commit

Permalink
add multiple connections and support protobuf
Browse files Browse the repository at this point in the history
  • Loading branch information
Sara Wei committed Dec 23, 2023
1 parent 5084b23 commit c54b947
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions request/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package request

import (
"math"
"net/http"

"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -17,20 +18,30 @@ import (
// 3. Support Protobuf as accepted content
func NewClients(kubeCfgPath string, num int, userAgent string, qps int) ([]rest.Interface, error) {
restCfg, err := clientcmd.BuildConfigFromFlags("", kubeCfgPath)

if err != nil {
return nil, err
}

if qps == 0 {
qps = math.MaxInt32
}

restCfg.QPS = float32(qps)
restCfg.NegotiatedSerializer = scheme.Codecs.WithoutConversion()

restCfg.UserAgent = userAgent

if restCfg.UserAgent == "" {
restCfg.UserAgent = rest.DefaultKubernetesUserAgent()
}
//set number of connections per host
restCfg.Transport = &http.Transport{
MaxConnsPerHost: num,
}

//set Protobuf as accepted content
restCfg.ContentType = "application/vnd.kubernetes.protobuf"

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

0 comments on commit c54b947

Please sign in to comment.