expose NewForConfigAndClient for the dynamic client

Kubernetes-commit: b584195e5cc0a1094318ba886a9aecd2f675d59c
This commit is contained in:
Antonio Ojea 2021-10-19 15:58:58 +02:00 committed by Kubernetes Publisher
parent bb294ffaf0
commit 12956a0d53

View File

@ -19,6 +19,7 @@ package dynamic
import (
"context"
"fmt"
"net/http"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -60,17 +61,30 @@ func NewForConfigOrDie(c *rest.Config) Interface {
}
// NewForConfig creates a new dynamic client or returns an error.
// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient),
// where httpClient was generated with rest.HTTPClientFor(c).
func NewForConfig(inConfig *rest.Config) (Interface, error) {
config := ConfigFor(inConfig)
httpClient, err := rest.HTTPClientFor(config)
if err != nil {
return nil, err
}
return NewForConfigAndClient(config, httpClient)
}
// NewForConfigAndClient creates a new dynamic client for the given config and http client.
// Note the http client provided takes precedence over the configured transport values.
func NewForConfigAndClient(inConfig *rest.Config, h *http.Client) (Interface, error) {
config := ConfigFor(inConfig)
// for serializing the options
config.GroupVersion = &schema.GroupVersion{}
config.APIPath = "/if-you-see-this-search-for-the-break"
restClient, err := rest.RESTClientFor(config)
restClient, err := rest.RESTClientForConfigAndClient(config, h)
if err != nil {
return nil, err
}
return &dynamicClient{client: restClient}, nil
}