func NewClients()

in request/client.go [24:62]


func NewClients(kubeCfgPath string, connsNum int, opts ...ClientCfgOpt) ([]rest.Interface, error) {
	var cfg = defaultClientCfg
	for _, opt := range opts {
		opt(&cfg)
	}

	restCfg, err := clientcmd.BuildConfigFromFlags("", kubeCfgPath)
	if err != nil {
		return nil, err
	}
	restCfg.NegotiatedSerializer = unstructuredscheme.NewNegotiatedSerializer()

	// NOTE:
	//
	// Make transport uncacheable. With default proxy function, client-go
	// will create new transport even if multiple clients use the same TLS
	// configuration. If not, all the clients will share one transport.
	// If protocol is HTTP2, there will be only one connection.
	//
	// REF: https://github.com/kubernetes/client-go/blob/c5938c6876a62f53c1f4ee55b879ca5c74253ae8/transport/cache.go#L154
	restCfg.Proxy = http.ProxyFromEnvironment

	err = cfg.apply(restCfg)
	if err != nil {
		return nil, err
	}

	restClients := make([]rest.Interface, 0, connsNum)
	for i := 0; i < connsNum; i++ {
		cfgShallowCopy := *restCfg

		restCli, err := rest.UnversionedRESTClientFor(&cfgShallowCopy)
		if err != nil {
			return nil, err
		}
		restClients = append(restClients, restCli)
	}
	return restClients, nil
}