@@ -20,6 +20,7 @@ import (
2020 "context"
2121 "fmt"
2222 "math/rand"
23+ "net/http"
2324 "sync"
2425 "time"
2526
@@ -44,6 +45,7 @@ func init() {
4445
4546// InformersOpts configures an InformerMap.
4647type InformersOpts struct {
48+ HTTPClient * http.Client
4749 Scheme * runtime.Scheme
4850 Mapper meta.RESTMapper
4951 ResyncPeriod time.Duration
@@ -62,9 +64,10 @@ type InformersOptsByGVK struct {
6264// NewInformers creates a new InformersMap that can create informers under the hood.
6365func NewInformers (config * rest.Config , options * InformersOpts ) * Informers {
6466 return & Informers {
65- config : config ,
66- scheme : options .Scheme ,
67- mapper : options .Mapper ,
67+ config : config ,
68+ httpClient : options .HTTPClient ,
69+ scheme : options .Scheme ,
70+ mapper : options .Mapper ,
6871 tracker : tracker {
6972 Structured : make (map [schema.GroupVersionKind ]* Cache ),
7073 Unstructured : make (map [schema.GroupVersionKind ]* Cache ),
@@ -99,6 +102,9 @@ type tracker struct {
99102// Informers create and caches Informers for (runtime.Object, schema.GroupVersionKind) pairs.
100103// It uses a standard parameter codec constructed based on the given generated Scheme.
101104type Informers struct {
105+ // httpClient is used to create a new REST client
106+ httpClient * http.Client
107+
102108 // scheme maps runtime.Objects to GroupVersionKinds
103109 scheme * runtime.Scheme
104110
@@ -364,7 +370,7 @@ func (ip *Informers) makeListWatcher(gvk schema.GroupVersionKind, obj runtime.Ob
364370 // we should remove it and use the one that the dynamic client sets for us.
365371 cfg := rest .CopyConfig (ip .config )
366372 cfg .NegotiatedSerializer = nil
367- dynamicClient , err := dynamic .NewForConfig (cfg )
373+ dynamicClient , err := dynamic .NewForConfigAndClient (cfg , ip . httpClient )
368374 if err != nil {
369375 return nil , err
370376 }
@@ -394,7 +400,7 @@ func (ip *Informers) makeListWatcher(gvk schema.GroupVersionKind, obj runtime.Ob
394400 cfg .NegotiatedSerializer = nil
395401
396402 // Grab the metadata metadataClient.
397- metadataClient , err := metadata .NewForConfig (cfg )
403+ metadataClient , err := metadata .NewForConfigAndClient (cfg , ip . httpClient )
398404 if err != nil {
399405 return nil , err
400406 }
@@ -435,7 +441,7 @@ func (ip *Informers) makeListWatcher(gvk schema.GroupVersionKind, obj runtime.Ob
435441 // Structured.
436442 //
437443 default :
438- client , err := apiutil .RESTClientForGVK (gvk , false , ip .config , ip .codecs )
444+ client , err := apiutil .RESTClientForGVK (gvk , false , ip .config , ip .codecs , ip . httpClient )
439445 if err != nil {
440446 return nil , err
441447 }
0 commit comments