From eb3caf3d08b57730008ef40c4cf44020c36478ae Mon Sep 17 00:00:00 2001 From: Fabian von Feilitzsch Date: Wed, 25 May 2022 17:09:02 -0400 Subject: [PATCH 1/2] Add missing godocs and provide default for HTTPClient --- pkg/cache/cache.go | 2 ++ pkg/cache/internal/informers_map.go | 1 + pkg/client/apiutil/apimachinery.go | 3 +++ pkg/client/client.go | 9 +++++++++ pkg/client/client_cache.go | 2 +- pkg/reconcile/reconcile.go | 2 +- 6 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index 904dea9c66..89c6b05817 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..e64fe857a9 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 } From 3e6465ca62a04f897240878d473f5912588d3104 Mon Sep 17 00:00:00 2001 From: Fabian von Feilitzsch Date: Thu, 26 May 2022 11:21:35 -0400 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Andy Goldstein --- pkg/cache/cache.go | 2 +- pkg/client/client_cache.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index 89c6b05817..0cdea6c41f 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -109,7 +109,7 @@ 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 + // KeyFunction is the cache.KeyFunc that the informers will be configured to use. // Defaults to cache.MetaNamespaceKeyFunc from client-go KeyFunction cache.KeyFunc diff --git a/pkg/client/client_cache.go b/pkg/client/client_cache.go index e64fe857a9..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 http.Client to talk to an apiserver + // httpClient is the http.Client to talk to an apiserver httpClient *http.Client // scheme maps go structs to GroupVersionKinds