Create an experimental client cache.

Previously, we would initialize the experimental client at factory creation
time. This is problematic because the clientConfig loader has values populated
from the command-line flag parsing, and these are not populated until after
Factory creation. Introduce an ExperimentalClientCache to create (and reuse)
ExperimentalClients.
This commit is contained in:
Muhammed Uluyol
2015-08-18 14:25:38 -07:00
parent 5000252e46
commit 7c58f94edc
2 changed files with 31 additions and 12 deletions

View File

@@ -89,3 +89,28 @@ func (c *ClientCache) ClientForVersion(version string) (*client.Client, error) {
c.clients[config.Version] = client
return client, nil
}
type ExperimentalClientCache struct {
loader clientcmd.ClientConfig
client *client.ExperimentalClient
err error
init bool
}
func NewExperimentalClientCache(loader clientcmd.ClientConfig) *ExperimentalClientCache {
return &ExperimentalClientCache{loader: loader}
}
func (cc *ExperimentalClientCache) Client() (*client.ExperimentalClient, error) {
if cc.init {
return cc.client, cc.err
}
cfg, err := cc.loader.ClientConfig()
if err != nil {
cc.err = err
} else {
cc.client, cc.err = client.NewExperimental(cfg)
}
cc.init = true
return cc.client, cc.err
}