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