Skip to content

Add missing godocs and provide default for HTTPClient #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/cache/internal/informers_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/client/apiutil/apimachinery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/client_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconcile/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down