diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index 904dea9c66..0cdea6c41f 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -109,6 +109,8 @@ type Options struct { // So that all informers will not send list requests simultaneously. Resync *time.Duration + // KeyFunction is the cache.KeyFunc that the informers will be configured to use. + // Defaults to cache.MetaNamespaceKeyFunc from client-go KeyFunction cache.KeyFunc // Namespace restricts the cache's ListWatch to the desired namespace diff --git a/pkg/cache/internal/informers_map.go b/pkg/cache/internal/informers_map.go index bd256eab5a..215852edb5 100644 --- a/pkg/cache/internal/informers_map.go +++ b/pkg/cache/internal/informers_map.go @@ -139,6 +139,7 @@ type specificInformersMap struct { // disableDeepCopy indicates not to deep copy objects during get or list objects. disableDeepCopy DisableDeepCopyByGVK + // keyFunction is the cache.KeyFunc informers will be configured to use keyFunction cache.KeyFunc } diff --git a/pkg/client/apiutil/apimachinery.go b/pkg/client/apiutil/apimachinery.go index db06b4f976..a62a2b8c00 100644 --- a/pkg/client/apiutil/apimachinery.go +++ b/pkg/client/apiutil/apimachinery.go @@ -123,6 +123,9 @@ func RESTClientForGVK(gvk schema.GroupVersionKind, isUnstructured bool, baseConf return rest.RESTClientFor(createRestConfig(gvk, isUnstructured, baseConfig, codecs)) } +// RESTClientForGVKAndClient constructs a new rest.Interface capable of accessing the resource associated +// wwith the give GroupVersionKind. The REST client will be configured to use provided http.Client, and the +// negotiated serializer from baseConfig, if set. func RESTClientForGVKAndClient(gvk schema.GroupVersionKind, client *http.Client, isUnstructured bool, baseConfig *rest.Config, codecs serializer.CodecFactory) (rest.Interface, error) { return rest.RESTClientForConfigAndClient(createRestConfig(gvk, isUnstructured, baseConfig, codecs), client) } diff --git a/pkg/client/client.go b/pkg/client/client.go index f6080668db..8bd424efdb 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -58,6 +58,7 @@ type Options struct { // Mapper, if provided, will be used to map GroupVersionKinds to Resources Mapper meta.RESTMapper + // HTTPClient, if provided, will be used by all constructed clients to talk to the apiserver HTTPClient *http.Client // Opts is used to configure the warning handler responsible for @@ -84,6 +85,14 @@ func newClient(config *rest.Config, options Options) (*client, error) { return nil, fmt.Errorf("must provide non-nil rest.Config to client.New") } + if options.HTTPClient == nil { + httpClient, err := rest.HTTPClientFor(config) + if err != nil { + return nil, fmt.Errorf("Could not create HTTPClient from config") + } + opts.HTTPClient = httpClient + } + if !options.Opts.SuppressWarnings { // surface warnings logger := log.Log.WithName("KubeAPIWarningLogger") diff --git a/pkg/client/client_cache.go b/pkg/client/client_cache.go index 38262b7c6f..2aa556c30a 100644 --- a/pkg/client/client_cache.go +++ b/pkg/client/client_cache.go @@ -36,7 +36,7 @@ type clientCache struct { // config is the rest.Config to talk to an apiserver config *rest.Config - // httpclient is the httpClient to talk to an apiserver + // httpClient is the http.Client to talk to an apiserver httpClient *http.Client // scheme maps go structs to GroupVersionKinds diff --git a/pkg/reconcile/reconcile.go b/pkg/reconcile/reconcile.go index f8a7a982df..8099a30e3a 100644 --- a/pkg/reconcile/reconcile.go +++ b/pkg/reconcile/reconcile.go @@ -45,7 +45,7 @@ func (r *Result) IsZero() bool { // information to uniquely identify the object - its Name and Namespace. It does NOT contain information about // any specific Event or the object contents itself. type Request struct { - // NamespacedName is the name and namespace of the object to reconcile. + // ObjectKey is the name, namespace, and cluster of the object to reconcile. client.ObjectKey }