mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
expose NewForConfigAndClient for the metadata client
This commit is contained in:
parent
b584195e5c
commit
909a1738fd
@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
@ -85,13 +86,27 @@ func NewForConfigOrDie(c *rest.Config) Interface {
|
||||
// metadata details about any Kubernetes object (core, aggregated, or custom
|
||||
// resource based) in the form of PartialObjectMetadata objects, 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 metadata 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 = "/this-value-should-never-be-sent"
|
||||
|
||||
restClient, err := rest.RESTClientFor(config)
|
||||
restClient, err := rest.RESTClientForConfigAndClient(config, h)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user