mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
Make ClientCache public
This commit is contained in:
parent
a53a3b7e8c
commit
01807c1fac
@ -22,17 +22,17 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/client/clientcmd"
|
"k8s.io/kubernetes/pkg/client/clientcmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewClientCache(loader clientcmd.ClientConfig) *clientCache {
|
func NewClientCache(loader clientcmd.ClientConfig) *ClientCache {
|
||||||
return &clientCache{
|
return &ClientCache{
|
||||||
clients: make(map[string]*client.Client),
|
clients: make(map[string]*client.Client),
|
||||||
configs: make(map[string]*client.Config),
|
configs: make(map[string]*client.Config),
|
||||||
loader: loader,
|
loader: loader,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// clientCache caches previously loaded clients for reuse, and ensures MatchServerVersion
|
// ClientCache caches previously loaded clients for reuse, and ensures MatchServerVersion
|
||||||
// is invoked only once
|
// is invoked only once
|
||||||
type clientCache struct {
|
type ClientCache struct {
|
||||||
loader clientcmd.ClientConfig
|
loader clientcmd.ClientConfig
|
||||||
clients map[string]*client.Client
|
clients map[string]*client.Client
|
||||||
configs map[string]*client.Config
|
configs map[string]*client.Config
|
||||||
@ -42,7 +42,7 @@ type clientCache struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ClientConfigForVersion returns the correct config for a server
|
// ClientConfigForVersion returns the correct config for a server
|
||||||
func (c *clientCache) ClientConfigForVersion(version string) (*client.Config, error) {
|
func (c *ClientCache) ClientConfigForVersion(version string) (*client.Config, error) {
|
||||||
if c.defaultConfig == nil {
|
if c.defaultConfig == nil {
|
||||||
config, err := c.loader.ClientConfig()
|
config, err := c.loader.ClientConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -73,7 +73,7 @@ func (c *clientCache) ClientConfigForVersion(version string) (*client.Config, er
|
|||||||
|
|
||||||
// ClientForVersion initializes or reuses a client for the specified version, or returns an
|
// ClientForVersion initializes or reuses a client for the specified version, or returns an
|
||||||
// error if that is not possible
|
// error if that is not possible
|
||||||
func (c *clientCache) ClientForVersion(version string) (*client.Client, error) {
|
func (c *ClientCache) ClientForVersion(version string) (*client.Client, error) {
|
||||||
if client, ok := c.clients[version]; ok {
|
if client, ok := c.clients[version]; ok {
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ const (
|
|||||||
// TODO: pass the various interfaces on the factory directly into the command constructors (so the
|
// TODO: pass the various interfaces on the factory directly into the command constructors (so the
|
||||||
// commands are decoupled from the factory).
|
// commands are decoupled from the factory).
|
||||||
type Factory struct {
|
type Factory struct {
|
||||||
clients *clientCache
|
clients *ClientCache
|
||||||
flags *pflag.FlagSet
|
flags *pflag.FlagSet
|
||||||
generators map[string]kubectl.Generator
|
generators map[string]kubectl.Generator
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user